These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\IntlBundle\Tests\DependencyInjection\Compiler; |
||
15 | |||
16 | use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
||
17 | use Sonata\IntlBundle\DependencyInjection\Compiler\StrictPass; |
||
18 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
19 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
20 | use Symfony\Component\DependencyInjection\Definition; |
||
21 | use Symfony\Component\DependencyInjection\Reference; |
||
22 | |||
23 | class StrictPassTest extends AbstractCompilerPassTestCase |
||
24 | { |
||
25 | protected function setUp(): void |
||
26 | { |
||
27 | parent::setUp(); |
||
28 | |||
29 | if (!method_exists('Symfony\Component\DependencyInjection\Reference', 'isStrict')) { |
||
30 | $this->markTestSkipped('Requires Symfony 2.x'); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | public function testStrictParameter(): void |
||
35 | { |
||
36 | $requestDef = new Definition(); |
||
37 | $requestDef->addArgument(new Reference('service_container', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)); |
||
0 ignored issues
–
show
|
|||
38 | |||
39 | $this->setDefinition('sonata.intl.locale_detector.request', $requestDef); |
||
40 | |||
41 | $sessionDef = new Definition(); |
||
42 | $sessionDef->addArgument(new Reference('session', ContainerInterface::NULL_ON_INVALID_REFERENCE, false)); |
||
0 ignored issues
–
show
The call to
Reference::__construct() has too many arguments starting with false .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
43 | |||
44 | $this->setDefinition('sonata.intl.locale_detector.session', $sessionDef); |
||
45 | |||
46 | $this->compile(); |
||
47 | |||
48 | $this->assertFalse($requestDef->getArgument(0)->isStrict()); |
||
49 | $this->assertFalse($sessionDef->getArgument(0)->isStrict()); |
||
50 | } |
||
51 | |||
52 | protected function registerCompilerPass(ContainerBuilder $container): void |
||
53 | { |
||
54 | $container->addCompilerPass(new StrictPass()); |
||
55 | } |
||
56 | } |
||
57 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.