Completed
Push — master ( 288a92...69853c )
by Samuel
63:45
created

PublicForTestsCompilerPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 4
A isPHPUnit() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ivory\SerializerBundle\DependencyInjection\Compiler;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
class PublicForTestsCompilerPass implements CompilerPassInterface
11
{
12
    public function process(ContainerBuilder $container)
13
    {
14
        if (!$this->isPHPUnit()) {
15
            return;
16
        }
17
18
        foreach ($container->getDefinitions() as $definition) {
19
            $definition->setPublic(true);
20
        }
21
22
        foreach ($container->getAliases() as $definition) {
23
            $definition->setPublic(true);
24
        }
25
    }
26
27
    private function isPHPUnit(): bool
28
    {
29
        // there constants are defined by PHPUnit
30
        return defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__');
31
    }
32
}
33