Skip to content

Commit 38ffeae

Browse files
committed
added helper function genDiff to differ
1 parent ed2afa1 commit 38ffeae

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

bin/gendiff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Differ\Factories\Formatters;
1616
use Differ\Exceptions\DifferException;
1717

1818
$differ = new Differ(
19-
$commandFactory = new CommandFactory(
19+
new CommandFactory(
2020
new \Docopt(),
2121
new FileReader(),
2222
new Formatters()

src/Differ.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Differ\Readers\FileReader;
1313
use Differ\Factories\Formatters;
1414
use Differ\Exceptions\DifferException;
15+
use Differ\Parsers\DocoptDouble;
1516

1617
class Differ
1718
{
@@ -130,3 +131,23 @@ public function genDiff(
130131
->getFilesDiffs();
131132
}
132133
}
134+
135+
function genDiff(
136+
string $pathToFile1,
137+
string $pathToFile2,
138+
string $format = 'stylish'
139+
): string {
140+
$differ = new Differ(
141+
new CommandFactory(
142+
new DocoptDouble(),
143+
new FileReader(),
144+
new Formatters()
145+
)
146+
);
147+
148+
return $differ->genDiff(
149+
$pathToFile1,
150+
$pathToFile2,
151+
$format
152+
);
153+
}

tests/Unit/GendiffConsoleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testAPIDiffer($formatter, $filePath)
8686
{
8787
$commandLineParser = is_null($formatter) ? new DocoptDouble() : new DocoptDouble($formatter);
8888
$differ = new Differ(
89-
$commandFactory = new CommandFactory(
89+
new CommandFactory(
9090
$commandLineParser,
9191
new FileReader(),
9292
new Formatters()

0 commit comments

Comments
 (0)