Passed
Push — 1.6 ( c2a002 )
by Luis
05:37
created

Definition::constants()   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 0
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
8
namespace PhUml\Code;
9
10
use PhUml\Code\Methods\Method;
11
use PhUml\Code\Modifiers\Visibility;
12
use PhUml\Graphviz\HasNodeIdentifier;
13
use PhUml\Graphviz\ObjectHashIdentifier;
14
15
/**
16
 * Base class for interfaces, classes and traits
17
 */
18
abstract class Definition implements Named, HasNodeIdentifier
19
{
20
    use WithName, ObjectHashIdentifier;
21
22
    /** @var Method[] */
23
    protected $methods;
24
25
    /** @param Method[] $methods */
26 354
    public function __construct(Name $name, array $methods = [])
27
    {
28 354
        $this->name = $name;
29 354
        $this->methods = $methods;
30 354
    }
31
32
    /**
33
     * This method is used by the Summary class to count how many methods by visibility in a
34
     * Structure are
35
     *
36
     * @see Summary::methodsSummary() for more details
37
     */
38
    public function countMethodsByVisibility(Visibility $modifier): int
39
    {
40 12
        return \count(array_filter($this->methods, function (Method $method) use ($modifier) {
41 12
            return $method->hasVisibility($modifier);
42 12
        }));
43
    }
44
45
    /**
46
     * This method is used when the commands are called with the option `hide-empty-blocks`
47
     *
48
     * For interfaces it counts the number of constants.
49
     * For classes it counts both constants and attributes.
50
     *
51
     * @see ClassDefinition::hasAttributes() for more details
52
     * @see InterfaceDefinition::hasAttributes() for more details
53
     */
54
    abstract public function hasAttributes(): bool;
55
56
    /** @return Method[] */
57 126
    public function methods(): array
58
    {
59 126
        return $this->methods;
60
    }
61
}
62