ServicesByTypeMap   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B addService() 0 16 5
A getMap() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\ActionAutowire\DependencyInjection\Container;
11
12
use ReflectionClass;
13
14
/**
15
 * Inspired by ClassMultiMap
16
 * https://github.com/skrz/autowiring-bundle/blob/master/DependencyInjection/ClassMultiMap.php.
17
 */
18
final class ServicesByTypeMap
19
{
20
    /**
21
     * @var string[]
22
     */
23
    private $classes = [];
24
25 2
    public function addService(string $serviceClass, string $serviceId)
26
    {
27 2
        $reflectionClass = new ReflectionClass($serviceClass);
28 2
        foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {
29 2
            if (! isset($this->classes[$interfaceName])) {
30 2
                $this->classes[$interfaceName] = [];
31
            }
32 2
            $this->classes[$interfaceName][] = $serviceId;
33
        }
34
        do {
35 2
            if (! isset($this->classes[$reflectionClass->getName()])) {
36 2
                $this->classes[$reflectionClass->getName()] = [];
37
            }
38 2
            $this->classes[$reflectionClass->getName()][] = $serviceId;
39 2
        } while ($reflectionClass = $reflectionClass->getParentClass());
40 2
    }
41
42 2
    public function getMap() : array
43
    {
44 2
        return $this->classes;
45
    }
46
}
47