Skip to content

Commit 20687c6

Browse files
committed
Refactor GenerateDiagramCommand to prioritize text-output option before checking file extension for .txt output
1 parent f880c14 commit 20687c6

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/GenerateDiagramCommand.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,9 @@ public function handle()
7070
);
7171
});
7272

73-
// Check if output filename has .txt extension
74-
$outputFileName = $this->getOutputFileName();
75-
if (pathinfo($outputFileName, PATHINFO_EXTENSION) === 'txt') {
76-
// Generate structured text output for .txt files
77-
$textOutput = $this->graphBuilder->generateStructuredTextRepresentation($models);
78-
file_put_contents($outputFileName, $textOutput);
79-
$this->info(PHP_EOL);
80-
$this->info('Wrote structured ER diagram to ' . $outputFileName);
81-
return;
82-
}
83-
8473
$graph = $this->graphBuilder->buildGraph($models);
8574

75+
// First check for text-output option
8676
if ($this->option('text-output') || $this->option('format') === self::FORMAT_TEXT) {
8777
$textOutput = $graph->__toString();
8878

@@ -100,6 +90,17 @@ public function handle()
10090
return;
10191
}
10292

93+
// Then check for .txt extension in filename
94+
$outputFileName = $this->getOutputFileName();
95+
if (pathinfo($outputFileName, PATHINFO_EXTENSION) === 'txt') {
96+
// Generate structured text output for .txt files
97+
$textOutput = $this->graphBuilder->generateStructuredTextRepresentation($models);
98+
file_put_contents($outputFileName, $textOutput);
99+
$this->info(PHP_EOL);
100+
$this->info('Wrote structured ER diagram to ' . $outputFileName);
101+
return;
102+
}
103+
103104
$graph->export($this->option('format'), $outputFileName);
104105

105106
$this->info(PHP_EOL);

0 commit comments

Comments
 (0)