Skip to content

Commit d970423

Browse files
committed
added compute flow
1 parent 535ad35 commit d970423

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/ConsoleApp.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,10 @@ public function __construct(
2828
public function run(): void
2929
{
3030
$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
40-
);
31+
foreach ($this->flowSteps as $step) {
32+
$currentCommand = $commandFactory->createCommand($step);
33+
$nextCommand = $currentCommand->execute($this->initCommand);
34+
$this->initCommand = $nextCommand;
35+
}
4136
}
4237
}

src/Differ.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ function genDiff(string $pathToFile1, string $pathToFile2, string $format = 'sty
2121
"FILE1" => $pathToFile1,
2222
"FILE2" => $pathToFile2
2323
];
24-
$nextCommand = $parseCommand->setFileNames($fileNames)
25-
->setFormat($format);
26-
27-
$differenceCommand = $commandFactory->createCommand('difference');
28-
$nextCommand = $differenceCommand->execute($nextCommand);
2924

30-
$formatCommand = $commandFactory->createCommand(
25+
$initCommand = $parseCommand->setFileNames($fileNames)
26+
->setFormat($format);
27+
$flowSteps = [
28+
"difference",
3129
strtolower($parseCommand->getFormat())
32-
);
33-
$formatter = $formatCommand->execute($nextCommand);
34-
30+
];
31+
foreach ($flowSteps as $step) {
32+
$currentCommand = $commandFactory->createCommand($step);
33+
$nextCommand = $currentCommand->execute($initCommand);
34+
$initCommand = $nextCommand;
35+
}
3536
$displayCommand = $commandFactory->createCommand("show");
36-
return $displayCommand->setFormatter($formatter)
37+
38+
return $displayCommand->setFormatter($initCommand)
3739
->getFilesDiffs();
3840
}

0 commit comments

Comments
 (0)