Skip to content

Commit 2af7da2

Browse files
committed
update console app
1 parent f7d5d74 commit 2af7da2

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ validate:
88
composer validate
99

1010
analyze:
11-
./vendor/bin/phpstan analyze --level 3 src/ tests/
11+
./vendor/bin/phpstan analyze --level 3 --ansi src/ tests/
1212

1313
lint:
1414
composer exec --verbose phpcs -- --standard=PSR12 src/ bin/

src/ConsoleApp.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,36 @@ class ConsoleApp
88
{
99
private CommandInterface $nextCommand;
1010
private CommandFactoryInterface $commandFactory;
11+
private array $flowSteps;
12+
private CommandInterface $initCommand;
1113

1214
public function __construct(
1315
CommandFactoryInterface $commandFactory
1416
) {
1517
$this->commandFactory = $commandFactory;
18+
19+
$parseCommand = $this->commandFactory->createCommand("parse");
20+
$this->initCommand = $parseCommand->execute();
21+
$this->flowSteps = [
22+
"difference",
23+
strtolower($parseCommand->getFormat()),
24+
"show"
25+
];
1626
}
1727

1828
public function run(): void
1929
{
20-
$parseCommand = $this->commandFactory->createCommand("parse");
21-
$this->nextCommand = $parseCommand
22-
->execute();
23-
24-
$differenceCommand = $this->commandFactory->createCommand("difference");
25-
$this->nextCommand = $differenceCommand
26-
->execute($this->nextCommand);
27-
28-
$formatCommand = $this->commandFactory->createCommand(
29-
strtolower($parseCommand->getFormat())
30+
$commandFactory = $this->commandFactory;
31+
array_reduce(
32+
$this->flowSteps,
33+
function($nextCommand, $item) use ($commandFactory) {
34+
$currentCommand = $commandFactory->createCommand($item);
35+
$nextCommand = $currentCommand->execute($nextCommand);
36+
37+
return $nextCommand;
38+
},
39+
$this->initCommand
3040
);
31-
$this->nextCommand = $formatCommand->execute($this->nextCommand);
32-
33-
$displayCommand = $this->commandFactory->createCommand("show");
34-
35-
$displayCommand->execute($this->nextCommand);
41+
3642
}
3743
}

src/FileReader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function __construct(string $fileFormat = 'json')
2121

2222
public function readFile(string $filename, bool $isArray = true): ?array
2323
{
24+
$fileContentArray = null;
2425
if (file_exists($filename)) {
2526
$fileNameParts = explode(".", $this->normalizeFilename($filename));
2627
$fileFormat = end($fileNameParts);

0 commit comments

Comments
 (0)