Skip to content

Commit 35689c5

Browse files
committed
added display command interface
1 parent d66a0e7 commit 35689c5

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

src/CommandFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Differ\FilesDiffCommandInterface as FDCI;
1717
use Differ\CommandInterface as CI;
1818
use Differ\FormattersInterface as FI;
19+
use Differ\DisplayCommandInterface as DCI;
1920

2021
class CommandFactory implements CommandFactoryInterface
2122
{
@@ -47,7 +48,7 @@ public function getFormatKeys(): array
4748
return self::FORMAT_KEYS;
4849
}
4950

50-
public function createCommand(string $commandType): CLP|FDCI|CI|FI
51+
public function createCommand(string $commandType): CLP|FDCI|CI|FI|DCI
5152
{
5253
switch ($commandType) {
5354
case "parse":

src/CommandFactoryInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use Differ\FilesDiffCommandInterface as FDCI;
77
use Differ\CommandInterface as CI;
88
use Differ\FormattersInterface as FI;
9+
use Differ\DisplayCommandInterface as DCI;
910

1011
interface CommandFactoryInterface
1112
{
12-
public function createCommand(string $commandType): CLP | FDCI | CI | FI;
13+
public function createCommand(string $commandType): CLP | FDCI | CI | FI | DCI;
1314
}

src/ConsoleApp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class ConsoleApp
88
{
9-
private CommandInterface|FilesDiffCommandInterface|FormattersInterface $nextCommand;
9+
private CommandInterface|FilesDiffCommandInterface|FormattersInterface|DisplayCommandInterface $nextCommand;
1010
private CommandFactoryInterface $commandFactory;
1111
private array $flowSteps;
12-
private CommandInterface|CommandLineParserInterface|FilesDiffCommandInterface|FormattersInterface $initCommand;
12+
private CommandInterface|CommandLineParserInterface|FilesDiffCommandInterface|FormattersInterface|DisplayCommandInterface $initCommand;
1313

1414
public function __construct(
1515
CommandFactoryInterface $commandFactory

src/DisplayCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use Differ\FilesDiffCommandInterface as FDCI;
77
use Differ\CommandInterface as CI;
88
use Differ\FormattersInterface as FI;
9+
use Differ\DisplayCommandInterface as DCI;
910

10-
class DisplayCommand implements CommandInterface
11+
class DisplayCommand implements DCI
1112
{
1213
private string $mode;
13-
private CommandInterface|FormattersInterface $formatCommand;
14+
private FormattersInterface $formatCommand;
1415
private const string MODE_EXCEPTION_MESSAGE = "internal error: unknown mode for display\n";
1516
public const AVAILABLE_MODES = [
1617
"differents" => "differents",
@@ -22,7 +23,7 @@ public function __construct(string $mode = self::AVAILABLE_MODES["differents"])
2223
$this->mode = $mode;
2324
}
2425

25-
public function setFormatter(CI|FI $formatter)
26+
public function setFormatter(FI $formatter): DCI
2627
{
2728
$this->formatCommand = $formatter;
2829

@@ -39,7 +40,7 @@ public function getFilesDiffs(): string
3940
return $this->formatCommand->getDiffsString();
4041
}
4142

42-
public function execute(CLP|FDCI|CI|FI $command): CI|FI
43+
public function execute(FI $command): DCI
4344
{
4445
$this->formatCommand = $command;
4546
switch ($this->mode) {
@@ -56,7 +57,7 @@ public function execute(CLP|FDCI|CI|FI $command): CI|FI
5657
return $this;
5758
}
5859

59-
public function setMode(string $mode): CI
60+
public function setMode(string $mode): DCI
6061
{
6162
if (in_array($mode, array_keys(self::AVAILABLE_MODES))) {
6263
$this->mode = $mode;

src/DisplayCommandInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Differ;
4+
5+
interface DisplayCommandInterface
6+
{
7+
public function execute(FormattersInterface $command): DisplayCommandInterface;
8+
public function getFilesContent(): string;
9+
public function getFilesDiffs(): string;
10+
}

0 commit comments

Comments
 (0)