Skip to content

[DependencyInjection] Handle ServiceClosureArgument for callable in container linting #35225

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

Merged

Conversation

shieldo
Copy link
Contributor

@shieldo shieldo commented Jan 6, 2020

Q A
Branch? 4.4 (+)
Bug fix? yes
New feature? no
Deprecations? no
Tickets (none)
License MIT

Making use of ServiceClosureArgument instances in service definitions was not accounted for in container linting when a service type-hints for callable in an argument - adding this check ensures that ServiceClosureArgument instances are recognised correctly as callables (once they are resolved).

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Jan 6, 2020
@nicolas-grekas nicolas-grekas changed the title [DependencyInjection] Handle ServiceClosureArgument for callable in c… [DependencyInjection] Handle ServiceClosureArgument for callable in container linting Jan 6, 2020
@@ -219,6 +220,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
return;
}

if ('callable' === $type && $value instanceof ServiceClosureArgument) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you maybe add this case in the previous condition so we only have 1 if for callable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but also considered that it might make that clause unreadable. I'll happily add it in though if that's the consensus here.

Copy link
Member

Choose a reason for hiding this comment

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

should we accept \Closure::class also btw?

Copy link
Contributor

@fancyweb fancyweb Jan 6, 2020

Choose a reason for hiding this comment

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

@shieldo I mean:

if ('callable' === $type) {
    if (\is_array($value)/* etc. */) {
        return;
    }

    if ($value instanceof ServiceClosureArgument) {
        return;
    }
}

And that's just a suggestion ofc :)

Copy link
Contributor Author

@shieldo shieldo Jan 6, 2020

Choose a reason for hiding this comment

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

@nicolas-grekas I think that was done in the previous commit d6a7fbf unless I'm mistaken?

(Do you think I should follow the suggestion from @fancyweb above?)

Copy link
Member

@nicolas-grekas nicolas-grekas Jan 6, 2020

Choose a reason for hiding this comment

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

I mean:
if ('callable' === $type || 'Closure' === $type) && $value instanceof ServiceClosureArgument) {

(about the CS, I'm fine with the original proposal personally.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK @fancyweb I've updated as per your suggestion - I think that's a pretty happy medium :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas I'd agree with that (and would also undo my previous change to make a distinct case in the code for that, as well as providing a new test). @fancyweb Make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do it @shieldo, we indeed need to support the \Closure case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to handle a \Closure type hint

@shieldo shieldo force-pushed the handle_service_closure_args_in_lint branch 2 times, most recently from 9f49d73 to 03cbbf5 Compare January 6, 2020 14:35
@shieldo shieldo force-pushed the handle_service_closure_args_in_lint branch from 03cbbf5 to 11e4fe1 Compare January 7, 2020 10:30
@nicolas-grekas nicolas-grekas force-pushed the handle_service_closure_args_in_lint branch from 11e4fe1 to e48829e Compare January 7, 2020 10:57
@nicolas-grekas
Copy link
Member

Thank you @shieldo.

nicolas-grekas added a commit that referenced this pull request Jan 7, 2020
…llable in container linting (shieldo)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection] Handle ServiceClosureArgument for callable in container linting

| Q             | A
| ------------- | ---
| Branch?       | 4.4 (+)
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | (none)
| License       | MIT

Making use of `ServiceClosureArgument` instances in service definitions was not accounted for in container linting when a service type-hints for `callable` in an argument - adding this check ensures that `ServiceClosureArgument` instances are recognised correctly as callables (once they are resolved).

Commits
-------

e48829e [DependencyInjection] Handle ServiceClosureArgument for callable in container linting
@nicolas-grekas nicolas-grekas merged commit e48829e into symfony:4.4 Jan 7, 2020
@shieldo shieldo deleted the handle_service_closure_args_in_lint branch January 7, 2020 11:58
This was referenced Jan 21, 2020
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.

5 participants