Security update for Core, with self-updated composer
[yaffs-website] / vendor / consolidation / annotated-command / src / Parser / Internal / TagFactory.php
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;
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 }