|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Docblock package. |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @license MIT License |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gossi\docblock\tags; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Represents tags which are in the format |
|
14
|
|
|
* |
|
15
|
|
|
* `@tag [Version] [Description]` |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class AbstractVersionTag extends AbstractDescriptionTag { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* PCRE regular expression matching a version vector. |
|
21
|
|
|
* Assumes the "x" modifier. |
|
22
|
|
|
*/ |
|
23
|
|
|
const REGEX_VERSION = '(?: |
|
24
|
|
|
# Normal release vectors. |
|
25
|
|
|
\d\S* |
|
26
|
|
|
| |
|
27
|
|
|
# VCS version vectors. Per PHPCS, they are expected to |
|
28
|
|
|
# follow the form of the VCS name, followed by ":", followed |
|
29
|
|
|
# by the version vector itself. |
|
30
|
|
|
# By convention, popular VCSes like CVS, SVN and GIT use "$" |
|
31
|
|
|
# around the actual version vector. |
|
32
|
|
|
[^\s\:]+\:\s*\$[^\$]+\$ |
|
33
|
|
|
)'; |
|
34
|
|
|
|
|
35
|
|
|
protected string $version = ''; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @see https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/src/phpDocumentor/Reflection/DocBlock/Tag/VersionTag.php Original Method: setContent() |
|
39
|
|
|
* @see \gossi\docblock\tags\AbstractTag::parse() |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $content |
|
42
|
|
|
*/ |
|
43
|
6 |
|
protected function parse(string $content): void { |
|
44
|
6 |
|
$matches = []; |
|
45
|
6 |
|
if (preg_match( |
|
46
|
6 |
|
'/^ |
|
47
|
|
|
# The version vector |
|
48
|
6 |
|
(' . self::REGEX_VERSION . ') |
|
49
|
|
|
\s* |
|
50
|
|
|
# The description |
|
51
|
|
|
(.+)? |
|
52
|
|
|
$/sux', |
|
53
|
|
|
$content, |
|
54
|
|
|
$matches)) { |
|
55
|
4 |
|
$this->version = $matches[1]; |
|
56
|
4 |
|
$this->setDescription($matches[2] ?? ''); |
|
57
|
|
|
} |
|
58
|
6 |
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
public function toString(): string { |
|
61
|
4 |
|
return trim(sprintf('@%s %s %s', $this->tagName, $this->version, $this->description)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the version |
|
66
|
|
|
* |
|
67
|
|
|
* @return string the version |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function getVersion(): string { |
|
70
|
1 |
|
return $this->version; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Sets the version |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $version the new version |
|
77
|
|
|
* |
|
78
|
|
|
* @return $this |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function setVersion(string $version): self { |
|
81
|
1 |
|
$this->version = $version; |
|
82
|
|
|
|
|
83
|
1 |
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|