From df270f5840c257a4d3d8a6180ba281a44664ff73 Mon Sep 17 00:00:00 2001 From: JBlond Date: Tue, 6 Oct 2020 21:49:17 +0200 Subject: [PATCH 1/8] correct typos --- lib/jblond/Diff/Renderer/MainRendererAbstract.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jblond/Diff/Renderer/MainRendererAbstract.php b/lib/jblond/Diff/Renderer/MainRendererAbstract.php index fd204a04..5a11e3e5 100644 --- a/lib/jblond/Diff/Renderer/MainRendererAbstract.php +++ b/lib/jblond/Diff/Renderer/MainRendererAbstract.php @@ -36,8 +36,8 @@ abstract class MainRendererAbstract * - deleteMarkers Markers for removed text. * - insertMarkers Markers for inserted text. * - equalityMarkers Markers for unchanged and changed lines. - * - insertColors Fore- and background color for inserted text. Only when cloColor = true. - * - deleteColors Fore- and background color for removed text. Only when cloColor = true. + * - insertColors Fore- and background color for inserted text. Only when cliColor = true. + * - deleteColors Fore- and background color for removed text. Only when cliColor = true. */ protected $mainOptions = [ 'tabSize' => 4, From 38864db2b5db077fd37a76a9237c02d6e3ec90e3 Mon Sep 17 00:00:00 2001 From: JBlond Date: Tue, 6 Oct 2020 21:51:58 +0200 Subject: [PATCH 2/8] change cli colors option from simple to true --- README.md | 2 +- example/cli.php | 2 +- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9781d298..62b8a55a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ $options = [ 'ignoreWhitespace' => true, 'ignoreCase' => true, 'context' => 2, - 'cliColor' => 'simple' // for cli output + 'cliColor' => true // for cli output ]; // Initialize the diff class. diff --git a/example/cli.php b/example/cli.php index 18054cf2..8b3ea7de 100644 --- a/example/cli.php +++ b/example/cli.php @@ -44,7 +44,7 @@ $renderer = new UnifiedCli( // Define renderer options. [ - 'cliColor' => 'simple', + 'cliColor' => true, ] ); diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 2f5007d2..9d840dfa 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -49,7 +49,7 @@ public function render(): string if (!isset($this->options['cliColor'])) { return $this->output(); } - if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') { + if (isset($this->options['cliColor'])) { return $this->output(); } throw new InvalidArgumentException('Invalid cliColor option'); @@ -63,7 +63,7 @@ public function render(): string */ private function colorizeString($string, $color = ''): string { - if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') { + if (isset($this->options['cliColor'])) { return $this->colors->getColoredString($string, $color); } return $string; From fbccaf423326e0b9472f99c79e8f1d83136c4cd5 Mon Sep 17 00:00:00 2001 From: JBlond Date: Tue, 6 Oct 2020 21:56:52 +0200 Subject: [PATCH 3/8] check type of option --- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 9d840dfa..bc9f0df1 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -49,7 +49,7 @@ public function render(): string if (!isset($this->options['cliColor'])) { return $this->output(); } - if (isset($this->options['cliColor'])) { + if (isset($this->options['cliColor']) && $this->options['cliColor'] === true) { return $this->output(); } throw new InvalidArgumentException('Invalid cliColor option'); @@ -63,7 +63,7 @@ public function render(): string */ private function colorizeString($string, $color = ''): string { - if (isset($this->options['cliColor'])) { + if (isset($this->options['cliColor']) && $this->options['cliColor'] === true) { return $this->colors->getColoredString($string, $color); } return $string; From 98781fd8c290bb2960f8960c945c0d951f1b9e29 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 7 Oct 2020 08:45:23 +0200 Subject: [PATCH 4/8] check only if option is set --- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index bc9f0df1..93077e2c 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -49,10 +49,7 @@ public function render(): string if (!isset($this->options['cliColor'])) { return $this->output(); } - if (isset($this->options['cliColor']) && $this->options['cliColor'] === true) { - return $this->output(); - } - throw new InvalidArgumentException('Invalid cliColor option'); + return $this->output(); } @@ -63,7 +60,7 @@ public function render(): string */ private function colorizeString($string, $color = ''): string { - if (isset($this->options['cliColor']) && $this->options['cliColor'] === true) { + if (isset($this->options['cliColor'])) { return $this->colors->getColoredString($string, $color); } return $string; From 0e3fd21254bc7eba09f1c4fdae8e85a0aec6b432 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 7 Oct 2020 11:38:33 +0200 Subject: [PATCH 5/8] merge options instead of set them directly --- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 93077e2c..414867f0 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -27,15 +27,23 @@ class UnifiedCli extends MainRendererAbstract */ private $colors; + /** + * @var array Associative array containing the default options available for this renderer and their default + * value. + */ + protected $subOptions = []; + /** * UnifiedCli constructor. * @param array $options + * */ public function __construct(array $options = []) { - parent::__construct($options); + parent::__construct(); + $this->setOptions($this->subOptions); + $this->setOptions($options); $this->colors = new CliColors(); - $this->options = $options; } /** From 24c8bb936077565cae3d1cc0da75eaf395a8cb20 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 7 Oct 2020 13:29:45 +0200 Subject: [PATCH 6/8] Simplify options merge --- lib/jblond/Diff/Renderer/Html/Inline.php | 3 +-- lib/jblond/Diff/Renderer/Html/SideBySide.php | 3 +-- lib/jblond/Diff/Renderer/Html/Unified.php | 3 +-- lib/jblond/Diff/Renderer/Text/InlineCli.php | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Html/Inline.php b/lib/jblond/Diff/Renderer/Html/Inline.php index 74d1933c..068b1177 100644 --- a/lib/jblond/Diff/Renderer/Html/Inline.php +++ b/lib/jblond/Diff/Renderer/Html/Inline.php @@ -49,8 +49,7 @@ class Inline extends MainRenderer implements SubRendererInterface */ public function __construct(array $options = []) { - parent::__construct(); - $this->setOptions($this->subOptions); + parent::__construct($this->subOptions); $this->setOptions($options); } diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index a53f09b9..5e1d937d 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -49,8 +49,7 @@ class SideBySide extends MainRenderer implements SubRendererInterface */ public function __construct(array $options = []) { - parent::__construct(); - $this->setOptions($this->subOptions); + parent::__construct($this->subOptions); $this->setOptions($options); } diff --git a/lib/jblond/Diff/Renderer/Html/Unified.php b/lib/jblond/Diff/Renderer/Html/Unified.php index 54ee60a4..e9bba020 100644 --- a/lib/jblond/Diff/Renderer/Html/Unified.php +++ b/lib/jblond/Diff/Renderer/Html/Unified.php @@ -49,8 +49,7 @@ class Unified extends MainRenderer implements SubRendererInterface */ public function __construct(array $options = []) { - parent::__construct(); - $this->setOptions($this->subOptions); + parent::__construct($this->subOptions); $this->setOptions($options); } diff --git a/lib/jblond/Diff/Renderer/Text/InlineCli.php b/lib/jblond/Diff/Renderer/Text/InlineCli.php index e454cc30..1261a721 100644 --- a/lib/jblond/Diff/Renderer/Text/InlineCli.php +++ b/lib/jblond/Diff/Renderer/Text/InlineCli.php @@ -37,8 +37,7 @@ class InlineCli extends MainRenderer implements SubRendererInterface */ public function __construct(array $options = []) { - parent::__construct(); - $this->setOptions($this->subOptions); + parent::__construct($this->subOptions); $this->setOptions($options); } From 276d84d8a4eca1dc00dcf20d2b745adcae68f582 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 7 Oct 2020 13:35:05 +0200 Subject: [PATCH 7/8] Simplify code --- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 414867f0..0c1cec40 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -54,9 +54,6 @@ public function __construct(array $options = []) */ public function render(): string { - if (!isset($this->options['cliColor'])) { - return $this->output(); - } return $this->output(); } From 8098c712490aec949828e844d43ce81ed9ee50f1 Mon Sep 17 00:00:00 2001 From: JBlond Date: Wed, 7 Oct 2020 14:16:13 +0200 Subject: [PATCH 8/8] if option is true, not only if it is set --- lib/jblond/Diff/Renderer/Text/UnifiedCli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 0c1cec40..eb19a221 100644 --- a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php +++ b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php @@ -65,7 +65,7 @@ public function render(): string */ private function colorizeString($string, $color = ''): string { - if (isset($this->options['cliColor'])) { + if ($this->options['cliColor']) { return $this->colors->getColoredString($string, $color); } return $string;