Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Fluent Interface missing on ConsoleModel::setErrorLevel #153

Closed
wants to merge 1 commit into from

Conversation

porebskk
Copy link

Hello,

contrary to almost all other setter methods on classes that implement the ModelInterface, ConsoleModel::setErrorLevel ist not returning itself when the method is called.
I would assume that it would return $this.

Best regards

$actual = $model->setErrorLevel(0);
$this->assertSame($model, $actual);
}
}
Copy link
Contributor

@thexpand thexpand Aug 15, 2018

Choose a reason for hiding this comment

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

A new line is missing here (at the end of the file), causing the build to fail.

@@ -0,0 +1,26 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

public function testImplementsModelInterface()
{
$model = new ConsoleModel();
$this->assertInstanceOf('Zend\View\Model\ModelInterface', $model);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use the class constant, instead of writing the FQN as a string.

Copy link
Member

@froschdesign froschdesign left a comment

Choose a reason for hiding this comment

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

Please also note the comments from @thexpand. Thank you in advance!

@@ -31,10 +31,12 @@ class ConsoleModel extends ViewModel
* Set error level to return after the application ends.
*
* @param int $errorLevel
* @return $this
Copy link
Member

Choose a reason for hiding this comment

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

Please use self here.

Copy link
Member

Choose a reason for hiding this comment

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

@froschdesign why self? I think $this is the most right here, as we return the same instance, not the new one. I think this is also what is suggested in PSR-5 draft: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md - check the bottom of the document: points 13-15.

Copy link
Member

Choose a reason for hiding this comment

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

@webimpress
I would like to remove it completely! (>=7.1)

Copy link
Member

Choose a reason for hiding this comment

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

@froschdesign Removing them is a different story and this is not answer for my question, why you think self is more appropriate here ;-)
As I understand fluent interfaces makes sens in some cases, and not always they are "evil".
https://ocramius.github.io/blog/fluent-interfaces-are-evil/

Copy link
Member

Choose a reason for hiding this comment

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

@webimpress
No, I mean remove the return type in the DocBlock.

Copy link
Member

Choose a reason for hiding this comment

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

@froschdesign I think what was decided in ZF is to remove them (PHPDocs) only if they are not providing any additional information. And in that case, even if we add RTH : self still @return $this gives us more information about returned object (as described - in quoted before - PSR-5 draft).

Copy link
Member

Choose a reason for hiding this comment

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

Then I will stop the discussion here. It makes no sense without any coding standard.

Copy link
Member

Choose a reason for hiding this comment

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

@weierophinney weierophinney added this to the 2.11.0 milestone Dec 6, 2018
weierophinney added a commit that referenced this pull request Dec 6, 2018
@weierophinney
Copy link
Member

Thanks, @porebskk. I made some minor consistency changes to the unit test, and cherry-picked this against develop for release with 2.11.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants