Skip to content

Commit 043ba68

Browse files
committed
FunctionsAnalyzer: fix for comment in type
1 parent 015ef53 commit 043ba68

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Tokenizer/Analyzer/FunctionsAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public function getFunctionReturnType(Tokens $tokens, $methodIndex)
8282
}
8383

8484
$type = '';
85-
$typeStartIndex = $tokens->getNextNonWhitespace($typeColonIndex);
85+
$typeStartIndex = $tokens->getNextMeaningfulToken($typeColonIndex);
8686
$typeEndIndex = $typeStartIndex;
8787
$functionBodyStart = $tokens->getNextTokenOfKind($typeColonIndex, ['{', ';']);
8888
for ($i = $typeStartIndex; $i < $functionBodyStart; ++$i) {
89-
if ($tokens[$i]->isWhitespace()) {
89+
if ($tokens[$i]->isWhitespace() || $tokens[$i]->isComment()) {
9090
continue;
9191
}
9292

tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ public function provideFunctionsWithArgumentsCases()
213213
)
214214
),
215215
]],
216+
['<?php function(\Foo\Bar $a){};', 1, [
217+
'$a' => new ArgumentAnalysis(
218+
'$a',
219+
8,
220+
null,
221+
new TypeAnalysis(
222+
'\Foo\Bar',
223+
3,
224+
6
225+
)
226+
),
227+
]],
228+
['<?php function(\Foo/** TODO: change to something else */\Bar $a){};', 1, [
229+
'$a' => new ArgumentAnalysis(
230+
'$a',
231+
9,
232+
null,
233+
new TypeAnalysis(
234+
'\Foo\Bar',
235+
3,
236+
7
237+
)
238+
),
239+
]],
216240
];
217241
}
218242

@@ -222,6 +246,8 @@ public function provideFunctionsWithReturnTypeCases()
222246
['<?php function(){};', 1, null],
223247
['<?php function($a): array {};', 1, new TypeAnalysis('array', 7, 7)],
224248
['<?php function($a): \Foo\Bar {};', 1, new TypeAnalysis('\Foo\Bar', 7, 10)],
249+
['<?php function($a): /* not sure if really an array */array {};', 1, new TypeAnalysis('array', 8, 8)],
250+
['<?php function($a): \Foo/** TODO: change to something else */\Bar {};', 1, new TypeAnalysis('\Foo\Bar', 7, 11)],
225251
];
226252
}
227253
}

0 commit comments

Comments
 (0)