Skip to content

Commit 2311922

Browse files
committed
Add all __ prefixed methods to return type whitelist
1 parent 1c6c12d commit 2311922

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Inpsyde\PhpcsHelpers;
1919
use PHP_CodeSniffer\Sniffs\Sniff;
2020
use PHP_CodeSniffer\Files\File;
21-
use PHPCompatibility;
21+
use PHP_CodeSniffer\Config;
2222

2323
class ReturnTypeDeclarationSniff implements Sniff
2424
{
@@ -30,7 +30,6 @@ class ReturnTypeDeclarationSniff implements Sniff
3030
];
3131

3232
const METHODS_WHITELIST = [
33-
'__to_string',
3433
'serialize',
3534
'jsonSerialize',
3635
'getIterator',
@@ -166,8 +165,9 @@ private function maybeErrors(
166165
return;
167166
}
168167

168+
$name = $file->getDeclarationName($position);
169169
if (PhpcsHelpers::functionIsMethod($file, $position)
170-
&& in_array($file->getDeclarationName($position), self::METHODS_WHITELIST, true)
170+
&& (in_array($name, self::METHODS_WHITELIST, true) || strpos($name, '__') === 0)
171171
) {
172172
return;
173173
}
@@ -328,7 +328,7 @@ private function hasReturnNullDocBloc(File $file, int $functionPosition): bool
328328
*/
329329
private function areNullableReturnTypesSupported(): bool
330330
{
331-
$testVersion = trim(PHPCompatibility\PHPCSHelper::getConfigData('testVersion') ?: '');
331+
$testVersion = trim(Config::getConfigData('testVersion') ?: '');
332332
if (!$testVersion) {
333333
return false;
334334
}

0 commit comments

Comments
 (0)