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

ExtensionHelperTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addServicesToCollector() 0 12 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
    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