Passed
Push — cleanup ( 1df3c6...d09870 )
by Luis
12:15
created

RawDefinition   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

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

13 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A attributes() 0 3 1
A methods() 0 3 1
A __construct() 0 3 1
A parent() 0 3 1
A externalInterface() 0 3 1
A isClass() 0 3 1
A interface() 0 6 1
A class() 0 8 1
A interfaces() 0 3 1
A externalClass() 0 3 1
A hasParent() 0 3 1
A isInterface() 0 3 1
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\Raw;
9
10
/**
11
 * A raw definition is a wrapper for an associative array of strings used to build `Definition`s
12
 *
13
 * @see \PhUml\Parser\Raw\Builders\ClassBuilder To check how a `RawDefinition` for a class is built
14
 * @see \PhUml\Parser\Raw\Builders\InterfaceBuilder To check how a `RawDefinition` for an interface is built
15
 */
16
class RawDefinition
17
{
18
    private static $classDefaults = [
19
        'attributes' => [],
20
        'methods' => [],
21
        'implements' => [],
22
        'extends' => null,
23
    ];
24
25
    private static $interfaceDefaults = [
26
        'methods' => [],
27
        'extends' => null,
28
    ];
29
30
    /** @var array */
31
    private $definition;
32
33
    private function __construct(array $definition)
34
    {
35
        $this->definition = $definition;
36
    }
37
38
    public static function class(array $definition): RawDefinition
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
39
    {
40
        return new RawDefinition([
41
            'class' => $definition['class'],
42
            'attributes' => $definition['attributes'] ?? self::$classDefaults['attributes'],
43
            'methods' => $definition['methods'] ?? self::$classDefaults['methods'],
44
            'implements' => $definition['implements'] ?? self::$classDefaults['implements'],
45
            'extends' => $definition['extends'] ?? self::$classDefaults['extends'],
46
        ]);
47
    }
48
49
    public static function interface(array $definition): RawDefinition
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
50
    {
51
        return new RawDefinition([
52
            'interface' => $definition['interface'],
53
            'methods' => $definition['methods'] ?? self::$interfaceDefaults['methods'],
54
            'extends' => $definition['extends'] ?? self::$interfaceDefaults['extends'],
55
        ]);
56
    }
57
58
    public static function externalClass(string $name): RawDefinition
59
    {
60
        return new RawDefinition(array_merge(['class' => $name], self::$classDefaults));
61
    }
62
63
    public static function externalInterface(string $name): RawDefinition
64
    {
65
        return new RawDefinition(array_merge(['interface' => $name], self::$interfaceDefaults));
66
    }
67
68
    public function name(): string
69
    {
70
        return $this->definition['class'] ?? $this->definition['interface'];
71
    }
72
73
    /** @return string[] */
74
    public function interfaces(): array
75
    {
76
        return $this->definition['implements'];
77
    }
78
79
    public function hasParent(): bool
80
    {
81
        return isset($this->definition['extends']);
82
    }
83
84
    public function parent(): ?string
85
    {
86
        return $this->definition['extends'] ?? null;
87
    }
88
89
    public function isClass(): bool
90
    {
91
        return isset($this->definition['class']);
92
    }
93
94
    public function isInterface(): bool
95
    {
96
        return isset($this->definition['interface']);
97
    }
98
99
    public function attributes(): array
100
    {
101
        return $this->definition['attributes'];
102
    }
103
104
    public function methods(): array
105
    {
106
        return $this->definition['methods'];
107
    }
108
}
109