1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the doyo/code-coverage project. |
||
5 | * |
||
6 | * (c) Anthonius Munthi <[email protected]> |
||
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\Bridge\CodeCoverage\Compiler; |
||
15 | |||
16 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
||
0 ignored issues
–
show
|
|||
17 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | use Symfony\Component\DependencyInjection\Definition; |
||
0 ignored issues
–
show
The type
Symfony\Component\DependencyInjection\Definition was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
19 | use Symfony\Component\DependencyInjection\Reference; |
||
0 ignored issues
–
show
The type
Symfony\Component\DependencyInjection\Reference was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
20 | |||
21 | class CoveragePass implements CompilerPassInterface |
||
22 | { |
||
23 | public function process(ContainerBuilder $container) |
||
24 | { |
||
25 | $this->processDriver($container); |
||
26 | $this->processFilter($container); |
||
27 | } |
||
28 | |||
29 | private function processDriver(ContainerBuilder $container) |
||
30 | { |
||
31 | $driverClass = $container->get('runtime')->getDriverClass(); |
||
32 | $container->getParameterBag()->set('coverage.driver.class', $driverClass); |
||
33 | |||
34 | $r = new \ReflectionClass($driverClass); |
||
35 | if ($r->hasMethod('setFilter')) { |
||
36 | $definition = $container->getDefinition('coverage.filter'); |
||
37 | $definition->addMethodCall('setFilter', [new Reference('coverage.filter')]); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | private function processFilter(ContainerBuilder $container) |
||
42 | { |
||
43 | $config = $container->getParameter('config.filter'); |
||
44 | $definition = $container->getDefinition('coverage.filter'); |
||
45 | |||
46 | foreach ($config as $options) { |
||
47 | $options['basePath'] = ''; |
||
48 | $this->filterWhitelist($definition, $options, 'add'); |
||
49 | $exclude = $options['exclude']; |
||
50 | foreach ($exclude as $item) { |
||
51 | $item['basePath'] = ''; |
||
52 | $this->filterWhitelist($definition, $item, 'remove'); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | |||
57 | private function filterWhitelist(Definition $definition, $options, $method) |
||
58 | { |
||
59 | $basePath = $options['basePath']; |
||
0 ignored issues
–
show
|
|||
60 | $suffix = $options['suffix'] ?: '.php'; |
||
61 | $prefix = $options['prefix'] ?: ''; |
||
62 | $type = $options['directory'] ? 'directory' : 'file'; |
||
63 | $directory = $options['directory']; |
||
64 | $file = $options['file']; |
||
65 | |||
66 | if (preg_match('/\/\*(\..+)/', $directory, $matches)) { |
||
67 | $suffix = $matches[1]; |
||
68 | $directory = str_replace($matches[0], '', $directory); |
||
69 | } |
||
70 | |||
71 | $methodSuffix = 'add' === $method ? 'ToWhitelist' : 'FromWhitelist'; |
||
72 | if ('directory' === $type) { |
||
73 | $definition->addMethodCall($method.'Directory'.$methodSuffix, [$directory, $suffix, $prefix]); |
||
74 | } |
||
75 | |||
76 | if ('file' === $type) { |
||
77 | $definition->addMethodCall($method.'File'.$methodSuffix, [$file]); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths