-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config] Handle nullable node name + fix inheritdocs #26335
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
Added all fixes that can be merged until master. Ill change #26297 to backport |
@@ -40,7 +40,7 @@ | ||
*/ | ||
public function __construct($name, NodeInterface $parent = null) | ||
{ | ||
if (false !== strpos($name, '.')) { | ||
if (null !== $name && false !== strpos($name, '.')) { |
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 cast to string instead?
if (false !== strpos($name = (string) $name, '.')) {
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.
yes, better. Now updated.
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.
Didnt reassign $name
btw... we need to preserve string|null on the property side. Or put different: im not sure about changing that.
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.
we need to preserve string|null on the property side
why? would need a side effect, which one is it? casting all the time is hurting perf, that's not the side effect I'd consider good ;)
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.
which one is it?
BC... (protected $name;
). Also the constructor sig kinda implies a nullable value.
Then again.. if i got this right, it shouldnt hurt indeed. AFAIK prototyped nodes will have a string name (setName()
) once being dealt with. And the calling side needs to expect string anyway due getName()
.
Given $arr[null] = ..
equals $arr[''] = ...
(see remaining issue) i think it's safe to make the change 👍
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.
the constructor sig kinda implies a nullable value
not the docblock, isn't it? I'd support doing the change :)
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.
touche. It does in 4.0 though. Now updated.
found a few more, derived from NodeInterface/PrototypeNodeInterface 😅 |
@@ -83,6 +89,9 @@ public function merge($leftSide, $rightSide); | ||
* @param mixed $value The value to finalize | ||
* | ||
* @return mixed The finalized value | ||
* | ||
* @throws Exception |
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.
All @throws
should have a description explaining when the exception can be triggered... or be removed :)
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.
Now updated.
* | ||
* @param mixed $value The value to normalize | ||
* @param mixed $value Value to normalize |
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.
maybe A value to normalize
?
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.
in fact.. i think i should revert this one as the interface was already using different syntax:
https://github.com/symfony/symfony/pull/26335/files#diff-41913ce7a681852774440044e2c091bdR92
@@ -40,7 +40,7 @@ | ||
*/ | ||
public function __construct($name, NodeInterface $parent = null) | ||
{ | ||
if (false !== strpos($name, '.')) { | ||
if (false !== strpos($name = (string) $name, '.')) { |
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.
$name
must be a string, so casting here should be removed. Adding this is not a bug fix.
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.
in 4.0 it's string|null
already
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR) |
hence #26297
practically using null
is just an alias for empty string, but we use null by design (as of 2.7!):
symfony/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php
Lines 75 to 78 in d65c43b
public function prototype($type) | |
{ | |
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this); | |
} |
if we preserve null
on the property side (thus no cast) we keep violating getName
:
symfony/src/Symfony/Component/Config/Definition/BaseNode.php
Lines 223 to 225 in d65c43b
* @return string The Node's name | |
*/ | |
public function getName() |
hence the cast
Thank you @ro0NL. |
…0NL) This PR was squashed before being merged into the 2.7 branch (closes #26335). Discussion ---------- [Config] Handle nullable node name + fix inheritdocs | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no-ish | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Small split from #26297 that can be merged until master/4.1. Whereas the doc fixes only apply until 3.4, hence the split. Small change regarding `getName/Path()` for not returning a `null` value anymore which violates `NodeInterface::getName/Path()` Remainng issue left at https://github.com/symfony/symfony/blob/cd5f4105a43208632c8b62fd75b4dad53dcd8a41/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php#L381-L383 which i tend to leave untouched across all branches for now. Commits ------- 5c3e6a9 [Config] Handle nullable node name + fix inheritdocs
Small split from #26297 that can be merged until master/4.1. Whereas the doc fixes only apply until 3.4, hence the split.
Small change regarding
getName/Path()
for not returning anull
value anymore which violatesNodeInterface::getName/Path()
Remainng issue left at
symfony/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php
Lines 381 to 383 in cd5f410
which i tend to leave untouched across all branches for now.