Completed
Push — master ( b7052b...e758c6 )
by Luis
05:32 queued 02:56
created

ClassDefinition::constructorParameters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
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
namespace PhUml\Code;
8
9
class ClassDefinition extends Definition
10
{
11
    /** @var Attribute[] */
12
    public $attributes;
13
14
    /** @var InterfaceDefinition[] */
15
    public $implements;
16
17 123
    public function __construct(
18
        string $name,
19
        array $attributes = [],
20
        array $functions = [],
21
        array $implements = [],
22
        $extends = null
23
    ) {
24 123
        parent::__construct($name, $functions, $extends);
25 123
        $this->attributes = $attributes;
26 123
        $this->implements = $implements;
27 123
    }
28
29
    public function hasConstructor(): bool
30
    {
31 27
        return \count(array_filter($this->functions, function (Method $function) {
32 21
            return $function->isConstructor();
33 27
        })) === 1;
34
    }
35
36
    /** @return Variable[] */
37 15
    public function constructorParameters(): array
38
    {
39 15
        if (!$this->hasConstructor()) {
40 3
            return [];
41
        }
42
43 12
        $constructors = array_filter($this->functions, function (Method $function) {
44 12
            return $function->isConstructor();
45 12
        });
46
47 12
        return reset($constructors)->params;
48
    }
49
50 30
    public function hasParent(): bool
51
    {
52 30
        return $this->extends !== null;
53
    }
54
}
55