diff --git a/README.md b/README.md index d8c37cfd..60609a09 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/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/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, diff --git a/lib/jblond/Diff/Renderer/Text/InlineCli.php b/lib/jblond/Diff/Renderer/Text/InlineCli.php index 869b7578..e86c9f82 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); } diff --git a/lib/jblond/Diff/Renderer/Text/UnifiedCli.php b/lib/jblond/Diff/Renderer/Text/UnifiedCli.php index 2f5007d2..eb19a221 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; } /** @@ -46,13 +54,7 @@ public function __construct(array $options = []) */ public function render(): string { - if (!isset($this->options['cliColor'])) { - return $this->output(); - } - if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') { - return $this->output(); - } - throw new InvalidArgumentException('Invalid cliColor option'); + return $this->output(); } @@ -63,7 +65,7 @@ public function render(): string */ private function colorizeString($string, $color = ''): string { - if (isset($this->options['cliColor']) && $this->options['cliColor'] == 'simple') { + if ($this->options['cliColor']) { return $this->colors->getColoredString($string, $color); } return $string;