Total Complexity | 5 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class ClassDefinition implements HasNodeIdentifier |
||
14 | { |
||
15 | use ObjectHashIdentifier; |
||
16 | |||
17 | /** @var string */ |
||
18 | public $name; |
||
19 | |||
20 | /** @var Attribute[] */ |
||
21 | public $attributes; |
||
22 | |||
23 | /** @var Method[] */ |
||
24 | public $functions; |
||
25 | |||
26 | /** @var InterfaceDefinition[] */ |
||
27 | public $implements; |
||
28 | |||
29 | /** @var ClassDefinition */ |
||
30 | public $extends; |
||
31 | |||
32 | public function __construct( |
||
33 | string $name, |
||
34 | array $attributes = [], |
||
35 | array $functions = [], |
||
36 | array $implements = [], |
||
37 | $extends = null |
||
38 | ) { |
||
39 | $this->name = $name; |
||
40 | $this->attributes = $attributes; |
||
41 | $this->functions = $functions; |
||
42 | $this->implements = $implements; |
||
43 | $this->extends = $extends; |
||
44 | } |
||
45 | |||
46 | public function hasConstructor(): bool |
||
47 | { |
||
48 | return \count(array_filter($this->functions, function (Method $function) { |
||
49 | return $function->isConstructor(); |
||
50 | })) === 1; |
||
51 | } |
||
52 | |||
53 | /** @return Variable[] */ |
||
54 | public function constructorParameters(): array |
||
55 | { |
||
56 | if (!$this->hasConstructor()) { |
||
57 | return []; |
||
58 | } |
||
59 | |||
60 | $constructors = array_filter($this->functions, function (Method $function) { |
||
61 | return $function->isConstructor(); |
||
62 | }); |
||
63 | |||
64 | return reset($constructors)->params; |
||
65 | } |
||
66 | |||
67 | public function hasParent(): bool |
||
70 | } |
||
71 | } |
||
72 |