Completed
Push — symfony-console-application ( 3187e2...c3ee2a )
by Luis
10:39
created

RelationsResolver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveParentClass() 0 6 3
A resolveForClass() 0 8 3
A resolveForInterface() 0 3 1
A resolve() 0 7 3
A resolveParentInterface() 0 6 3
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
namespace PhUml\Parser;
8
9
class RelationsResolver
10
{
11
    public function resolve(Definitions $definitions): void
12
    {
13
        foreach ($definitions->all() as $definition) {
14
            if ($definitions->isClass($definition)) {
15
                $this->resolveForClass($definitions, $definition);
16
            } else {
17
                $this->resolveForInterface($definitions, $definition);
18
            }
19
        }
20
    }
21
22
    private function resolveForClass(Definitions $definitions, array $definition): void
23
    {
24
        foreach ($definitions->interfaces($definition) as $interface) {
25
            if (!$definitions->has($interface)) {
26
                $definitions->addExternalInterface($interface);
27
            }
28
        }
29
        $this->resolveParentClass($definitions, $definition);
30
    }
31
32
    private function resolveForInterface(Definitions $definitions, array $definition): void
33
    {
34
        $this->resolveParentInterface($definitions, $definition);
35
    }
36
37
    private function resolveParentClass(Definitions $definitions, array $definition): void
38
    {
39
        if ($definitions->hasParent($definition)) {
40
            $parent = $definitions->parent($definition);
41
            if (!$definitions->has($parent)) {
42
                $definitions->addExternalClass($parent);
43
            }
44
        }
45
    }
46
47
    private function resolveParentInterface(Definitions $definitions, array $definition): void
48
    {
49
        if ($definitions->hasParent($definition)) {
50
            $parent = $definitions->parent($definition);
51
            if (!$definitions->has($parent)) {
52
                $definitions->addExternalInterface($parent);
53
            }
54
        }
55
    }
56
}
57