Passed
Push — 1.6 ( c2a002 )
by Luis
05:37
created

TraitDefinitionBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A build() 0 7 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
8
namespace PhUml\Parser\Code\Builders;
9
10
use PhpParser\Node\Stmt\Trait_;
11
use PhUml\Code\Name;
12
use PhUml\Code\TraitDefinition;
13
use PhUml\Parser\Code\Builders\Names\TraitNamesBuilder;
14
15
/**
16
 * It builds a `TraitDefinition`
17
 *
18
 * @see MembersBuilder
19
 * @see TraitNamesBuilder
20
 */
21
class TraitDefinitionBuilder
22
{
23
    use TraitNamesBuilder;
24
25
    /** @var MembersBuilder */
26
    protected $membersBuilder;
27
28 141
    public function __construct(MembersBuilder $membersBuilder = null)
29
    {
30 141
        $this->membersBuilder = $membersBuilder ?? new MembersBuilder();
31 141
    }
32
33 48
    public function build(Trait_ $trait): TraitDefinition
34
    {
35 48
        return new TraitDefinition(
36 48
            Name::from($trait->name),
0 ignored issues
show
Bug introduced by
It seems like $trait->name can also be of type null; however, parameter $text of PhUml\Code\Name::from() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            Name::from(/** @scrutinizer ignore-type */ $trait->name),
Loading history...
37 48
            $this->membersBuilder->methods($trait->getMethods()),
38 48
            $this->membersBuilder->attributes($trait->stmts),
39 48
            $this->buildTraits($trait->stmts)
40
        );
41
    }
42
}
43