Skip to content

Php diff 60 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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