Skip to content

Commit f92b002

Browse files
committed
Fix everything.
1 parent f6c7d9d commit f92b002

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

visitor.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ public function enterNode(Node $node)
2929
parent::enterNode($node);
3030

3131
if (!($node instanceof Function_) && !($node instanceof ClassMethod)) {
32-
return;
32+
return null;
3333
}
3434

3535
$docComment = $node->getDocComment();
3636

3737
if (!($docComment instanceof Doc)) {
38-
return;
38+
return null;
3939
}
4040

4141
$newDocComment = $this->addArrayHashNotation($docComment);
4242

4343
if ($newDocComment !== null) {
4444
$node->setDocComment($newDocComment);
4545
}
46+
47+
return null;
4648
}
4749

4850
private function addArrayHashNotation(Doc $docComment): ?Doc
@@ -168,6 +170,10 @@ private function getTypeNameFromType(Type $tagVariableType): ?string
168170
// typed arrays such as `int[]` with `array`.
169171
$tagVariableType = preg_replace('#[a-zA-Z0-9_]+\[\]#', 'array', $tagVariableType->__toString());
170172

173+
if ($tagVariableType === null) {
174+
return null;
175+
}
176+
171177
if (strpos($tagVariableType, 'array') === false) {
172178
// Skip if we have hash notation that's not for an array (ie. for `object`).
173179
return null;
@@ -196,11 +202,22 @@ private function getElementsFromDescription(Description $tagDescription, bool $o
196202

197203
// Populate `$types` with the value of each top level `@type`.
198204
$types = preg_split('/\R+ @type /', $text);
205+
206+
if (!$types) {
207+
return null;
208+
}
209+
199210
unset($types[0]);
200211
$elements = [];
201212

202213
foreach ($types as $typeTag) {
203-
list($type, $name) = preg_split('#\s+#', trim($typeTag));
214+
$parts = preg_split('#\s+#', trim($typeTag));
215+
216+
if (!$parts || count($parts) < 2) {
217+
return null;
218+
}
219+
220+
list($type, $name) = $parts;
204221

205222
// Bail out completely if any element doesn't have a static key.
206223
if (strpos($name, '...$') !== false) {

0 commit comments

Comments
 (0)