Test Failed
Push — graphviz-refactoring ( 3f1b14 )
by Luis
02:18
created

plPhpClass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
dl 0
loc 58
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasConstructor() 0 5 1
A hasParent() 0 3 1
A constructorParameters() 0 11 2
A __construct() 0 12 1
1
<?php
2
3
class plPhpClass implements plHasNodeIdentifier
4
{
5
    use plObjectHashIdentifier;
6
7
    /** @var string */
8
    public $name;
9
10
    /** @var plPhpAttribute[] */
11
    public $attributes;
12
13
    /** @var plPhpFunction[] */
14
    public $functions;
15
16
    /** @var plPhpInterface[] */
17
    public $implements;
18
19
    /** @var plPhpClass */
20
    public $extends;
21
22
    public function __construct(
23
        string $name,
24
        array $attributes = [],
25
        array $functions = [],
26
        array $implements = [],
27
        $extends = null
28
    ) {
29
        $this->name = $name;
30
        $this->attributes = $attributes;
31
        $this->functions = $functions;
32
        $this->implements = $implements;
33
        $this->extends = $extends;
34
    }
35
36
37
    public function hasConstructor(): bool
38
    {
39
        return count(array_filter($this->functions, function (plPhpFunction $function) {
40
            return $function->isConstructor();
41
        })) === 1;
42
    }
43
44
    /** @return plPhpVariable[] */
45
    public function constructorParameters(): array
46
    {
47
        if (!$this->hasConstructor()) {
48
            return [];
49
        }
50
51
        $constructors = array_filter($this->functions, function (plPhpFunction $function) {
52
            return $function->isConstructor();
53
        });
54
55
        return reset($constructors)->params;
56
    }
57
58
    public function hasParent(): bool
59
    {
60
        return $this->extends !== null;
61
    }
62
}
63