Completed
Pull Request — master (#1)
by Viacheslav
02:50
created

Setter::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 2
dl 0
loc 27
ccs 12
cts 12
cp 1
crap 2
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder\Property;
4
5
use Swaggest\PhpCodeBuilder\PhpClassProperty;
6
use Swaggest\PhpCodeBuilder\PhpDocType;
7
use Swaggest\PhpCodeBuilder\PhpFlags;
8
use Swaggest\PhpCodeBuilder\PhpFunction;
9
10
class Setter extends PhpFunction
11
{
12
    /**
13
     * Getter constructor.
14
     * @param PhpClassProperty $property
15
     * @param bool $fluent
16
     */
17 4
    public function __construct(PhpClassProperty $property, $fluent = true)
18
    {
19 4
        $name = $property->getNamedVar()->getName();
20 4
        parent::__construct(
21 4
            'set' . ucfirst($name),
22 4
            PhpFlags::VIS_PUBLIC
23
        );
24
25 4
        $this->skipCodeCoverage = true;
26
27 4
        $this->addArgument($property->getNamedVar());
28
29
        $body = <<<PHP
30 4
\$this->{$name} = \${$name};
31
32
PHP;
33
34 4
        if ($fluent) {
35 4
            $this->setResult(PhpDocType::thisType());
36
            $body .= <<<PHP
37 4
return \$this;
38
39
PHP;
40
41
        }
42
43 4
        $this->setBody($body);
44
45
    }
46
}