Completed
Push — master ( 993468...5fd9a9 )
by Markus
12s queued 10s
created

ClassDefinitionMapLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 18 3
A __construct() 0 8 1
1
<?php
2
3
namespace Jellyfish\Transfer\Definition;
4
5
use SplFileInfo;
6
7
class ClassDefinitionMapLoader implements ClassDefinitionMapLoaderInterface
8
{
9
    /**
10
     * @var \Jellyfish\Transfer\Definition\DefinitionFinderInterface
11
     */
12
    protected $definitionFinder;
13
14
    /**
15
     * @var \Jellyfish\Transfer\Definition\ClassDefinitionMapMapperInterface
16
     */
17
    protected $classDefinitionMapMapper;
18
19
    /**
20
     * @var \Jellyfish\Transfer\Definition\ClassDefinitionMapMergerInterface
21
     */
22
    protected $classDefinitionMapMerger;
23
24
    /**
25
     * @param \Jellyfish\Transfer\Definition\DefinitionFinderInterface $definitionFinder
26
     * @param \Jellyfish\Transfer\Definition\ClassDefinitionMapMapperInterface $classDefinitionMapMapper
27
     * @param \Jellyfish\Transfer\Definition\ClassDefinitionMapMergerInterface $classDefinitionMapMerger
28
     */
29
    public function __construct(
30
        DefinitionFinderInterface $definitionFinder,
31
        ClassDefinitionMapMapperInterface $classDefinitionMapMapper,
32
        ClassDefinitionMapMergerInterface $classDefinitionMapMerger
33
    ) {
34
        $this->definitionFinder = $definitionFinder;
35
        $this->classDefinitionMapMapper = $classDefinitionMapMapper;
36
        $this->classDefinitionMapMerger = $classDefinitionMapMerger;
37
    }
38
39
    /**
40
     * @return \Jellyfish\Transfer\Definition\ClassDefinition[]
41
     */
42
    public function load(): array
43
    {
44
        $classDefinitionMap = [];
45
46
        foreach ($this->definitionFinder->find() as $definitionFile) {
47
            if (!($definitionFile instanceof SplFileInfo)) {
48
                continue;
49
            }
50
51
            $definitionFileContent = \file_get_contents($definitionFile->getRealPath());
52
53
            $currentClassDefinitionMap = $this->classDefinitionMapMapper->from($definitionFileContent);
54
55
            $classDefinitionMap = $this->classDefinitionMapMerger
56
                ->merge($classDefinitionMap, $currentClassDefinitionMap);
57
        }
58
59
        return $classDefinitionMap;
60
    }
61
}
62