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

TurnOnAutowireCompilerPass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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