8000 [DI] Add compiler pass to check arguments type hint by alcalyn · Pull Request #27825 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle case when passing array to Traversable, ignore definitions con…
…taining another Definition
  • Loading branch information
alcalyn committed Jul 12, 2018
commit 9740eee73ff054196cade72c1444966773ce99dc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -142,6 +147,10 @@ private function checkTypeHint($configurationArgument, \ReflectionParameter $par
return;
}

if ('Traversable' === $parameter->getType()->getName() && $configurationArgument instanceof IteratorArgument) {
Copy link

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.

Copy link
Contributor

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.

return;
}

$checkFunction = 'is_'.$parameter->getType()->getName();
Copy link

Choose a reason for hiding this comment

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

sprintf('is_%s', $parameter->getType()->getName()) can be used here. Looks more neat than appending


if (!$parameter->getType()->isBuiltin() || !$checkFunction($configurationArgument)) {
Expand Down
0