@@ -21,33 +21,33 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class BaseTag implements DocBlock\Tag |
23 | 23 | { |
24 | - /** @var string Name of the tag */ |
|
25 | - protected $name = ''; |
|
26 | - |
|
27 | - /** @var Description|null Description of the tag. */ |
|
28 | - protected $description; |
|
29 | - |
|
30 | - /** |
|
31 | - * Gets the name of this tag. |
|
32 | - * |
|
33 | - * @return string The name of this tag. |
|
34 | - */ |
|
35 | - public function getName(): string |
|
36 | - { |
|
37 | - return $this->name; |
|
38 | - } |
|
39 | - |
|
40 | - public function getDescription(): ?Description |
|
41 | - { |
|
42 | - return $this->description; |
|
43 | - } |
|
44 | - |
|
45 | - public function render(?Formatter $formatter = null): string |
|
46 | - { |
|
47 | - if ($formatter === null) { |
|
48 | - $formatter = new Formatter\PassthroughFormatter(); |
|
49 | - } |
|
50 | - |
|
51 | - return $formatter->format($this); |
|
52 | - } |
|
24 | + /** @var string Name of the tag */ |
|
25 | + protected $name = ''; |
|
26 | + |
|
27 | + /** @var Description|null Description of the tag. */ |
|
28 | + protected $description; |
|
29 | + |
|
30 | + /** |
|
31 | + * Gets the name of this tag. |
|
32 | + * |
|
33 | + * @return string The name of this tag. |
|
34 | + */ |
|
35 | + public function getName(): string |
|
36 | + { |
|
37 | + return $this->name; |
|
38 | + } |
|
39 | + |
|
40 | + public function getDescription(): ?Description |
|
41 | + { |
|
42 | + return $this->description; |
|
43 | + } |
|
44 | + |
|
45 | + public function render(?Formatter $formatter = null): string |
|
46 | + { |
|
47 | + if ($formatter === null) { |
|
48 | + $formatter = new Formatter\PassthroughFormatter(); |
|
49 | + } |
|
50 | + |
|
51 | + return $formatter->format($this); |
|
52 | + } |
|
53 | 53 | } |
@@ -20,11 +20,11 @@ |
||
20 | 20 | |
21 | 21 | class PassthroughFormatter implements Formatter |
22 | 22 | { |
23 | - /** |
|
24 | - * Formats the given tag to return a simple plain text version. |
|
25 | - */ |
|
26 | - public function format(Tag $tag): string |
|
27 | - { |
|
28 | - return trim('@' . $tag->getName() . ' ' . $tag); |
|
29 | - } |
|
23 | + /** |
|
24 | + * Formats the given tag to return a simple plain text version. |
|
25 | + */ |
|
26 | + public function format(Tag $tag): string |
|
27 | + { |
|
28 | + return trim('@' . $tag->getName() . ' ' . $tag); |
|
29 | + } |
|
30 | 30 | } |
@@ -25,6 +25,6 @@ |
||
25 | 25 | */ |
26 | 26 | public function format(Tag $tag): string |
27 | 27 | { |
28 | - return trim('@' . $tag->getName() . ' ' . $tag); |
|
28 | + return trim('@'.$tag->getName().' '.$tag); |
|
29 | 29 | } |
30 | 30 | } |
@@ -22,29 +22,29 @@ |
||
22 | 22 | |
23 | 23 | class AlignFormatter implements Formatter |
24 | 24 | { |
25 | - /** @var int The maximum tag name length. */ |
|
26 | - protected $maxLen = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param Tag[] $tags All tags that should later be aligned with the formatter. |
|
30 | - */ |
|
31 | - public function __construct(array $tags) |
|
32 | - { |
|
33 | - foreach ($tags as $tag) { |
|
34 | - $this->maxLen = max($this->maxLen, strlen($tag->getName())); |
|
35 | - } |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Formats the given tag to return a simple plain text version. |
|
40 | - */ |
|
41 | - public function format(Tag $tag): string |
|
42 | - { |
|
43 | - return '@' . $tag->getName() . |
|
44 | - str_repeat( |
|
45 | - ' ', |
|
46 | - $this->maxLen - strlen($tag->getName()) + 1 |
|
47 | - ) . |
|
48 | - $tag; |
|
49 | - } |
|
25 | + /** @var int The maximum tag name length. */ |
|
26 | + protected $maxLen = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param Tag[] $tags All tags that should later be aligned with the formatter. |
|
30 | + */ |
|
31 | + public function __construct(array $tags) |
|
32 | + { |
|
33 | + foreach ($tags as $tag) { |
|
34 | + $this->maxLen = max($this->maxLen, strlen($tag->getName())); |
|
35 | + } |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Formats the given tag to return a simple plain text version. |
|
40 | + */ |
|
41 | + public function format(Tag $tag): string |
|
42 | + { |
|
43 | + return '@' . $tag->getName() . |
|
44 | + str_repeat( |
|
45 | + ' ', |
|
46 | + $this->maxLen - strlen($tag->getName()) + 1 |
|
47 | + ) . |
|
48 | + $tag; |
|
49 | + } |
|
50 | 50 | } |
@@ -40,11 +40,11 @@ |
||
40 | 40 | */ |
41 | 41 | public function format(Tag $tag): string |
42 | 42 | { |
43 | - return '@' . $tag->getName() . |
|
43 | + return '@'.$tag->getName(). |
|
44 | 44 | str_repeat( |
45 | 45 | ' ', |
46 | 46 | $this->maxLen - strlen($tag->getName()) + 1 |
47 | - ) . |
|
47 | + ). |
|
48 | 48 | $tag; |
49 | 49 | } |
50 | 50 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | final class Since extends BaseTag implements Factory\StaticMethod |
27 | 27 | { |
28 | - /** @var string */ |
|
29 | - protected $name = 'since'; |
|
30 | - |
|
31 | - /** |
|
32 | - * PCRE regular expression matching a version vector. |
|
33 | - * Assumes the "x" modifier. |
|
34 | - */ |
|
35 | - public const REGEX_VECTOR = '(?: |
|
28 | + /** @var string */ |
|
29 | + protected $name = 'since'; |
|
30 | + |
|
31 | + /** |
|
32 | + * PCRE regular expression matching a version vector. |
|
33 | + * Assumes the "x" modifier. |
|
34 | + */ |
|
35 | + public const REGEX_VECTOR = '(?: |
|
36 | 36 | # Normal release vectors. |
37 | 37 | \d\S* |
38 | 38 | | |
@@ -44,60 +44,60 @@ discard block |
||
44 | 44 | [^\s\:]+\:\s*\$[^\$]+\$ |
45 | 45 | )'; |
46 | 46 | |
47 | - /** @var string|null The version vector. */ |
|
48 | - private $version; |
|
49 | - |
|
50 | - public function __construct(?string $version = null, ?Description $description = null) |
|
51 | - { |
|
52 | - Assert::nullOrNotEmpty($version); |
|
53 | - |
|
54 | - $this->version = $version; |
|
55 | - $this->description = $description; |
|
56 | - } |
|
57 | - |
|
58 | - public static function create( |
|
59 | - ?string $body, |
|
60 | - ?DescriptionFactory $descriptionFactory = null, |
|
61 | - ?TypeContext $context = null |
|
62 | - ): ?self { |
|
63 | - if (empty($body)) { |
|
64 | - return new static(); |
|
65 | - } |
|
66 | - |
|
67 | - $matches = []; |
|
68 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - Assert::notNull($descriptionFactory); |
|
73 | - |
|
74 | - return new static( |
|
75 | - $matches[1], |
|
76 | - $descriptionFactory->create($matches[2] ?? '', $context) |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Gets the version section of the tag. |
|
82 | - */ |
|
83 | - public function getVersion(): ?string |
|
84 | - { |
|
85 | - return $this->version; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns a string representation for this tag. |
|
90 | - */ |
|
91 | - public function __toString(): string |
|
92 | - { |
|
93 | - if ($this->description) { |
|
94 | - $description = $this->description->render(); |
|
95 | - } else { |
|
96 | - $description = ''; |
|
97 | - } |
|
98 | - |
|
99 | - $version = (string) $this->version; |
|
100 | - |
|
101 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
102 | - } |
|
47 | + /** @var string|null The version vector. */ |
|
48 | + private $version; |
|
49 | + |
|
50 | + public function __construct(?string $version = null, ?Description $description = null) |
|
51 | + { |
|
52 | + Assert::nullOrNotEmpty($version); |
|
53 | + |
|
54 | + $this->version = $version; |
|
55 | + $this->description = $description; |
|
56 | + } |
|
57 | + |
|
58 | + public static function create( |
|
59 | + ?string $body, |
|
60 | + ?DescriptionFactory $descriptionFactory = null, |
|
61 | + ?TypeContext $context = null |
|
62 | + ): ?self { |
|
63 | + if (empty($body)) { |
|
64 | + return new static(); |
|
65 | + } |
|
66 | + |
|
67 | + $matches = []; |
|
68 | + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + Assert::notNull($descriptionFactory); |
|
73 | + |
|
74 | + return new static( |
|
75 | + $matches[1], |
|
76 | + $descriptionFactory->create($matches[2] ?? '', $context) |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Gets the version section of the tag. |
|
82 | + */ |
|
83 | + public function getVersion(): ?string |
|
84 | + { |
|
85 | + return $this->version; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns a string representation for this tag. |
|
90 | + */ |
|
91 | + public function __toString(): string |
|
92 | + { |
|
93 | + if ($this->description) { |
|
94 | + $description = $this->description->render(); |
|
95 | + } else { |
|
96 | + $description = ''; |
|
97 | + } |
|
98 | + |
|
99 | + $version = (string) $this->version; |
|
100 | + |
|
101 | + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
102 | + } |
|
103 | 103 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $matches = []; |
68 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
68 | + if ( ! preg_match('/^('.self::REGEX_VECTOR.')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | 69 | return null; |
70 | 70 | } |
71 | 71 | |
@@ -101,6 +101,6 @@ discard block |
||
101 | 101 | |
102 | 102 | $version = (string) $this->version; |
103 | 103 | |
104 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
104 | + return $version.($description !== '' ? ($version !== '' ? ' ' : '').$description : ''); |
|
105 | 105 | } |
106 | 106 | } |
@@ -18,8 +18,8 @@ |
||
18 | 18 | */ |
19 | 19 | interface StaticMethod |
20 | 20 | { |
21 | - /** |
|
22 | - * @return mixed |
|
23 | - */ |
|
24 | - public static function create(string $body); |
|
21 | + /** |
|
22 | + * @return mixed |
|
23 | + */ |
|
24 | + public static function create(string $body); |
|
25 | 25 | } |
@@ -34,141 +34,141 @@ |
||
34 | 34 | */ |
35 | 35 | final class Param extends TagWithType implements Factory\StaticMethod |
36 | 36 | { |
37 | - /** @var string|null */ |
|
38 | - private $variableName; |
|
39 | - |
|
40 | - /** @var bool determines whether this is a variadic argument */ |
|
41 | - private $isVariadic; |
|
42 | - |
|
43 | - /** @var bool determines whether this is passed by reference */ |
|
44 | - private $isReference; |
|
45 | - |
|
46 | - public function __construct( |
|
47 | - ?string $variableName, |
|
48 | - ?Type $type = null, |
|
49 | - bool $isVariadic = false, |
|
50 | - ?Description $description = null, |
|
51 | - bool $isReference = false |
|
52 | - ) { |
|
53 | - $this->name = 'param'; |
|
54 | - $this->variableName = $variableName; |
|
55 | - $this->type = $type; |
|
56 | - $this->isVariadic = $isVariadic; |
|
57 | - $this->description = $description; |
|
58 | - $this->isReference = $isReference; |
|
59 | - } |
|
60 | - |
|
61 | - public static function create( |
|
62 | - string $body, |
|
63 | - ?TypeResolver $typeResolver = null, |
|
64 | - ?DescriptionFactory $descriptionFactory = null, |
|
65 | - ?TypeContext $context = null |
|
66 | - ): self { |
|
67 | - Assert::stringNotEmpty($body); |
|
68 | - Assert::notNull($typeResolver); |
|
69 | - Assert::notNull($descriptionFactory); |
|
70 | - |
|
71 | - [$firstPart, $body] = self::extractTypeFromBody($body); |
|
72 | - |
|
73 | - $type = null; |
|
74 | - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
75 | - $variableName = ''; |
|
76 | - $isVariadic = false; |
|
77 | - $isReference = false; |
|
78 | - |
|
79 | - // if the first item that is encountered is not a variable; it is a type |
|
80 | - if ($firstPart && !self::strStartsWithVariable($firstPart)) { |
|
81 | - $type = $typeResolver->resolve($firstPart, $context); |
|
82 | - } else { |
|
83 | - // first part is not a type; we should prepend it to the parts array for further processing |
|
84 | - array_unshift($parts, $firstPart); |
|
85 | - } |
|
86 | - |
|
87 | - // if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name |
|
88 | - if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) { |
|
89 | - $variableName = array_shift($parts); |
|
90 | - if ($type) { |
|
91 | - array_shift($parts); |
|
92 | - } |
|
93 | - |
|
94 | - Assert::notNull($variableName); |
|
95 | - |
|
96 | - if (strpos($variableName, '$') === 0) { |
|
97 | - $variableName = substr($variableName, 1); |
|
98 | - } elseif (strpos($variableName, '&$') === 0) { |
|
99 | - $isReference = true; |
|
100 | - $variableName = substr($variableName, 2); |
|
101 | - } elseif (strpos($variableName, '...$') === 0) { |
|
102 | - $isVariadic = true; |
|
103 | - $variableName = substr($variableName, 4); |
|
104 | - } elseif (strpos($variableName, '&...$') === 0) { |
|
105 | - $isVariadic = true; |
|
106 | - $isReference = true; |
|
107 | - $variableName = substr($variableName, 5); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - $description = $descriptionFactory->create(implode('', $parts), $context); |
|
112 | - |
|
113 | - return new static($variableName, $type, $isVariadic, $description, $isReference); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns the variable's name. |
|
118 | - */ |
|
119 | - public function getVariableName(): ?string |
|
120 | - { |
|
121 | - return $this->variableName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Returns whether this tag is variadic. |
|
126 | - */ |
|
127 | - public function isVariadic(): bool |
|
128 | - { |
|
129 | - return $this->isVariadic; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Returns whether this tag is passed by reference. |
|
134 | - */ |
|
135 | - public function isReference(): bool |
|
136 | - { |
|
137 | - return $this->isReference; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns a string representation for this tag. |
|
142 | - */ |
|
143 | - public function __toString(): string |
|
144 | - { |
|
145 | - if ($this->description) { |
|
146 | - $description = $this->description->render(); |
|
147 | - } else { |
|
148 | - $description = ''; |
|
149 | - } |
|
150 | - |
|
151 | - $variableName = ''; |
|
152 | - if ($this->variableName) { |
|
153 | - $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); |
|
154 | - $variableName .= '$' . $this->variableName; |
|
155 | - } |
|
156 | - |
|
157 | - $type = (string) $this->type; |
|
158 | - |
|
159 | - return $type |
|
160 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
161 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
162 | - } |
|
163 | - |
|
164 | - private static function strStartsWithVariable(string $str): bool |
|
165 | - { |
|
166 | - return strpos($str, '$') === 0 |
|
167 | - || |
|
168 | - strpos($str, '...$') === 0 |
|
169 | - || |
|
170 | - strpos($str, '&$') === 0 |
|
171 | - || |
|
172 | - strpos($str, '&...$') === 0; |
|
173 | - } |
|
37 | + /** @var string|null */ |
|
38 | + private $variableName; |
|
39 | + |
|
40 | + /** @var bool determines whether this is a variadic argument */ |
|
41 | + private $isVariadic; |
|
42 | + |
|
43 | + /** @var bool determines whether this is passed by reference */ |
|
44 | + private $isReference; |
|
45 | + |
|
46 | + public function __construct( |
|
47 | + ?string $variableName, |
|
48 | + ?Type $type = null, |
|
49 | + bool $isVariadic = false, |
|
50 | + ?Description $description = null, |
|
51 | + bool $isReference = false |
|
52 | + ) { |
|
53 | + $this->name = 'param'; |
|
54 | + $this->variableName = $variableName; |
|
55 | + $this->type = $type; |
|
56 | + $this->isVariadic = $isVariadic; |
|
57 | + $this->description = $description; |
|
58 | + $this->isReference = $isReference; |
|
59 | + } |
|
60 | + |
|
61 | + public static function create( |
|
62 | + string $body, |
|
63 | + ?TypeResolver $typeResolver = null, |
|
64 | + ?DescriptionFactory $descriptionFactory = null, |
|
65 | + ?TypeContext $context = null |
|
66 | + ): self { |
|
67 | + Assert::stringNotEmpty($body); |
|
68 | + Assert::notNull($typeResolver); |
|
69 | + Assert::notNull($descriptionFactory); |
|
70 | + |
|
71 | + [$firstPart, $body] = self::extractTypeFromBody($body); |
|
72 | + |
|
73 | + $type = null; |
|
74 | + $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
75 | + $variableName = ''; |
|
76 | + $isVariadic = false; |
|
77 | + $isReference = false; |
|
78 | + |
|
79 | + // if the first item that is encountered is not a variable; it is a type |
|
80 | + if ($firstPart && !self::strStartsWithVariable($firstPart)) { |
|
81 | + $type = $typeResolver->resolve($firstPart, $context); |
|
82 | + } else { |
|
83 | + // first part is not a type; we should prepend it to the parts array for further processing |
|
84 | + array_unshift($parts, $firstPart); |
|
85 | + } |
|
86 | + |
|
87 | + // if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name |
|
88 | + if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) { |
|
89 | + $variableName = array_shift($parts); |
|
90 | + if ($type) { |
|
91 | + array_shift($parts); |
|
92 | + } |
|
93 | + |
|
94 | + Assert::notNull($variableName); |
|
95 | + |
|
96 | + if (strpos($variableName, '$') === 0) { |
|
97 | + $variableName = substr($variableName, 1); |
|
98 | + } elseif (strpos($variableName, '&$') === 0) { |
|
99 | + $isReference = true; |
|
100 | + $variableName = substr($variableName, 2); |
|
101 | + } elseif (strpos($variableName, '...$') === 0) { |
|
102 | + $isVariadic = true; |
|
103 | + $variableName = substr($variableName, 4); |
|
104 | + } elseif (strpos($variableName, '&...$') === 0) { |
|
105 | + $isVariadic = true; |
|
106 | + $isReference = true; |
|
107 | + $variableName = substr($variableName, 5); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + $description = $descriptionFactory->create(implode('', $parts), $context); |
|
112 | + |
|
113 | + return new static($variableName, $type, $isVariadic, $description, $isReference); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns the variable's name. |
|
118 | + */ |
|
119 | + public function getVariableName(): ?string |
|
120 | + { |
|
121 | + return $this->variableName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Returns whether this tag is variadic. |
|
126 | + */ |
|
127 | + public function isVariadic(): bool |
|
128 | + { |
|
129 | + return $this->isVariadic; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Returns whether this tag is passed by reference. |
|
134 | + */ |
|
135 | + public function isReference(): bool |
|
136 | + { |
|
137 | + return $this->isReference; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns a string representation for this tag. |
|
142 | + */ |
|
143 | + public function __toString(): string |
|
144 | + { |
|
145 | + if ($this->description) { |
|
146 | + $description = $this->description->render(); |
|
147 | + } else { |
|
148 | + $description = ''; |
|
149 | + } |
|
150 | + |
|
151 | + $variableName = ''; |
|
152 | + if ($this->variableName) { |
|
153 | + $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); |
|
154 | + $variableName .= '$' . $this->variableName; |
|
155 | + } |
|
156 | + |
|
157 | + $type = (string) $this->type; |
|
158 | + |
|
159 | + return $type |
|
160 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
161 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
162 | + } |
|
163 | + |
|
164 | + private static function strStartsWithVariable(string $str): bool |
|
165 | + { |
|
166 | + return strpos($str, '$') === 0 |
|
167 | + || |
|
168 | + strpos($str, '...$') === 0 |
|
169 | + || |
|
170 | + strpos($str, '&$') === 0 |
|
171 | + || |
|
172 | + strpos($str, '&...$') === 0; |
|
173 | + } |
|
174 | 174 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
75 | 75 | $variableName = ''; |
76 | 76 | $isVariadic = false; |
77 | - $isReference = false; |
|
77 | + $isReference = false; |
|
78 | 78 | |
79 | 79 | // if the first item that is encountered is not a variable; it is a type |
80 | - if ($firstPart && !self::strStartsWithVariable($firstPart)) { |
|
80 | + if ($firstPart && ! self::strStartsWithVariable($firstPart)) { |
|
81 | 81 | $type = $typeResolver->resolve($firstPart, $context); |
82 | 82 | } else { |
83 | 83 | // first part is not a type; we should prepend it to the parts array for further processing |
@@ -150,15 +150,15 @@ discard block |
||
150 | 150 | |
151 | 151 | $variableName = ''; |
152 | 152 | if ($this->variableName) { |
153 | - $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); |
|
154 | - $variableName .= '$' . $this->variableName; |
|
153 | + $variableName .= ($this->isReference ? '&' : '').($this->isVariadic ? '...' : ''); |
|
154 | + $variableName .= '$'.$this->variableName; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | $type = (string) $this->type; |
158 | 158 | |
159 | 159 | return $type |
160 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
161 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
160 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '').$variableName : '') |
|
161 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '').$description : ''); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | private static function strStartsWithVariable(string $str): bool |
@@ -33,74 +33,74 @@ |
||
33 | 33 | */ |
34 | 34 | final class See extends BaseTag implements Factory\StaticMethod |
35 | 35 | { |
36 | - /** @var string */ |
|
37 | - protected $name = 'see'; |
|
38 | - |
|
39 | - /** @var Reference */ |
|
40 | - protected $refers; |
|
41 | - |
|
42 | - /** |
|
43 | - * Initializes this tag. |
|
44 | - */ |
|
45 | - public function __construct(Reference $refers, ?Description $description = null) |
|
46 | - { |
|
47 | - $this->refers = $refers; |
|
48 | - $this->description = $description; |
|
49 | - } |
|
50 | - |
|
51 | - public static function create( |
|
52 | - string $body, |
|
53 | - ?FqsenResolver $typeResolver = null, |
|
54 | - ?DescriptionFactory $descriptionFactory = null, |
|
55 | - ?TypeContext $context = null |
|
56 | - ): self { |
|
57 | - Assert::notNull($descriptionFactory); |
|
58 | - |
|
59 | - $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
60 | - $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; |
|
61 | - |
|
62 | - // https://tools.ietf.org/html/rfc2396#section-3 |
|
63 | - if (preg_match('#\w://\w#', $parts[0])) { |
|
64 | - return new static(new Url($parts[0]), $description); |
|
65 | - } |
|
66 | - |
|
67 | - return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description); |
|
68 | - } |
|
69 | - |
|
70 | - private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen |
|
71 | - { |
|
72 | - Assert::notNull($fqsenResolver); |
|
73 | - $fqsenParts = explode('::', $parts); |
|
74 | - $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
|
75 | - |
|
76 | - if (!array_key_exists(1, $fqsenParts)) { |
|
77 | - return $resolved; |
|
78 | - } |
|
79 | - |
|
80 | - return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns the ref of this tag. |
|
85 | - */ |
|
86 | - public function getReference(): Reference |
|
87 | - { |
|
88 | - return $this->refers; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns a string representation of this tag. |
|
93 | - */ |
|
94 | - public function __toString(): string |
|
95 | - { |
|
96 | - if ($this->description) { |
|
97 | - $description = $this->description->render(); |
|
98 | - } else { |
|
99 | - $description = ''; |
|
100 | - } |
|
101 | - |
|
102 | - $refers = (string) $this->refers; |
|
103 | - |
|
104 | - return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
105 | - } |
|
36 | + /** @var string */ |
|
37 | + protected $name = 'see'; |
|
38 | + |
|
39 | + /** @var Reference */ |
|
40 | + protected $refers; |
|
41 | + |
|
42 | + /** |
|
43 | + * Initializes this tag. |
|
44 | + */ |
|
45 | + public function __construct(Reference $refers, ?Description $description = null) |
|
46 | + { |
|
47 | + $this->refers = $refers; |
|
48 | + $this->description = $description; |
|
49 | + } |
|
50 | + |
|
51 | + public static function create( |
|
52 | + string $body, |
|
53 | + ?FqsenResolver $typeResolver = null, |
|
54 | + ?DescriptionFactory $descriptionFactory = null, |
|
55 | + ?TypeContext $context = null |
|
56 | + ): self { |
|
57 | + Assert::notNull($descriptionFactory); |
|
58 | + |
|
59 | + $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
60 | + $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; |
|
61 | + |
|
62 | + // https://tools.ietf.org/html/rfc2396#section-3 |
|
63 | + if (preg_match('#\w://\w#', $parts[0])) { |
|
64 | + return new static(new Url($parts[0]), $description); |
|
65 | + } |
|
66 | + |
|
67 | + return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description); |
|
68 | + } |
|
69 | + |
|
70 | + private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen |
|
71 | + { |
|
72 | + Assert::notNull($fqsenResolver); |
|
73 | + $fqsenParts = explode('::', $parts); |
|
74 | + $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
|
75 | + |
|
76 | + if (!array_key_exists(1, $fqsenParts)) { |
|
77 | + return $resolved; |
|
78 | + } |
|
79 | + |
|
80 | + return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns the ref of this tag. |
|
85 | + */ |
|
86 | + public function getReference(): Reference |
|
87 | + { |
|
88 | + return $this->refers; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns a string representation of this tag. |
|
93 | + */ |
|
94 | + public function __toString(): string |
|
95 | + { |
|
96 | + if ($this->description) { |
|
97 | + $description = $this->description->render(); |
|
98 | + } else { |
|
99 | + $description = ''; |
|
100 | + } |
|
101 | + |
|
102 | + $refers = (string) $this->refers; |
|
103 | + |
|
104 | + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
105 | + } |
|
106 | 106 | } |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $fqsenParts = explode('::', $parts); |
69 | 69 | $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
70 | 70 | |
71 | - if (!array_key_exists(1, $fqsenParts)) { |
|
71 | + if ( ! array_key_exists(1, $fqsenParts)) { |
|
72 | 72 | return $resolved; |
73 | 73 | } |
74 | 74 | |
75 | - return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
75 | + return new Fqsen($resolved.'::'.$fqsenParts[1]); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -96,6 +96,6 @@ discard block |
||
96 | 96 | |
97 | 97 | $refers = (string) $this->refers; |
98 | 98 | |
99 | - return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
99 | + return $refers.($description !== '' ? ($refers !== '' ? ' ' : '').$description : ''); |
|
100 | 100 | } |
101 | 101 | } |
@@ -39,70 +39,70 @@ discard block |
||
39 | 39 | */ |
40 | 40 | final class Method extends BaseTag implements Factory\StaticMethod |
41 | 41 | { |
42 | - /** @var string */ |
|
43 | - protected $name = 'method'; |
|
44 | - |
|
45 | - /** @var string */ |
|
46 | - private $methodName; |
|
47 | - |
|
48 | - /** |
|
49 | - * @phpstan-var array<int, array{name: string, type: Type}> |
|
50 | - * @var array<int, array<string, Type|string>> |
|
51 | - */ |
|
52 | - private $arguments; |
|
53 | - |
|
54 | - /** @var bool */ |
|
55 | - private $isStatic; |
|
56 | - |
|
57 | - /** @var Type */ |
|
58 | - private $returnType; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array<int, array<string, Type|string>> $arguments |
|
62 | - * @phpstan-param array<int, array{name: string, type: Type}|string> $arguments |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - string $methodName, |
|
66 | - array $arguments = [], |
|
67 | - ?Type $returnType = null, |
|
68 | - bool $static = false, |
|
69 | - ?Description $description = null |
|
70 | - ) { |
|
71 | - Assert::stringNotEmpty($methodName); |
|
72 | - |
|
73 | - if ($returnType === null) { |
|
74 | - $returnType = new Void_(); |
|
75 | - } |
|
76 | - |
|
77 | - $this->methodName = $methodName; |
|
78 | - $this->arguments = $this->filterArguments($arguments); |
|
79 | - $this->returnType = $returnType; |
|
80 | - $this->isStatic = $static; |
|
81 | - $this->description = $description; |
|
82 | - } |
|
83 | - |
|
84 | - public static function create( |
|
85 | - string $body, |
|
86 | - ?TypeResolver $typeResolver = null, |
|
87 | - ?DescriptionFactory $descriptionFactory = null, |
|
88 | - ?TypeContext $context = null |
|
89 | - ): ?self { |
|
90 | - Assert::stringNotEmpty($body); |
|
91 | - Assert::notNull($typeResolver); |
|
92 | - Assert::notNull($descriptionFactory); |
|
93 | - |
|
94 | - // 1. none or more whitespace |
|
95 | - // 2. optionally the keyword "static" followed by whitespace |
|
96 | - // 3. optionally a word with underscores followed by whitespace : as |
|
97 | - // type for the return value |
|
98 | - // 4. then optionally a word with underscores followed by () and |
|
99 | - // whitespace : as method name as used by phpDocumentor |
|
100 | - // 5. then a word with underscores, followed by ( and any character |
|
101 | - // until a ) and whitespace : as method name with signature |
|
102 | - // 6. any remaining text : as description |
|
103 | - if ( |
|
104 | - !preg_match( |
|
105 | - '/^ |
|
42 | + /** @var string */ |
|
43 | + protected $name = 'method'; |
|
44 | + |
|
45 | + /** @var string */ |
|
46 | + private $methodName; |
|
47 | + |
|
48 | + /** |
|
49 | + * @phpstan-var array<int, array{name: string, type: Type}> |
|
50 | + * @var array<int, array<string, Type|string>> |
|
51 | + */ |
|
52 | + private $arguments; |
|
53 | + |
|
54 | + /** @var bool */ |
|
55 | + private $isStatic; |
|
56 | + |
|
57 | + /** @var Type */ |
|
58 | + private $returnType; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array<int, array<string, Type|string>> $arguments |
|
62 | + * @phpstan-param array<int, array{name: string, type: Type}|string> $arguments |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + string $methodName, |
|
66 | + array $arguments = [], |
|
67 | + ?Type $returnType = null, |
|
68 | + bool $static = false, |
|
69 | + ?Description $description = null |
|
70 | + ) { |
|
71 | + Assert::stringNotEmpty($methodName); |
|
72 | + |
|
73 | + if ($returnType === null) { |
|
74 | + $returnType = new Void_(); |
|
75 | + } |
|
76 | + |
|
77 | + $this->methodName = $methodName; |
|
78 | + $this->arguments = $this->filterArguments($arguments); |
|
79 | + $this->returnType = $returnType; |
|
80 | + $this->isStatic = $static; |
|
81 | + $this->description = $description; |
|
82 | + } |
|
83 | + |
|
84 | + public static function create( |
|
85 | + string $body, |
|
86 | + ?TypeResolver $typeResolver = null, |
|
87 | + ?DescriptionFactory $descriptionFactory = null, |
|
88 | + ?TypeContext $context = null |
|
89 | + ): ?self { |
|
90 | + Assert::stringNotEmpty($body); |
|
91 | + Assert::notNull($typeResolver); |
|
92 | + Assert::notNull($descriptionFactory); |
|
93 | + |
|
94 | + // 1. none or more whitespace |
|
95 | + // 2. optionally the keyword "static" followed by whitespace |
|
96 | + // 3. optionally a word with underscores followed by whitespace : as |
|
97 | + // type for the return value |
|
98 | + // 4. then optionally a word with underscores followed by () and |
|
99 | + // whitespace : as method name as used by phpDocumentor |
|
100 | + // 5. then a word with underscores, followed by ( and any character |
|
101 | + // until a ) and whitespace : as method name with signature |
|
102 | + // 6. any remaining text : as description |
|
103 | + if ( |
|
104 | + !preg_match( |
|
105 | + '/^ |
|
106 | 106 | # Static keyword |
107 | 107 | # Declares a static method ONLY if type is also present |
108 | 108 | (?: |
@@ -132,148 +132,148 @@ discard block |
||
132 | 132 | # Description |
133 | 133 | (.*) |
134 | 134 | $/sux', |
135 | - $body, |
|
136 | - $matches |
|
137 | - ) |
|
138 | - ) { |
|
139 | - return null; |
|
140 | - } |
|
141 | - |
|
142 | - [, $static, $returnType, $methodName, $argumentLines, $description] = $matches; |
|
143 | - |
|
144 | - $static = $static === 'static'; |
|
145 | - |
|
146 | - if ($returnType === '') { |
|
147 | - $returnType = 'void'; |
|
148 | - } |
|
149 | - |
|
150 | - $returnType = $typeResolver->resolve($returnType, $context); |
|
151 | - $description = $descriptionFactory->create($description, $context); |
|
152 | - |
|
153 | - /** @phpstan-var array<int, array{name: string, type: Type}> $arguments */ |
|
154 | - $arguments = []; |
|
155 | - if ($argumentLines !== '') { |
|
156 | - $argumentsExploded = explode(',', $argumentLines); |
|
157 | - foreach ($argumentsExploded as $argument) { |
|
158 | - $argument = explode(' ', self::stripRestArg(trim($argument)), 2); |
|
159 | - if (strpos($argument[0], '$') === 0) { |
|
160 | - $argumentName = substr($argument[0], 1); |
|
161 | - $argumentType = new Mixed_(); |
|
162 | - } else { |
|
163 | - $argumentType = $typeResolver->resolve($argument[0], $context); |
|
164 | - $argumentName = ''; |
|
165 | - if (isset($argument[1])) { |
|
166 | - $argument[1] = self::stripRestArg($argument[1]); |
|
167 | - $argumentName = substr($argument[1], 1); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - $arguments[] = ['name' => $argumentName, 'type' => $argumentType]; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - return new static($methodName, $arguments, $returnType, $static, $description); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Retrieves the method name. |
|
180 | - */ |
|
181 | - public function getMethodName(): string |
|
182 | - { |
|
183 | - return $this->methodName; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return array<int, array<string, Type|string>> |
|
188 | - * @phpstan-return array<int, array{name: string, type: Type}> |
|
189 | - */ |
|
190 | - public function getArguments(): array |
|
191 | - { |
|
192 | - return $this->arguments; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Checks whether the method tag describes a static method or not. |
|
197 | - * |
|
198 | - * @return bool TRUE if the method declaration is for a static method, FALSE otherwise. |
|
199 | - */ |
|
200 | - public function isStatic(): bool |
|
201 | - { |
|
202 | - return $this->isStatic; |
|
203 | - } |
|
204 | - |
|
205 | - public function getReturnType(): Type |
|
206 | - { |
|
207 | - return $this->returnType; |
|
208 | - } |
|
209 | - |
|
210 | - public function __toString(): string |
|
211 | - { |
|
212 | - $arguments = []; |
|
213 | - foreach ($this->arguments as $argument) { |
|
214 | - $arguments[] = $argument['type'] . ' $' . $argument['name']; |
|
215 | - } |
|
216 | - |
|
217 | - $argumentStr = '(' . implode(', ', $arguments) . ')'; |
|
218 | - |
|
219 | - if ($this->description) { |
|
220 | - $description = $this->description->render(); |
|
221 | - } else { |
|
222 | - $description = ''; |
|
223 | - } |
|
224 | - |
|
225 | - $static = $this->isStatic ? 'static' : ''; |
|
226 | - |
|
227 | - $returnType = (string) $this->returnType; |
|
228 | - |
|
229 | - $methodName = $this->methodName; |
|
230 | - |
|
231 | - return $static |
|
232 | - . ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '') |
|
233 | - . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $methodName : '') |
|
234 | - . $argumentStr |
|
235 | - . ($description !== '' ? ' ' . $description : ''); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @param mixed[][]|string[] $arguments |
|
240 | - * @phpstan-param array<int, array{name: string, type: Type}|string> $arguments |
|
241 | - * |
|
242 | - * @return mixed[][] |
|
243 | - * @phpstan-return array<int, array{name: string, type: Type}> |
|
244 | - */ |
|
245 | - private function filterArguments(array $arguments = []): array |
|
246 | - { |
|
247 | - $result = []; |
|
248 | - foreach ($arguments as $argument) { |
|
249 | - if (is_string($argument)) { |
|
250 | - $argument = ['name' => $argument]; |
|
251 | - } |
|
252 | - |
|
253 | - if (!isset($argument['type'])) { |
|
254 | - $argument['type'] = new Mixed_(); |
|
255 | - } |
|
256 | - |
|
257 | - $keys = array_keys($argument); |
|
258 | - sort($keys); |
|
259 | - if ($keys !== ['name', 'type']) { |
|
260 | - throw new InvalidArgumentException( |
|
261 | - 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) |
|
262 | - ); |
|
263 | - } |
|
264 | - |
|
265 | - $result[] = $argument; |
|
266 | - } |
|
267 | - |
|
268 | - return $result; |
|
269 | - } |
|
270 | - |
|
271 | - private static function stripRestArg(string $argument): string |
|
272 | - { |
|
273 | - if (strpos($argument, '...') === 0) { |
|
274 | - $argument = trim(substr($argument, 3)); |
|
275 | - } |
|
276 | - |
|
277 | - return $argument; |
|
278 | - } |
|
135 | + $body, |
|
136 | + $matches |
|
137 | + ) |
|
138 | + ) { |
|
139 | + return null; |
|
140 | + } |
|
141 | + |
|
142 | + [, $static, $returnType, $methodName, $argumentLines, $description] = $matches; |
|
143 | + |
|
144 | + $static = $static === 'static'; |
|
145 | + |
|
146 | + if ($returnType === '') { |
|
147 | + $returnType = 'void'; |
|
148 | + } |
|
149 | + |
|
150 | + $returnType = $typeResolver->resolve($returnType, $context); |
|
151 | + $description = $descriptionFactory->create($description, $context); |
|
152 | + |
|
153 | + /** @phpstan-var array<int, array{name: string, type: Type}> $arguments */ |
|
154 | + $arguments = []; |
|
155 | + if ($argumentLines !== '') { |
|
156 | + $argumentsExploded = explode(',', $argumentLines); |
|
157 | + foreach ($argumentsExploded as $argument) { |
|
158 | + $argument = explode(' ', self::stripRestArg(trim($argument)), 2); |
|
159 | + if (strpos($argument[0], '$') === 0) { |
|
160 | + $argumentName = substr($argument[0], 1); |
|
161 | + $argumentType = new Mixed_(); |
|
162 | + } else { |
|
163 | + $argumentType = $typeResolver->resolve($argument[0], $context); |
|
164 | + $argumentName = ''; |
|
165 | + if (isset($argument[1])) { |
|
166 | + $argument[1] = self::stripRestArg($argument[1]); |
|
167 | + $argumentName = substr($argument[1], 1); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + $arguments[] = ['name' => $argumentName, 'type' => $argumentType]; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + return new static($methodName, $arguments, $returnType, $static, $description); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Retrieves the method name. |
|
180 | + */ |
|
181 | + public function getMethodName(): string |
|
182 | + { |
|
183 | + return $this->methodName; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return array<int, array<string, Type|string>> |
|
188 | + * @phpstan-return array<int, array{name: string, type: Type}> |
|
189 | + */ |
|
190 | + public function getArguments(): array |
|
191 | + { |
|
192 | + return $this->arguments; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Checks whether the method tag describes a static method or not. |
|
197 | + * |
|
198 | + * @return bool TRUE if the method declaration is for a static method, FALSE otherwise. |
|
199 | + */ |
|
200 | + public function isStatic(): bool |
|
201 | + { |
|
202 | + return $this->isStatic; |
|
203 | + } |
|
204 | + |
|
205 | + public function getReturnType(): Type |
|
206 | + { |
|
207 | + return $this->returnType; |
|
208 | + } |
|
209 | + |
|
210 | + public function __toString(): string |
|
211 | + { |
|
212 | + $arguments = []; |
|
213 | + foreach ($this->arguments as $argument) { |
|
214 | + $arguments[] = $argument['type'] . ' $' . $argument['name']; |
|
215 | + } |
|
216 | + |
|
217 | + $argumentStr = '(' . implode(', ', $arguments) . ')'; |
|
218 | + |
|
219 | + if ($this->description) { |
|
220 | + $description = $this->description->render(); |
|
221 | + } else { |
|
222 | + $description = ''; |
|
223 | + } |
|
224 | + |
|
225 | + $static = $this->isStatic ? 'static' : ''; |
|
226 | + |
|
227 | + $returnType = (string) $this->returnType; |
|
228 | + |
|
229 | + $methodName = $this->methodName; |
|
230 | + |
|
231 | + return $static |
|
232 | + . ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '') |
|
233 | + . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $methodName : '') |
|
234 | + . $argumentStr |
|
235 | + . ($description !== '' ? ' ' . $description : ''); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @param mixed[][]|string[] $arguments |
|
240 | + * @phpstan-param array<int, array{name: string, type: Type}|string> $arguments |
|
241 | + * |
|
242 | + * @return mixed[][] |
|
243 | + * @phpstan-return array<int, array{name: string, type: Type}> |
|
244 | + */ |
|
245 | + private function filterArguments(array $arguments = []): array |
|
246 | + { |
|
247 | + $result = []; |
|
248 | + foreach ($arguments as $argument) { |
|
249 | + if (is_string($argument)) { |
|
250 | + $argument = ['name' => $argument]; |
|
251 | + } |
|
252 | + |
|
253 | + if (!isset($argument['type'])) { |
|
254 | + $argument['type'] = new Mixed_(); |
|
255 | + } |
|
256 | + |
|
257 | + $keys = array_keys($argument); |
|
258 | + sort($keys); |
|
259 | + if ($keys !== ['name', 'type']) { |
|
260 | + throw new InvalidArgumentException( |
|
261 | + 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) |
|
262 | + ); |
|
263 | + } |
|
264 | + |
|
265 | + $result[] = $argument; |
|
266 | + } |
|
267 | + |
|
268 | + return $result; |
|
269 | + } |
|
270 | + |
|
271 | + private static function stripRestArg(string $argument): string |
|
272 | + { |
|
273 | + if (strpos($argument, '...') === 0) { |
|
274 | + $argument = trim(substr($argument, 3)); |
|
275 | + } |
|
276 | + |
|
277 | + return $argument; |
|
278 | + } |
|
279 | 279 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | // until a ) and whitespace : as method name with signature |
102 | 102 | // 6. any remaining text : as description |
103 | 103 | if ( |
104 | - !preg_match( |
|
104 | + ! preg_match( |
|
105 | 105 | '/^ |
106 | 106 | # Static keyword |
107 | 107 | # Declares a static method ONLY if type is also present |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | { |
212 | 212 | $arguments = []; |
213 | 213 | foreach ($this->arguments as $argument) { |
214 | - $arguments[] = $argument['type'] . ' $' . $argument['name']; |
|
214 | + $arguments[] = $argument['type'].' $'.$argument['name']; |
|
215 | 215 | } |
216 | 216 | |
217 | - $argumentStr = '(' . implode(', ', $arguments) . ')'; |
|
217 | + $argumentStr = '('.implode(', ', $arguments).')'; |
|
218 | 218 | |
219 | 219 | if ($this->description) { |
220 | 220 | $description = $this->description->render(); |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | $methodName = $this->methodName; |
230 | 230 | |
231 | 231 | return $static |
232 | - . ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '') |
|
233 | - . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $methodName : '') |
|
232 | + . ($returnType !== '' ? ($static !== '' ? ' ' : '').$returnType : '') |
|
233 | + . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '').$methodName : '') |
|
234 | 234 | . $argumentStr |
235 | - . ($description !== '' ? ' ' . $description : ''); |
|
235 | + . ($description !== '' ? ' '.$description : ''); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $argument = ['name' => $argument]; |
251 | 251 | } |
252 | 252 | |
253 | - if (!isset($argument['type'])) { |
|
253 | + if ( ! isset($argument['type'])) { |
|
254 | 254 | $argument['type'] = new Mixed_(); |
255 | 255 | } |
256 | 256 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | sort($keys); |
259 | 259 | if ($keys !== ['name', 'type']) { |
260 | 260 | throw new InvalidArgumentException( |
261 | - 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) |
|
261 | + 'Arguments can only have the "name" and "type" fields, found: '.var_export($keys, true) |
|
262 | 262 | ); |
263 | 263 | } |
264 | 264 |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | final class Deprecated extends BaseTag implements Factory\StaticMethod |
27 | 27 | { |
28 | - /** @var string */ |
|
29 | - protected $name = 'deprecated'; |
|
30 | - |
|
31 | - /** |
|
32 | - * PCRE regular expression matching a version vector. |
|
33 | - * Assumes the "x" modifier. |
|
34 | - */ |
|
35 | - public const REGEX_VECTOR = '(?: |
|
28 | + /** @var string */ |
|
29 | + protected $name = 'deprecated'; |
|
30 | + |
|
31 | + /** |
|
32 | + * PCRE regular expression matching a version vector. |
|
33 | + * Assumes the "x" modifier. |
|
34 | + */ |
|
35 | + public const REGEX_VECTOR = '(?: |
|
36 | 36 | # Normal release vectors. |
37 | 37 | \d\S* |
38 | 38 | | |
@@ -44,66 +44,66 @@ discard block |
||
44 | 44 | [^\s\:]+\:\s*\$[^\$]+\$ |
45 | 45 | )'; |
46 | 46 | |
47 | - /** @var string|null The version vector. */ |
|
48 | - private $version; |
|
49 | - |
|
50 | - public function __construct(?string $version = null, ?Description $description = null) |
|
51 | - { |
|
52 | - Assert::nullOrNotEmpty($version); |
|
53 | - |
|
54 | - $this->version = $version; |
|
55 | - $this->description = $description; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public static function create( |
|
62 | - ?string $body, |
|
63 | - ?DescriptionFactory $descriptionFactory = null, |
|
64 | - ?TypeContext $context = null |
|
65 | - ): self { |
|
66 | - if (empty($body)) { |
|
67 | - return new static(); |
|
68 | - } |
|
69 | - |
|
70 | - $matches = []; |
|
71 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
72 | - return new static( |
|
73 | - null, |
|
74 | - $descriptionFactory !== null ? $descriptionFactory->create($body, $context) : null |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - Assert::notNull($descriptionFactory); |
|
79 | - |
|
80 | - return new static( |
|
81 | - $matches[1], |
|
82 | - $descriptionFactory->create($matches[2] ?? '', $context) |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Gets the version section of the tag. |
|
88 | - */ |
|
89 | - public function getVersion(): ?string |
|
90 | - { |
|
91 | - return $this->version; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns a string representation for this tag. |
|
96 | - */ |
|
97 | - public function __toString(): string |
|
98 | - { |
|
99 | - if ($this->description) { |
|
100 | - $description = $this->description->render(); |
|
101 | - } else { |
|
102 | - $description = ''; |
|
103 | - } |
|
104 | - |
|
105 | - $version = (string) $this->version; |
|
106 | - |
|
107 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
108 | - } |
|
47 | + /** @var string|null The version vector. */ |
|
48 | + private $version; |
|
49 | + |
|
50 | + public function __construct(?string $version = null, ?Description $description = null) |
|
51 | + { |
|
52 | + Assert::nullOrNotEmpty($version); |
|
53 | + |
|
54 | + $this->version = $version; |
|
55 | + $this->description = $description; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public static function create( |
|
62 | + ?string $body, |
|
63 | + ?DescriptionFactory $descriptionFactory = null, |
|
64 | + ?TypeContext $context = null |
|
65 | + ): self { |
|
66 | + if (empty($body)) { |
|
67 | + return new static(); |
|
68 | + } |
|
69 | + |
|
70 | + $matches = []; |
|
71 | + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
72 | + return new static( |
|
73 | + null, |
|
74 | + $descriptionFactory !== null ? $descriptionFactory->create($body, $context) : null |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + Assert::notNull($descriptionFactory); |
|
79 | + |
|
80 | + return new static( |
|
81 | + $matches[1], |
|
82 | + $descriptionFactory->create($matches[2] ?? '', $context) |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Gets the version section of the tag. |
|
88 | + */ |
|
89 | + public function getVersion(): ?string |
|
90 | + { |
|
91 | + return $this->version; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns a string representation for this tag. |
|
96 | + */ |
|
97 | + public function __toString(): string |
|
98 | + { |
|
99 | + if ($this->description) { |
|
100 | + $description = $this->description->render(); |
|
101 | + } else { |
|
102 | + $description = ''; |
|
103 | + } |
|
104 | + |
|
105 | + $version = (string) $this->version; |
|
106 | + |
|
107 | + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
108 | + } |
|
109 | 109 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | $matches = []; |
71 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
71 | + if ( ! preg_match('/^('.self::REGEX_VECTOR.')\s*(.+)?$/sux', $body, $matches)) { |
|
72 | 72 | return new static( |
73 | 73 | null, |
74 | 74 | $descriptionFactory !== null ? $descriptionFactory->create($body, $context) : null |
@@ -104,6 +104,6 @@ discard block |
||
104 | 104 | |
105 | 105 | $version = (string) $this->version; |
106 | 106 | |
107 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
107 | + return $version.($description !== '' ? ($version !== '' ? ' ' : '').$description : ''); |
|
108 | 108 | } |
109 | 109 | } |