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

Php diff 60 #61

merged 9 commits into from
Oct 8, 2020

Conversation

JBlond
Copy link
Owner

@JBlond JBlond commented Oct 6, 2020

No description provided.

@@ -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']) && $this->options['cliColor'] === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if ($this->options['cliColor']) { is sufficient.

The variable should be set already by MainRendererAbstract and acting on any truthy value is ok.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed that

@@ -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']) && $this->options['cliColor'] === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if ($this->options['cliColor']) { is sufficient.

The variable should be set already by MainRendererAbstract and acting on any truthy value is ok.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed that.

Copy link
Collaborator

@DigiLive DigiLive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some inline comments.

@@ -49,10 +49,7 @@ public function render(): string
if (!isset($this->options['cliColor'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->options['cliColor'] should be set by MainRendererAbstract.
Therefor this line will always evaluate to true.

Please also check remaining code which uses this variable.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not always true. I check that via the example/cli.php script.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I'm saying 'should' while it's not. 😉
When extending MainRendererAbstract, the options for a sub renderer are supposed to be a merge of:

  • MainRendererAbstract::$mainOptions (Default renderer options)
  • SubRenderer::$subOptions (Default child renderer options)
  • The array parameter of SubRenderer::__construct() (custom options).

SubRenderer::__construct() should look something like:

    public function __construct(array $options = [])
    {
        parent::__construct();
        $this->setOptions($this->subOptions); // Override/Add options MainRenderer with defaults of SubRenderer.
        $this->setOptions($options); // Override/Add options MainRenderer with customs.
    }

Method setOptions, inherited from MainRendererAbstract, will take care of the merges.

Currently UnifiedCli::__construct() is different:

    public function __construct(array $options = [])
    {
        parent::__construct($options);
        $this->colors = new CliColors();
        $this->options = $options;
    }

You can look at InlineCli.php as an example on how to apply options.
Also it's described at https://github.com/JBlond/php-diff/wiki/b)-Parameters-and-Options#parameters-1
and https://github.com/JBlond/php-diff/wiki/b)-Parameters-and-Options#text-unified-cli-renderer

@DigiLive
Copy link
Collaborator

DigiLive commented Oct 7, 2020

Please also check remaining code which uses $this->options.
Line 57-59 can be removed?
Line 71 always evaluates to true? Remove isset function?

@JBlond
Copy link
Owner Author

JBlond commented Oct 7, 2020

Please also check remaining code which uses $this->options.

I did.

Line 57-59 can be removed?

Yes

Line 71 always evaluates to true? Remove isset function?

Nope, in doubt the colorizeString function returns the string as is.

@DigiLive
Copy link
Collaborator

DigiLive commented Oct 7, 2020

Nope, in doubt the colorizeString function returns the string as is.

I'm not sure what 'In doubt' means.

Currently:

  • $string is colorized when the option is set (Which what MainRenderAbstract will do), no matter the value is a truthy or falsy.
  • $string is returned as is when the option isn't set (But it will be set by MainRendererAbstract::__construct() calling MainRendererAbstract::setOptions()).

Expected:

  • $string is colorized when the option is set and the value is a truthy.
  • $string is returned as is when the option isn't set or when the value is a falsy.

Having if ($this->options['cliColor']) {...
The way I see it, $this->options['cliColor'] is either set (by the MainRenderer) and its value is a truthy or falsy, or it isn't set which evaluates to a falsy also. (https://3v4l.org/vGsYB)

Copy link
Collaborator

@DigiLive DigiLive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's all ok now.
Maybe we should user ask/warn vendeeglobe there's a PR merge comming up and ask for his feedback.

@JBlond
Copy link
Owner Author

JBlond commented Oct 8, 2020

@vendeeglobe please give feedback to this PR.

@vendeeglobe
Copy link

Looks good to me. I'll pull and test it after it's merged into master.

@JBlond JBlond merged commit 3940323 into master Oct 8, 2020
@JBlond JBlond deleted the php-dif-60 branch October 8, 2020 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants