Completed
Pull Request — master (#6)
by Tomáš
03:49
created

TurnOnAutowireCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 4
c 5
b 2
f 0
lcom 1
cbo 3
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\DefaultAutowire\DependencyInjection\Compiler;
9
10
use ReflectionClass;
11
use ReflectionMethod;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symplify\DefaultAutowire\DependencyInjection\Definition\DefinitionAnalyzer;
16
17
final class TurnOnAutowireCompilerPass implements CompilerPassInterface
18
{
19
    /**
20
     * @var DefinitionAnalyzer
21
     */
22
    private $definitionAnalyzer;
23
24 2
    public function __construct(DefinitionAnalyzer $definitionAnalyzer)
25
    {
26 2
        $this->definitionAnalyzer = $definitionAnalyzer;
27 2
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    public function process(ContainerBuilder $containerBuilder)
33
    {
34 2
        foreach ($containerBuilder->getDefinitions() as $definition) {
35 2
            if ($this->definitionAnalyzer->shouldDefinitionBeAutowired($definition)) {
36 2
                $definition->setAutowired(true);
37
            }
38
        }
39 2
    }
40
}
41