Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 7 commits into from
Closed

[Config] Handle nullable node name + fix inheritdocs #26335

wants to merge 7 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Feb 27, 2018

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no-ish
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

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

public function append(NodeDefinition $node)
{
$this->children[$node->name] = $node->setParent($this);

which i tend to leave untouched across all branches for now.

@ro0NL ro0NL changed the title [Config] Handle nullable node name [Config] Handle nullable node name + fix inheritdocs Feb 27, 2018
@ro0NL
Copy link
Contributor Author

ro0NL commented Feb 27, 2018

Added all fixes that can be merged until master. Ill change #26297 to backport string|null fixes soley (which are type declarations as of 4.0>

@@ -40,7 +40,7 @@
*/
public function __construct($name, NodeInterface $parent = null)
{
if (false !== strpos($name, '.')) {
if (null !== $name && false !== strpos($name, '.')) {
Copy link
Member

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, '.')) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, better. Now updated.

Copy link
Contributor Author

@ro0NL ro0NL Feb 27, 2018

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.

Copy link
Member

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 ;)

Copy link
Contributor Author

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 👍

Copy link
Member

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 :)

Copy link
Contributor Author

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.

@ro0NL
Copy link
Contributor Author

ro0NL commented Feb 27, 2018

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
Copy link
Member

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 :)

Copy link
Contributor Author

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
Copy link
Contributor

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 ?

Copy link
Contributor Author

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, '.')) {
Copy link
Member

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.

Copy link
Contributor Author

@ro0NL ro0NL Mar 5, 2018

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!):

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:

* @return string The Node's name
*/
public function getName()

hence the cast

@nicolas-grekas
Copy link
Member

Thank you @ro0NL.

nicolas-grekas added a commit that referenced this pull request Mar 19, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.