Skip to content

Commit 04ef827

Browse files
committed
improved maintainability
1 parent 39fab8c commit 04ef827

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/ConsoleApp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function run(): void
3030
$commandFactory = $this->commandFactory;
3131
foreach ($this->flowSteps as $step) {
3232
$currentCommand = $commandFactory->createCommand($step);
33-
$nextCommand = $currentCommand->execute($this->initCommand);
34-
$this->initCommand = $nextCommand;
33+
$this->nextCommand = $currentCommand->execute($this->initCommand);
34+
$this->initCommand = $this->nextCommand;
3535
}
3636
}
3737
}

src/Differ.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
use Differ\DisplayCommand;
1010
use Differ\Formatters;
1111

12-
function genDiff(string $pathToFile1, string $pathToFile2, string $format = 'stylish')
13-
{
12+
function genDiff(
13+
string $pathToFile1,
14+
string $pathToFile2,
15+
string $format = 'stylish'
16+
): string {
1417
$commandFactory = new CommandFactory(
1518
new \Docopt(),
1619
new FileReader(),

src/Formatters.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@ class Formatters implements CommandFactoryInterface
1717

1818
public function createCommand(string $commandKey): CommandInterface
1919
{
20-
$requestedCommand = null;
2120
switch ($commandKey) {
2221
case self::FORMAT_KEYS["stylish"]:
23-
$requestedCommand = new StylishCommand();
22+
$this->formatCommand = new StylishCommand();
2423
break;
2524
case self::FORMAT_KEYS["plain"]:
26-
$requestedCommand = new PlainCommand();
25+
$this->formatCommand = new PlainCommand();
2726
break;
2827
case self::FORMAT_KEYS["json"]:
29-
$requestedCommand = new JSONCommand();
28+
$this->formatCommand = new JSONCommand();
3029
break;
3130
default:
3231
return throw new DifferException("input error: unknown output format\n");
3332
}
3433

35-
return $requestedCommand;
34+
return $this->formatCommand;
3635
}
3736
}

0 commit comments

Comments
 (0)