Setter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 28
ccs 12
cts 12
cp 1
crap 2
rs 9.7
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 5
    public function __construct(PhpClassProperty $property, $fluent = true)
18
    {
19 5
        $name = $property->getNamedVar()->getName();
20 5
        parent::__construct(
21 5
            'set' . ucfirst($name),
22 5
            PhpFlags::VIS_PUBLIC
23
        );
24
25 5
        $this->skipCodeCoverage = true;
26
        $this->outputArgumentsWithDefaults = false;
27 5
28
        $this->addArgument($property->getNamedVar());
29
30 5
        $body = <<<PHP
31
\$this->{$name} = \${$name};
32
33
PHP;
34 5
35 5
        if ($fluent) {
36
            $this->setResult(PhpDocType::thisType());
37 5
            $body .= <<<PHP
38
return \$this;
39
40
PHP;
41
42
        }
43 5
44
        $this->setBody($body);
45 5
46
    }
47
}