Completed
Branch master (c5ceed)
by Tomáš
33:54 queued 13:17
created

ExtensionHelperTrait::addServicesToCollector()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 6
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\PHP7_CodeSniffer\DI;
9
10
use Nette\DI\ContainerBuilder;
11
use Nette\DI\ServiceDefinition;
12
13
/**
14
 * @method ContainerBuilder getContainerBuilder()
15
 */
16
trait ExtensionHelperTrait
17
{
18
    private function addServicesToCollector(string $collectorClass, string $collectedClass, string $adderMethodName)
19
    {
20
        $collectorDefinition = $this->getDefinitionByType($collectorClass);
21
        $containerBuilder = $this->getContainerBuilder();
22
23
        foreach ($containerBuilder->findByType($collectedClass) as $definition) {
24
            $collectorDefinition->addSetup(
25
                $adderMethodName,
26
                ['@'.$definition->getClass()]
27
            );
28
        }
29
    }
30
31
    private function getDefinitionByType(string $type) : ServiceDefinition
32
    {
33
        $containerBuilder = $this->getContainerBuilder();
34
        $definitionName = $containerBuilder->getByType($type);
35
36
        return $containerBuilder->getDefinition($definitionName);
37
    }
38
}
39