Passed
Push — develop ( 6b3bb3...b964e0 )
by Mikaël
01:53 queued 11s
created

PhpFile::getElements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PhpGenerator\Component;
6
7
use WsdlToPhp\PhpGenerator\Component\PhpClass as PhpClassComponent;
8
use WsdlToPhp\PhpGenerator\Component\PhpInterface as PhpInterfaceComponent;
9
use WsdlToPhp\PhpGenerator\Element\PhpDeclare;
10
use WsdlToPhp\PhpGenerator\Element\PhpFile as PhpFileElement;
11
use WsdlToPhp\PhpGenerator\Element\PhpFunction as PhpFunctionElement;
12
use WsdlToPhp\PhpGenerator\Element\PhpVariable as PhpVariableElement;
13
14
class PhpFile extends AbstractComponent
15
{
16 12
    public function __construct(string $name)
17
    {
18 12
        $this->setMainElement(new PhpFileElement($name));
19 12
    }
20
21 4
    public function addClassComponent(PhpClassComponent $class): self
22
    {
23 4
        $this->mainElement->addChild($class->toString());
24
25 4
        return $this;
26
    }
27
28 2
    public function addInterfaceComponent(PhpInterfaceComponent $interface): self
29
    {
30 2
        $this->mainElement->addChild($interface->toString());
31
32 2
        return $this;
33
    }
34
35 2
    public function addVariableElement(PhpVariableElement $variable): self
36
    {
37 2
        $this->mainElement->addChild($variable);
38
39 2
        return $this;
40
    }
41
42 2
    public function addVariable(string $name, $value = null): self
43
    {
44 2
        return $this->addVariableElement(new PhpVariableElement($name, $value));
45
    }
46
47 2
    public function addFunctionElement(PhpFunctionElement $function): self
48
    {
49 2
        $this->mainElement->addChild($function);
50
51 2
        return $this;
52
    }
53
54 2
    public function addFunction(string $name, array $parameters = []): self
55
    {
56 2
        return $this->addFunctionElement(new PhpFunctionElement($name, $parameters));
57
    }
58
59 6
    public function addUse(string $use, string $as = null, bool $last = false): self
60
    {
61 6
        $expression = empty($as) ? 'use %1$s;%3$s' : 'use %1$s as %2$s;%3$s';
62 6
        $this->mainElement->addChild(sprintf($expression, $use, $as, $last ? self::BREAK_LINE_CHAR : ''));
63
64 6
        return $this;
65
    }
66
67 6
    public function setDeclareElement(PhpDeclare $phpDeclare): self
68
    {
69 6
        $this->mainElement->addChild(sprintf('%s%s', self::BREAK_LINE_CHAR, $phpDeclare->toString()));
70
71 6
        return $this;
72
    }
73
74 2
    public function setDeclare(string $name, $value): self
75
    {
76 2
        return $this->setDeclareElement(new PhpDeclare($name, $value));
77
    }
78
79 6
    public function setNamespace(string $namespace): self
80
    {
81 6
        $this->mainElement->addChild(
82 6
            sprintf(
83 6
                '%snamespace %s;%s',
84 6
                self::BREAK_LINE_CHAR,
85
                $namespace,
86 6
                self::BREAK_LINE_CHAR
87
            )
88
        );
89
90 6
        return $this;
91
    }
92
}
93