PhpInterface::addExtends()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Murtukov\PHPCodeGenerator;
6
7
use function join;
8
9
class PhpInterface extends OOPStructure
10
{
11
    protected array $extends = [];
12
    protected ?Comment $docBlock = null;
13
14 4
    public function generate(): string
15
    {
16
        // Extends
17 4
        $extends = '';
18 4
        if (!empty($this->extends)) {
19 3
            $extends = ' extends '.join(', ', $this->extends);
20
        }
21
22
        return <<<CODE
23 4
        {$this->buildDocBlock()}interface $this->name{$extends}
24
        {
25 4
        {$this->generateContent()}
26
        }
27
        CODE;
28
    }
29
30 1
    public function createSignature(string $name, string $returnType = ''): Signature
31
    {
32 1
        $signature = new Signature($name, Modifier::PUBLIC, $returnType);
33 1
        $this->append($signature);
34
35 1
        return $signature;
36
    }
37
38 1
    public function addSignature(string $name, string $returnType = ''): self
39
    {
40 1
        return $this->append(new Signature($name, Modifier::PUBLIC, $returnType));
41
    }
42
43 1
    public function addSignatureFromMethod(Method $method)
44
    {
45 1
        return $this->append($method->signature);
46
    }
47
48
    /**
49
     * @param mixed $value
50
     */
51 1
    public function addConst(string $name, $value): self
52
    {
53 1
        return $this->append(Property::new($name, Modifier::PUBLIC, '', $value)->setConst());
54
    }
55
56 1
    public function addExtends(string ...$extends)
57
    {
58 1
        foreach ($extends as $extend) {
59 1
            $this->extends[] = $this->resolveQualifier($extend);
60
        }
61
62 1
        return $this;
63
    }
64
}
65