-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DI] Add compiler pass to check arguments type hint #27825
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
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4b59201
[#27744] Add compiler pass to check arguments type hint
alcalyn 1aefc17
update phpdoc
alcalyn cc8c4de
add missing case with 'iterable' type hint
alcalyn ddba549
lint:container command
alcalyn 9740eee
handle case when passing array to Traversable, ignore definitions con…
alcalyn 361e8a6
command lint:container allows to check only used services
alcalyn b305a69
lint
alcalyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
handle case when passing array to Traversable, ignore definitions con…
…taining another Definition
- Loading branch information
commit 9740eee73ff054196cade72c1444966773ce99dc
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeHintException; | ||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument; | ||
|
@@ -58,6 +59,10 @@ protected function processValue($value, $isRoot = false) | |
return parent::processValue($value, $isRoot); | ||
} | ||
|
||
if ($value->getClass() === ServiceLocator::class) { | ||
return parent::processValue($value, $isRoot); | ||
} | ||
|
||
if (null !== $constructor = $this->getConstructor($value, false)) { | ||
$this->checkArgumentsTypeHints($constructor, $value->getArguments()); | ||
} | ||
|
@@ -142,6 +147,10 @@ private function checkTypeHint($configurationArgument, \ReflectionParameter $par | |
return; | ||
} | ||
|
||
if ('Traversable' === $parameter->getType()->getName() && $configurationArgument instanceof IteratorArgument) { | ||
return; | ||
} | ||
|
||
$checkFunction = 'is_'.$parameter->getType()->getName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (!$parameter->getType()->isBuiltin() || !$checkFunction($configurationArgument)) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CC53
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.
Personally, I do not like this, as it seems that iterable and Traversable seems to be case sensitive.
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.
iterable
does seem to be case insensitive as it's a php builtin type, however Traversable is case sensitive indeed.