Trait_   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addStmt() 0 13 3
A getNode() 0 5 1
1
<?php
2
3
namespace PhpParser\Builder;
4
5
use PhpParser;
6
use PhpParser\Node\Name;
7
use PhpParser\Node\Stmt;
8
9
class Trait_ extends Declaration
10
{
11
    protected $name;
12
    protected $properties = array();
13
    protected $methods = array();
14
15
    /**
16
     * Creates an interface builder.
17
     *
18
     * @param string $name Name of the interface
19
     */
20
    public function __construct($name) {
21
        $this->name = $name;
22
    }
23
24
    /**
25
     * Adds a statement.
26
     *
27
     * @param Stmt|PhpParser\Builder $stmt The statement to add
28
     *
29
     * @return $this The builder instance (for fluid interface)
30
     */
31
    public function addStmt($stmt) {
32
        $stmt = $this->normalizeNode($stmt);
33
34
        if ($stmt instanceof Stmt\Property) {
35
            $this->properties[] = $stmt;
36
        } else if ($stmt instanceof Stmt\ClassMethod) {
37
            $this->methods[] = $stmt;
38
        } else {
39
            throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
40
        }
41
42
        return $this;
43
    }
44
45
    /**
46
     * Returns the built trait node.
47
     *
48
     * @return Stmt\Trait_ The built interface node
49
     */
50
    public function getNode() {
51
        return new Stmt\Trait_(
52
            $this->name, array_merge($this->properties, $this->methods), $this->attributes
53
        );
54
    }
55
}
56