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

TraitDefinitionBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
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
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