PhpAnnotation   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 76
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0
wmc 14

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPhpDeclaration() 0 3 1
A getPhpContent() 0 13 3
A hasContent() 0 3 1
A setContent() 0 5 1
A getContent() 0 3 1
A getPhpName() 0 3 3
A setMaxLength() 0 5 1
A getChildrenTypes() 0 3 1
A getMaxLength() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PhpGenerator\Element;
6
7
class PhpAnnotation extends AbstractElement
8
{
9
    public const NO_NAME = '__NO_NAME__';
10
11
    public const MAX_LENGTH = 80;
12
13
    protected string $content;
14
15
    protected int $maxLength;
16
17 66
    public function __construct(string $name, string $content, int $maxLength = self::MAX_LENGTH)
18
    {
19 66
        parent::__construct($name);
20
        $this
21 66
            ->setContent($content)
22 66
            ->setMaxLength($maxLength)
23
        ;
24 66
    }
25
26 66
    public function setContent(string $content): self
27
    {
28 66
        $this->content = trim($content);
29
30 66
        return $this;
31
    }
32
33 50
    public function getContent(): string
34
    {
35 50
        return $this->content;
36
    }
37
38 2
    public function hasContent(): bool
39
    {
40 2
        return !empty($this->content);
41
    }
42
43 50
    public function getPhpName(): string
44
    {
45 50
        return (!empty($this->name) && $this->getName() !== static::NO_NAME) ? sprintf(' @%s', parent::getPhpName()) : '';
46
    }
47
48 50
    public function getPhpDeclaration(): string
49
    {
50 50
        return sprintf(' *%s', implode(sprintf('%s *', parent::BREAK_LINE_CHAR), $this->getPhpContent()));
51
    }
52
53 2
    public function getChildrenTypes(): array
54
    {
55 2
        return [];
56
    }
57
58 66
    public function setMaxLength(int $maxlength): self
59
    {
60 66
        $this->maxLength = $maxlength;
61
62 66
        return $this;
63
    }
64
65 36
    public function getMaxLength(): int
66
    {
67 36
        return $this->maxLength;
68
    }
69
70 50
    protected function getPhpContent(): array
71
    {
72 50
        $fullContent = trim(sprintf('%s %s', $this->getPhpName(), $this->getContent()));
73 25
        $content = [
74 50
            $fullContent,
75
        ];
76 50
        if ('' === $this->getPhpName() && strlen($fullContent) > $this->getMaxLength()) {
77 10
            $content = explode(self::BREAK_LINE_CHAR, wordwrap($fullContent, $this->getMaxLength(), self::BREAK_LINE_CHAR, true));
78
        }
79
80 50
        return array_map(function ($element) {
81 50
            return sprintf(' %s', $element);
82 50
        }, $content);
83
    }
84
}
85