ArrowFunction   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 52
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A new() 0 3 1
A getExpression() 0 3 1
A generate() 0 5 1
A manageExprDependency() 0 9 2
A setExpression() 0 5 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Murtukov\PHPCodeGenerator;
6
7
class ArrowFunction extends AbstractFunction
8
{
9
    /** @var GeneratorInterface|string */
10
    private $expression;
11
12 2
    public function __construct($expression = null, string $returnType = '')
13
    {
14 2
        $this->signature = new Signature('', Modifier::NONE, $returnType, 'fn');
15 2
        $this->expression = $this->manageExprDependency($expression);
16
17 2
        $this->dependencyAwareChildren[] = $this->signature;
18 2
    }
19
20 2
    public static function new($expression = null, string $returnType = '')
21
    {
22 2
        return new self($expression, $returnType);
23
    }
24
25 3
    public function generate(): string
26
    {
27 3
        $expression = Utils::stringify($this->expression);
28
29 3
        return "$this->signature => $expression";
30
    }
31
32
    /**
33
     * @return GeneratorInterface|string
34
     */
35 1
    public function getExpression()
36
    {
37 1
        return $this->expression;
38
    }
39
40
    /**
41
     * @param mixed $expression
42
     */
43 1
    public function setExpression($expression): self
44
    {
45 1
        $this->expression = $this->manageExprDependency($expression);
46
47 1
        return $this;
48
    }
49
50 2
    protected function manageExprDependency($value)
51
    {
52 2
        if ($value instanceof DependencyAwareGenerator) {
53 1
            $this->dependencyAwareChildren['expr'] = $value;
54
        } else {
55 2
            unset($this->dependencyAwareChildren['expr']);
56
        }
57
58 2
        return $value;
59
    }
60
}
61