Completed
Push — master ( 03b872...678a23 )
by Jaap
02:59
created

DescriptionDescriptor::isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Descriptor\DocBlock;
6
7
use phpDocumentor\Descriptor\TagDescriptor;
8
use phpDocumentor\Reflection\DocBlock\Description;
9
use function trim;
10
use function vsprintf;
11
12
final class DescriptionDescriptor
13
{
14
    /** @var Description */
15
    private $description;
16
17
    /** @var array<int, TagDescriptor|null> */
18
    private $inlineTags;
19
20
    /**
21
     * @param array<int, TagDescriptor|null> $inlineTags
22
     */
23 9
    public function __construct(?Description $description, array $inlineTags)
24
    {
25 9
        $this->description = $description ?? new Description('');
26 9
        $this->inlineTags = $inlineTags;
27 9
    }
28
29 3
    public function getBodyTemplate() : string
30
    {
31 3
        return $this->description->getBodyTemplate();
32
    }
33
34 2
    public function replaceTag(int $position, ?TagDescriptor $tagDescriptor) : void
35
    {
36 2
        $this->inlineTags[$position] = $tagDescriptor;
37 2
    }
38
39
    /**
40
     * Returns the tags for this description
41
     *
42
     * @return array<int, TagDescriptor|null>
0 ignored issues
show
Documentation introduced by
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
43
     */
44 2
    public function getTags() : array
45
    {
46 2
        return $this->inlineTags;
47
    }
48
49
    public function isEmpty() : bool
50
    {
51
        return $this->description->getBodyTemplate() === '';
52
    }
53
54
    /**
55
     * Renders docblock as string.
56
     *
57
     * This method is here for legacy purpose. The new v3 template has improved the way we render descriptons
58
     * which requires more advanced handling of descriptions and just not some string jugling.
59
     *
60
     * @deprecated will be removed in v4
61
     *
62
     * @return string
63
     */
64 3
    public function __toString()
65
    {
66 3
        $tags = [];
67 3
        foreach ($this->getTags() as $tag) {
68 3
            if ($tag === null) {
69 1
                $tags[] = null;
70 1
                continue;
71
            }
72
73 2
            $tags[] = '{' . trim('@' . $tag->getName() . ' ' . $tag) . '}';
74
        }
75
76 3
        return vsprintf($this->getBodyTemplate(), $tags);
77
    }
78
}
79