Skip to content

Commit 3940323

Browse files
authored
Merge pull request #61 from JBlond/php-dif-60
Php diff 60
2 parents 1a71822 + 8098c71 commit 3940323

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

example/cli.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
$renderer = new UnifiedCli(
4545
// Define renderer options.
4646
[
47-
'cliColor' => 'simple',
47+
'cliColor' => true,
4848
]
4949
);
5050

lib/jblond/Diff/Renderer/Html/Inline.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class Inline extends MainRenderer implements SubRendererInterface
4949
*/
5050
public function __construct(array $options = [])
5151
{
52-
parent::__construct();
53-
$this->setOptions($this->subOptions);
52+
parent::__construct($this->subOptions);
5453
$this->setOptions($options);
5554
}
5655

lib/jblond/Diff/Renderer/Html/SideBySide.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class SideBySide extends MainRenderer implements SubRendererInterface
4949
*/
5050
public function __construct(array $options = [])
5151
{
52-
parent::__construct();
53-
$this->setOptions($this->subOptions);
52+
parent::__construct($this->subOptions);
5453
$this->setOptions($options);
5554
}
5655

lib/jblond/Diff/Renderer/Html/Unified.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class Unified extends MainRenderer implements SubRendererInterface
4949
*/
5050
public function __construct(array $options = [])
5151
{
52-
parent::__construct();
53-
$this->setOptions($this->subOptions);
52+
parent::__construct($this->subOptions);
5453
$this->setOptions($options);
5554
}
5655

lib/jblond/Diff/Renderer/MainRendererAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ abstract class MainRendererAbstract
3636
* - deleteMarkers Markers for removed text.
3737
* - insertMarkers Markers for inserted text.
3838
* - equalityMarkers Markers for unchanged and changed lines.
39-
* - insertColors Fore- and background color for inserted text. Only when cloColor = true.
40-
* - deleteColors Fore- and background color for removed text. Only when cloColor = true.
39+
* - insertColors Fore- and background color for inserted text. Only when cliColor = true.
40+
* - deleteColors Fore- and background color for removed text. Only when cliColor = true.
4141
*/
4242
protected $mainOptions = [
4343
'tabSize' => 4,

lib/jblond/Diff/Renderer/Text/InlineCli.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class InlineCli extends MainRenderer implements SubRendererInterface
3737
*/
3838
public function __construct(array $options = [])
3939
{
40-
parent::__construct();
41-
$this->setOptions($this->subOptions);
40+
parent::__construct($this->subOptions);
4241
$this->setOptions($options);
4342
}
4443

lib/jblond/Diff/Renderer/Text/UnifiedCli.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ class UnifiedCli extends MainRendererAbstract
2727
*/
2828
private $colors;
2929

30+
/**
31+
* @var array Associative array containing the default options available for this renderer and their default
32+
* value.
33+
*/
34+
protected $subOptions = [];
35+
3036
/**
3137
* UnifiedCli constructor.
3238
* @param array $options
39+
*
3340
*/
3441
public function __construct(array $options = [])
3542
{
36-
parent::__construct($options);
43+
parent::__construct();
44+
$this->setOptions($this->subOptions);
45+
$this->setOptions($options);
3746
$this->colors = new CliColors();
38-
$this->options = $options;
3947
}
4048

4149
/**
@@ -46,13 +54,7 @@ public function __construct(array $options = [])
4654
*/
4755
public function render(): string
4856
{
49-
if (!isset($this->options['cliColor'])) {
50-
return $this->output();
51-
}
52-
if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') {
53-
return $this->output();
54-
}
55-
throw new InvalidArgumentException('Invalid cliColor option');
57+
return $this->output();
5658
}
5759

5860

@@ -63,7 +65,7 @@ public function render(): string
6365
*/
6466
private function colorizeString($string, $color = ''): string
6567
{
66-
if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') {
68+
if ($this->options['cliColor']) {
6769
return $this->colors->getColoredString($string, $color);
6870
}
6971
return $string;

0 commit comments

Comments
 (0)