Passed
Push — parser-refactoring ( e758c6 )
by Luis
04:05
created

Structure::addInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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