Passed
Push — 1.3 ( 2ce63d )
by Luis
11:41
created

Definition::constants()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
8
namespace PhUml\Code;
9
10
use PhUml\Graphviz\HasNodeIdentifier;
11
use PhUml\Graphviz\ObjectHashIdentifier;
12
13
/**
14
 * Base class for interfaces and classes
15
 *
16
 * It does not support traits yet
17
 */
18
abstract class Definition implements HasNodeIdentifier
19
{
20
    use ObjectHashIdentifier;
21
22
    /** @var string */
23
    protected $name;
24
25
    /** @var Constant[] */
26
    protected $constants;
27
28
    /** @var Method[] */
29
    protected $methods;
30
31
    /** @var Definition */
32
    protected $extends;
33
34
    /**
35
     * @param Constant[] $constants
36
     * @param Method[] $methods
37
     */
38
    public function __construct(
39
        string $name,
40
        array $constants = [],
41
        array $methods = [],
42
        Definition $extends = null
43
    ) {
44
        $this->name = $name;
45
        $this->constants = $constants;
46
        $this->methods = $methods;
47
        $this->extends = $extends;
48
    }
49
50
    public function countMethodsByVisibility(Visibility $modifier): int
51
    {
52
        return \count(array_filter($this->methods, function (Method $method) use ($modifier) {
53
            return $method->hasVisibility($modifier);
54
        }));
55
    }
56
57
    public function name(): string
58
    {
59
        return $this->name;
60
    }
61
62
    abstract public function hasAttributes(): bool;
63
64
    /** @return Constant[] */
65
    public function constants(): array
66
    {
67
        return $this->constants;
68
    }
69
70
    /** @return Method[] */
71
    public function methods(): array
72
    {
73
        return $this->methods;
74
    }
75
76
    public function extends(): Definition
77
    {
78
        return $this->extends;
79
    }
80
}
81