Passed
Push — 1.5 ( c7c5a4...fe8795 )
by Luis
06:06
created

resolveExternalConstructorParameters()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
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
8
namespace PhUml\Parser\Code;
9
10
use PhUml\Code\Attributes\Attribute;
11
use PhUml\Code\ClassDefinition;
12
use PhUml\Code\Codebase;
13
use PhUml\Code\Variables\Variable;
14
15
/**
16
 * It checks the attributes and the constructor parameters of a class looking for external definitions
17
 *
18
 * An external definition is either a class or interface from a third party library, or a built-in
19
 * class
20
 *
21
 * In this case a `ClassDefinition` is added by default.
22
 * Although we don't really know if it's an interface since we don't have access to the source code
23
 */
24
class ExternalAssociationsResolver extends ExternalDefinitionsResolver
25
{
26 27
    protected function resolveForClass(ClassDefinition $definition, Codebase $codebase): void
27
    {
28 27
        parent::resolveForClass($definition, $codebase);
29 27
        $this->resolveExternalAttributes($definition, $codebase);
30 27
        $this->resolveExternalConstructorParameters($definition, $codebase);
31 27
    }
32
33
    private function resolveExternalAttributes(ClassDefinition $definition, Codebase $codebase): void
34
    {
35 27
        array_map(function (Attribute $attribute) use ($codebase) {
36 15
            if ($attribute->isAReference() && !$codebase->has($attribute->typeName())) {
37 3
                $codebase->add($this->externalClass($attribute->typeName()));
38
            }
39 27
        }, $definition->attributes());
40 27
    }
41
42
    private function resolveExternalConstructorParameters(ClassDefinition $definition, Codebase $codebase): void
43
    {
44 27
        array_map(function (Variable $parameter) use ($codebase) {
45 15
            if ($parameter->isAReference() && !$codebase->has($parameter->typeName())) {
46 3
                $codebase->add($this->externalClass($parameter->typeName()));
47
            }
48 27
        }, $definition->constructorParameters());
49
    }
50
}
51