Completed
Push — symfony-console-application ( 3187e2...c3ee2a )
by Luis
10:39
created

ClassDefinition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasParent() 0 3 1
A constructorParameters() 0 11 2
A hasConstructor() 0 5 1
A __construct() 0 10 1
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
    public function __construct(
18
        string $name,
19
        array $attributes = [],
20
        array $functions = [],
21
        array $implements = [],
22
        $extends = null
23
    ) {
24
        parent::__construct($name, $functions, $extends);
25
        $this->attributes = $attributes;
26
        $this->implements = $implements;
27
    }
28
29
    public function hasConstructor(): bool
30
    {
31
        return \count(array_filter($this->functions, function (Method $function) {
32
            return $function->isConstructor();
33
        })) === 1;
34
    }
35
36
    /** @return Variable[] */
37
    public function constructorParameters(): array
38
    {
39
        if (!$this->hasConstructor()) {
40
            return [];
41
        }
42
43
        $constructors = array_filter($this->functions, function (Method $function) {
44
            return $function->isConstructor();
45
        });
46
47
        return reset($constructors)->params;
48
    }
49
50
    public function hasParent(): bool
51
    {
52
        return $this->extends !== null;
53
    }
54
}
55