ExtensionHelperTrait   A
last analyzed

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