Skip to content

Commit 5f5853d

Browse files
committed
PhpdocToReturnTypeFixer - tests against all tokens
1 parent 382e00e commit 5f5853d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
251251
continue;
252252
}
253253

254+
try {
255+
Tokens::fromCode(sprintf('<?php function f():%s {}', $returnType));
256+
} catch (\ParseError $e) {
257+
continue;
258+
}
259+
254260
$this->fixFunctionDefinition($tokens, $startIndex, $isNullable, $returnType);
255261
}
256262
}

tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function provideFixCases()
6060
'invalid class 2' => [
6161
'<?php /** @return \\Foo\\\\Bar */ function my_foo() {}',
6262
],
63+
'invalid class 3' => [
64+
'<?php /** @return Break */ function my_foo() {}',
65+
],
66+
'invalid class 4' => [
67+
'<?php /** @return __CLASS__ */ function my_foo() {}',
68+
],
6369
'blacklisted class methods' => [
6470
'<?php
6571

0 commit comments

Comments
 (0)