Completed
Push — master ( 23bc19...2eec4d )
by Tomáš
11:42
created

ExtensionHelperTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addServicesToCollector() 0 15 2
A getDefinitionByType() 0 7 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\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 1
    private function addServicesToCollector(
19
        string $collectorClass,
20
        string $collectedClass,
21
        string $adderMethodName
22
    ) {
23 1
        $containerBuilder = $this->getContainerBuilder();
24 1
        $collectorDefinition = $this->getDefinitionByType($collectorClass);
25
26 1
        foreach ($containerBuilder->findByType($collectedClass) as $definition) {
27 1
            $collectorDefinition->addSetup(
28
                $adderMethodName,
29 1
                ['@'.$definition->getClass()]
30
            );
31
        }
32 1
    }
33
34 1
    private function getDefinitionByType(string $type) : ServiceDefinition
35
    {
36 1
        $containerBuilder = $this->getContainerBuilder();
37 1
        $definitionName = $containerBuilder->getByType($type);
38
39 1
        return $containerBuilder->getDefinition($definitionName);
40
    }
41
}
42