-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Yaml: check if $tags is an array before using it #21348
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
dunglas
commented
Jan 19, 2017
Q | A |
---|---|
Branch? | master |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | n/a |
License | MIT |
Doc PR | n/a |
@@ -331,7 +331,15 @@ private function parseDefinition($id, $service, $file, array $defaults) | |||
} | |||
} | |||
|
|||
$tags = isset($service['tags']) ? $service['tags'] : array(); |
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 think this line was fine, just add if (!is_array($tags)) {
on the next line
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.
shouldn't this PR be applied on a lower branch btw?
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 but it adds 1 useless check when $service['tags']
is not set.
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.
No the branch is correct (this "bug" was introduced by _defaults
in #21071).
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 adds 1 useless check
yes, but we don't care, readibility is more important here (thinking about the complexity of nested if/else blocks) IMHO
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 usually prefer if
/else
than the ternary operator but it's probably because I need glasses to read on a screen.
I'll change 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.
done
We should add a test then to avoid future regressions. |
@xabbuh test added |
Tests fail :) |
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.
👍
Status: Reviewed
|
||
Foo\Bar: | ||
tags: invalid | ||
inherit_tags: true |
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 find this test confusing. Intuitively, I thought that tags were inherited and then validated, so the Foo\Bar
service has the valid tags: ['foo']
tags instead of tags: invalid
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.
But this way (using a string instead of an array) to specify tags already wasn't supported before. Why should we do that now?
Thank you @dunglas. |
…efore using it (dunglas) This PR was squashed before being merged into the 3.3-dev branch (closes #21348). Discussion ---------- [DependencyInjection] Yaml: check if $tags is an array before using it | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 1c9b5c9 [DependencyInjection] Yaml: check if is an array before using it