Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

Structure::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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\Code;
8
9
/**
10
 * Collection of all the classes and interfaces definitions
11
 */
12
class Structure
13
{
14
    /** @var ClassDefinition[] */
15
    private $classes;
16
17
    /** @var InterfaceDefinition[] */
18
    private $interfaces;
19
20 117
    public function __construct()
21
    {
22 117
        $this->classes = [];
23 117
        $this->interfaces = [];
24 117
    }
25
26 75
    public function addClass(ClassDefinition $class): void
27
    {
28 75
        $this->classes[$class->name] = $class;
29 75
    }
30
31 33
    public function addInterface(InterfaceDefinition $interface): void
32
    {
33 33
        $this->interfaces[$interface->name] = $interface;
34 33
    }
35
36 69
    public function has(string $name): bool
37
    {
38 69
        return isset($this->interfaces[$name]) || isset($this->classes[$name]);
39
    }
40
41 72
    public function get(string $name): Definition
42
    {
43 72
        return $this->interfaces[$name] ?? $this->classes[$name];
44
    }
45
46
    /** @return Definition[] */
47 42
    public function definitions(): array
48
    {
49 42
        return array_merge($this->classes, $this->interfaces);
50
    }
51
}
52