1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the doyo/code-coverage project. |
||
5 | * |
||
6 | * (c) Anthonius Munthi <https://itstoni.com> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Doyo\Behat\CodeCoverage; |
||
15 | |||
16 | use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
||
17 | use Behat\Testwork\ServiceContainer\ExtensionManager; |
||
18 | use Doyo\Behat\CodeCoverage\Controller\CliController; |
||
19 | use Doyo\Behat\CodeCoverage\Listener\CoverageListener; |
||
20 | use Doyo\Bridge\CodeCoverage\Configuration; |
||
21 | use Doyo\Bridge\CodeCoverage\ContainerFactory; |
||
22 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
23 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
24 | use Symfony\Component\DependencyInjection\Definition; |
||
25 | use Symfony\Component\DependencyInjection\Reference; |
||
26 | |||
27 | class Extension implements ExtensionInterface |
||
28 | { |
||
29 | public function process(ContainerBuilder $container) |
||
30 | { |
||
31 | } |
||
32 | |||
33 | public function getConfigKey() |
||
34 | { |
||
35 | return 'doyo_coverage'; |
||
36 | } |
||
37 | |||
38 | public function initialize(ExtensionManager $extensionManager) |
||
39 | { |
||
40 | // TODO: Implement initialize() method. |
||
41 | } |
||
42 | |||
43 | public function configure(ArrayNodeDefinition $builder) |
||
44 | { |
||
45 | $configuration = new Configuration(); |
||
46 | $configuration->configure($builder); |
||
47 | |||
48 | return $builder; |
||
49 | } |
||
50 | |||
51 | public function load(ContainerBuilder $container, array $config) |
||
52 | { |
||
53 | $definition = new Definition(CliController::class); |
||
54 | $definition->setPublic(true); |
||
55 | $definition->addTag('cli.controller', ['priority' => 80000]); |
||
56 | $container->setDefinition('doyo.coverage.cli_controller', $definition); |
||
57 | |||
58 | // load listener |
||
59 | $coverageContainer = (new ContainerFactory($config, true))->getContainer(); |
||
0 ignored issues
–
show
|
|||
60 | $coverageContainer->set('console.input', $container->get('cli.input')); |
||
61 | $coverageContainer->set('console.output', $container->get('cli.output')); |
||
62 | |||
63 | $container->set('doyo.coverage.container', $coverageContainer); |
||
64 | $container->set('doyo.coverage', $coverageContainer->get('coverage')); |
||
65 | |||
66 | /* @var \Symfony\Component\Console\Input\InputInterface $input */ |
||
67 | $input = $container->get('cli.input'); |
||
68 | $coverageEnabled = $input->hasParameterOption(['--coverage']); |
||
69 | $container->setParameter('doyo.coverage_enabled', $coverageEnabled); |
||
70 | |||
71 | $listener = new Definition(CoverageListener::class); |
||
72 | $listener->addArgument(new Reference('doyo.coverage')); |
||
73 | $listener->addArgument($container->getParameterBag()->get('doyo.coverage_enabled')); |
||
74 | $listener->addTag('event_dispatcher.subscriber'); |
||
75 | |||
76 | $container->setDefinition('doyo.coverage.listener', $listener); |
||
77 | } |
||
78 | } |
||
79 |
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. Please note the @ignore annotation hint above.