Skip to content

[DI] Improve error message for non-autowirable scalar argument #26856

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
merged 1 commit into from
Apr 10, 2018

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #26838
License MIT
Doc PR -

if ($type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, false)) {
$message = 'Cannot autowire service "%s": argument "%s $%s" of method "%s()" must be given a value explicitly.';
} else {
$message = 'Cannot autowire service "%s": argument "%s$%s" of method "%s()" must have a type-hint or be given a value explicitly.';
Copy link
Contributor

Choose a reason for hiding this comment

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

just adding a type hint does not neccessarily help like string. So maybe it should say something like "must have a known type-hint".

@nicolas-grekas
Copy link
Member Author

message updated

@@ -233,7 +233,10 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
if ($parameter->isOptional()) {
continue;
}
throw new AutowiringFailedException($this->currentId, sprintf('Cannot autowire service "%s": argument "$%s" of method "%s()" must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
$type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, false);
$type = $type ? sprintf('is type-hinted "%s"', $type) : 'has not type-hint';
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: has no type-hint

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@Tobion
Copy link
Contributor

Tobion commented Apr 10, 2018

Thank you @nicolas-grekas.

@Tobion Tobion merged commit 7f39811 into symfony:3.4 Apr 10, 2018
Tobion added a commit that referenced this pull request Apr 10, 2018
…gument (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Improve error message for non-autowirable scalar argument

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26838
| License       | MIT
| Doc PR        | -

Commits
-------

7f39811 [DI] Improve error message for non-autowirable scalar argument
@nicolas-grekas nicolas-grekas deleted the di-type-msg branch April 14, 2018 22:19
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.

4 participants