Skip to content

Commit

Permalink
Merge pull request #61 from JBlond/php-dif-60
Browse files Browse the repository at this point in the history
Php diff 60
  • Loading branch information
JBlond authored Oct 8, 2020
2 parents 1a71822 + 8098c71 commit 3940323
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$renderer = new UnifiedCli(
// Define renderer options.
[
'cliColor' => 'simple',
'cliColor' => true,
]
);

Expand Down
3 changes: 1 addition & 2 deletions lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/jblond/Diff/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/jblond/Diff/Renderer/Html/Unified.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/jblond/Diff/Renderer/MainRendererAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions lib/jblond/Diff/Renderer/Text/InlineCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 12 additions & 10 deletions lib/jblond/Diff/Renderer/Text/UnifiedCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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();
}


Expand All @@ -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;
Expand Down

0 comments on commit 3940323

Please sign in to comment.