Skip to content

Commit

Permalink
Classes/NewClasses: bug fix
Browse files Browse the repository at this point in the history
All parts of a type should be checked, the sniff should not bow out if the first part of the type is not a new class.

Fixed now.

Includes test.
  • Loading branch information
jrfnl committed Apr 20, 2024
1 parent a988e5b commit 6e2c140
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions PHPCompatibility/Sniffs/Classes/NewClassesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1351,12 +1351,12 @@ private function checkTypeDeclaration($phpcsFile, $stackPtr, $typeString)
$type = \ltrim($type, '\\');

if ($type === '') {
return;
continue;
}

$typeLc = \strtolower($type);
if (isset($this->newClasses[$typeLc]) === false) {
return;
continue;
}

$itemInfo = [
Expand Down
5 changes: 5 additions & 0 deletions PHPCompatibility/Tests/Classes/NewClassesUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,8 @@ class MyRandom extends \Random\Randomizer {
}
}
}


function CheckAllTypeParts(
NotATarget|XMLReader $a
) : NotATarget|ReflectionType {}
4 changes: 2 additions & 2 deletions PHPCompatibility/Tests/Classes/NewClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function dataNewClass()
['RecursiveCachingIterator', '5.0', [297], '5.1'],
['RecursiveFilterIterator', '5.0', [298], '5.1'],
['SimpleXMLIterator', '5.0', [311], '5.1'],
['XMLReader', '5.0', [312, 336], '5.1'],
['XMLReader', '5.0', [312, 336, 489], '5.1'],
['SplFileObject', '5.0', [302, 336], '5.1'],
['SplObjectStorage', '5.0', [282], '5.1'],
['SplFileInfo', '5.1.1', [303], '5.2', '5.1'],
Expand Down Expand Up @@ -197,7 +197,7 @@ public static function dataNewClass()
['UConverter', '5.4', [276], '5.5'],
['GMP', '5.5', [281], '5.6'],
['IntlChar', '5.6', [277, 448], '7.0'],
['ReflectionType', '5.6', [308], '7.0'],
['ReflectionType', '5.6', [308, 490], '7.0'],
['ReflectionGenerator', '5.6', [309], '7.0'],
['ReflectionClassConstant', '7.0', [306, 465], '7.1'],
['ReflectionNamedType', '7.0', [359, 465], '7.1'],
Expand Down

0 comments on commit 6e2c140

Please sign in to comment.