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

RelationsResolver::resolveForClass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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