-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fix @return statements to use $this or static when relevant #21054
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
Conversation
With #21047 i also spotted some cases where I have no clear ref on this, but PhpStorm really doesnt seem to like it. Or at least not when used inconsistently so it seems 😕 (1 class mixing Perhaps worth looking at. |
@@ -42,7 +42,7 @@ public function __construct(Scope $parent = null) | |||
/** | |||
* Opens a new child scope. | |||
* | |||
* @return Scope | |||
* @return $this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be @return self
right?
this
- return exactly the same instance
self
- return new instance of exactly same type
static
- return new instance of same type or any child of type
21c14d3
to
78f726a
Compare
c66a477
to
683eaf2
Compare
I would appreciate some careful review before merging as re-reading the PR several times allowed me to fix some issues I introduced. I know, this is quite painful to do, but let's try to do it well. |
@@ -38,7 +38,7 @@ public function __construct(NodeDefinition $node) | |||
* @param string $key The key to remap | |||
* @param string $plural The plural of the key in case of irregular plural | |||
* | |||
* @return NormalizationBuilder | |||
* @return $this | |||
*/ | |||
public function remap($key, $plural = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before()
(below) can be $this|ExprBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -57,7 +57,7 @@ public function import($resource, $type = null) | |||
* @param mixed $resource A resource | |||
* @param string|null $type The resource type or null if unknown | |||
* | |||
* @return LoaderInterface A LoaderInterface instance | |||
* @return $this|self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be $this|LoaderInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -35,7 +35,7 @@ public function setHelperSet(HelperSet $helperSet = null) | |||
/** | |||
* Gets the helper set associated with this helper. | |||
* | |||
* @return HelperSet A HelperSet instance | |||
* @return HelperSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be HelperSet|null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -81,7 +81,7 @@ public function setDispatcher(EventDispatcherInterface $dispatcher) | |||
/** | |||
* Returns the EventDispatcher that dispatches this Event. | |||
* | |||
* @return EventDispatcherInterface | |||
* @return EventDispatcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventDispatcherInterface
was right? The @var
is wrong..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -27,7 +27,7 @@ class Expression implements ValueInterface | |||
/** | |||
* @param string $expr | |||
* | |||
* @return Expression | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -42,7 +42,7 @@ public function __construct(Scope $parent = null) | |||
/** | |||
* Opens a new child scope. | |||
* | |||
* @return Scope | |||
* @return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be inconsistent with a lot of changes below.. where it goes to static
for new self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If new self
is used, it should be self
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
@@ -55,7 +55,7 @@ class Regex implements ValueInterface | |||
/** | |||
* @param string $expr | |||
* | |||
* @return Regex | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self
. Im stopping here for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -52,7 +52,7 @@ public function enter() | |||
/** | |||
* Closes current scope and returns parent one. | |||
* | |||
* @return Scope|null | |||
* @return self|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should prefer using self
over the class/interface name. IMHO, we should only distinguish $this
, static
and classname
usages, but self
does not bring anything more, so it isn't worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should prefer using self over the class/interface name.
Personally, i prefer it... so while we're at it 👍 for doing this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, i prefer it...
I don't 😆
I just don't understand the motivations behind, and there are many places where this was not applied (FormFactoryBuilderInterface::getFormFactory()
for instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid duplicating terms. But you're right, if not done consistently it's not really worth it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep self
as in the code, that's also what we are using.
@@ -93,7 +93,7 @@ public static function setStyleDefinition($name, TableStyle $style) | |||
* | |||
* @param string $name The style name | |||
* | |||
* @return TableStyle A TableStyle instance | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks wrong to me. self::$styles
is an array of TableStyle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -27,7 +27,7 @@ class SyntaxErrorException extends ParseException | |||
* @param string $expectedValue | |||
* @param Token $foundToken | |||
* | |||
* @return SyntaxErrorException | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be self
(same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -38,7 +38,7 @@ public function add($child, $type = null, array $options = array()); | |||
* @param string|FormTypeInterface $type The type of the form or null if name is a property | |||
* @param array $options The options | |||
* | |||
* @return FormBuilderInterface The created builder | |||
* @return $this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks wrong to me. It doesn't return the current instance, but creates another one, for a child for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -47,7 +47,7 @@ public function create($name, $type = null, array $options = array()); | |||
* | |||
* @param string $name The name of the child | |||
* | |||
* @return FormBuilderInterface The builder for the child | |||
* @return $this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. It returns a child. Not the same instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -715,7 +715,7 @@ public function setInheritData($inheritData) | |||
* | |||
* @param bool $inheritData Whether the form should inherit its parent's data | |||
* | |||
* @return FormConfigBuilder The configuration object | |||
* @return $this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't return anything actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -349,7 +349,7 @@ public function getInheritData() | |||
/** | |||
* Alias of {@link getInheritData()}. | |||
* | |||
* @return FormConfigBuilder The configuration object | |||
* @return $this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. It returns a boolean actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm done 😅
Sorry, I've left a lot of comment related to what seems misleading usages of static
to me (see #21054 (comment)), in order to keep track of it. If you don't agree, I'll remove them.
Anyway, what a colossal job you've achieved here!
@@ -36,7 +36,7 @@ public function setParent(FormInterface $parent = null); | |||
/** | |||
* Returns the parent form. | |||
* | |||
* @return FormInterface|null The parent form or null if there is none | |||
* @return $this|null The parent form or null if there is none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong change. The returned instance is the form parent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be self|null
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -89,7 +89,7 @@ public function remove($name); | |||
/** | |||
* Returns all children in this group. | |||
* | |||
* @return FormInterface[] An array of FormInterface instances | |||
* @return FormInterface[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not self[]
then? (Related to #21054 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -70,7 +70,7 @@ | |||
* | |||
* @param Guess[] $guesses An array of guesses | |||
* | |||
* @return Guess|null The guess with the highest confidence | |||
* @return static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should keep Guess|null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or self|null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -48,7 +48,7 @@ public function __construct(array $items) | |||
* | |||
* @param string $headerValue | |||
* | |||
* @return AcceptHeader | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -57,7 +57,7 @@ public function __construct($value, array $attributes = array()) | |||
* | |||
* @param string $itemValue | |||
* | |||
* @return AcceptHeaderItem | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -302,7 +302,7 @@ public function __construct($locale = 'en', $style = null, $pattern = null) | |||
* NumberFormat::PATTERN_RULEBASED. It must conform to the syntax | |||
* described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation | |||
* | |||
* @return NumberFormatter | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -21,7 +21,7 @@ | |||
/** | |||
* Creates a property accessor with the default configuration. | |||
* | |||
* @return PropertyAccessor The new property accessor | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks wrong. (same for other changes in this class)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -52,7 +52,7 @@ public function __construct($identifier, $type) | |||
* | |||
* @param object $domainObject | |||
* | |||
* @return ObjectIdentity | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -52,7 +52,7 @@ public function __construct($username, $class) | |||
* | |||
* @param UserInterface $user | |||
* | |||
* @return UserSecurityIdentity | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -64,7 +64,7 @@ public static function fromAccount(UserInterface $user) | |||
* | |||
* @param TokenInterface $token | |||
* | |||
* @return UserSecurityIdentity | |||
* @return static | |||
*/ | |||
public static function fromToken(TokenInterface $token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did just a quick review, these are the glitches I found.
@@ -61,7 +61,7 @@ public function __toString() | |||
* | |||
* @param Command|null $parent Parent command | |||
* | |||
* @return Command New Command instance | |||
* @return static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -157,7 +157,7 @@ public function cmd($esc) | |||
* | |||
* @param string $label The unique label | |||
* | |||
* @return Command The current Command instance | |||
* @return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be self|string
, according to add()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -194,7 +194,7 @@ public function get($label) | |||
/** | |||
* Returns parent command (if any). | |||
* | |||
* @return Command Parent command | |||
* @return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self|null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so as it throws an exception is parent is null
.
@@ -178,7 +178,7 @@ public function ins($label) | |||
* | |||
* @param string $label | |||
* | |||
* @return Command The labeled command | |||
* @return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self|string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -36,7 +36,7 @@ public function setParent(FormInterface $parent = null); | |||
/** | |||
* Returns the parent form. | |||
* | |||
* @return FormInterface|null The parent form or null if there is none | |||
* @return $this|null The parent form or null if there is none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be self|null
then
@@ -80,7 +80,7 @@ public function has($name); | |||
* | |||
* @param string $name The name of the child to remove | |||
* | |||
* @return FormInterface The form instance | |||
* @return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually $this
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -70,7 +70,7 @@ | |||
* | |||
* @param Guess[] $guesses An array of guesses | |||
* | |||
* @return Guess|null The guess with the highest confidence | |||
* @return static|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or self|null
@@ -191,7 +191,7 @@ public function getStatusCode() | |||
/** | |||
* Finds children profilers. | |||
* | |||
* @return Profile[] An array of Profile | |||
* @return Profile[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@wouterj @ogizanagi @ro0NL Thank you very much for your reviews. I think we're good now. |
@fabpot are you planning to do all branches? |
…ant (fabpot) This PR was merged into the 2.7 branch. Discussion ---------- Fix @return statements to use $this or static when relevant | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20290 | License | MIT | Doc PR | n/a see #20290 Commits ------- 3c0693d fixed @return when returning this or static
This PR was merged into the 2.8 branch. Discussion ---------- fixed @return when returning this or static | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Follow-up of #21054 for the 2.8 branch. Commits ------- 7808b67 fixed @return when returning this or static
…terface (wouterj) This PR was merged into the 2.7 branch. Discussion ---------- Fixed `@return self` with `$this` in FormConfigBuilderInterface | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Fixes a tiny bug introduced by #21054 . `FormConfigBuilder` methods actually return `$this` and not `self`. This is important, as the `FormBuilder` (extending `FormConfigBuilder`) methods can also be called (e.g. `$builder->setDataMapper(...)->add()` is perfectly possible). Commits ------- 505e84d Fixed `@return self` with `$this`
see #20290