Security update for Core, with self-updated composer
[yaffs-website] / vendor / consolidation / annotated-command / src / Parser / Internal / TagFactory.php
diff --git a/vendor/consolidation/annotated-command/src/Parser/Internal/TagFactory.php b/vendor/consolidation/annotated-command/src/Parser/Internal/TagFactory.php
new file mode 100644 (file)
index 0000000..4c48679
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+namespace Consolidation\AnnotatedCommand\Parser\Internal;
+
+/**
+ * Hold some state. Collect tags.
+ */
+class TagFactory
+{
+    /** @var DocblockTag|null Current tag */
+    protected $current;
+
+    /** @var DocblockTag[] All tag */
+    protected $tags;
+
+    /**
+     * DocblockTag constructor
+     */
+    public function __construct()
+    {
+        $this->current = null;
+        $this->tags = [];
+    }
+
+    public function parseLine($line)
+    {
+        if (DocblockTag::isTag($line)) {
+            return $this->createTag($line);
+        }
+        if (empty($line)) {
+            return $this->storeCurrentTag();
+        }
+        return $this->accumulateContent($line);
+    }
+
+    public function getTags()
+    {
+        $this->storeCurrentTag();
+        return $this->tags;
+    }
+
+    protected function createTag($line)
+    {
+        DocblockTag::splitTagAndContent($line, $matches);
+        $this->storeCurrentTag();
+        $this->current = new DocblockTag($matches['tag'], $matches['description']);
+        return true;
+    }
+
+    protected function storeCurrentTag()
+    {
+        if (!$this->current) {
+            return false;
+        }
+        $this->tags[] = $this->current;
+        $this->current = false;
+        return true;
+    }
+
+    protected function accumulateContent($line)
+    {
+        if (!$this->current) {
+            return false;
+        }
+        $this->current->appendContent($line);
+        return true;
+    }
+}