TagFactory   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 61
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parseLine() 0 10 3
A getTags() 0 5 1
A createTag() 0 7 1
A storeCurrentTag() 0 9 2
A accumulateContent() 0 8 2
1
<?php
2
namespace Consolidation\AnnotatedCommand\Parser\Internal;
3
4
/**
5
 * Hold some state. Collect tags.
6
 */
7
class TagFactory
8
{
9
    /** @var DocblockTag|null Current tag */
10
    protected $current;
11
12
    /** @var DocblockTag[] All tag */
13
    protected $tags;
14
15
    /**
16
     * DocblockTag constructor
17
     */
18
    public function __construct()
19
    {
20
        $this->current = null;
21
        $this->tags = [];
22
    }
23
24
    public function parseLine($line)
25
    {
26
        if (DocblockTag::isTag($line)) {
27
            return $this->createTag($line);
28
        }
29
        if (empty($line)) {
30
            return $this->storeCurrentTag();
31
        }
32
        return $this->accumulateContent($line);
33
    }
34
35
    public function getTags()
36
    {
37
        $this->storeCurrentTag();
38
        return $this->tags;
39
    }
40
41
    protected function createTag($line)
42
    {
43
        DocblockTag::splitTagAndContent($line, $matches);
44
        $this->storeCurrentTag();
45
        $this->current = new DocblockTag($matches['tag'], $matches['description']);
46
        return true;
47
    }
48
49
    protected function storeCurrentTag()
50
    {
51
        if (!$this->current) {
52
            return false;
53
        }
54
        $this->tags[] = $this->current;
55
        $this->current = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<Consolidation\Ann...ernal\DocblockTag>|null of property $current.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        return true;
57
    }
58
59
    protected function accumulateContent($line)
60
    {
61
        if (!$this->current) {
62
            return false;
63
        }
64
        $this->current->appendContent($line);
65
        return true;
66
    }
67
}
68