Skip to content

Commit 9c1b5fe

Browse files
authored
Add note for substr() can return false on php 7.x on ClassLikeNameClassNameImportSkipVoter (#7438)
* Add note for substr() can return false on php 7.x on ClassLikeNameClassNameImportSkipVoter * Add note for substr() can return false on php 7.x on ClassLikeNameClassNameImportSkipVoter
1 parent 21b6091 commit 9c1b5fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
4646
$namespace = strtolower((string) $namespace);
4747

4848
$shortNameLowered = $fullyQualifiedObjectType->getShortNameLowered();
49-
$subClassName = substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1);
50-
$fullyQualifiedObjectTypeNamespace = strtolower((string) $subClassName);
49+
/**
50+
* on php 7.x, substr() result can return false, so force (string) is needed
51+
* @see https://github.com/rectorphp/rector-src/pull/7436
52+
*/
53+
$subClassName = (string) substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1);
54+
$fullyQualifiedObjectTypeNamespace = strtolower($subClassName);
5155

5256
foreach ($classLikeNames as $classLikeName) {
5357
if (strtolower($classLikeName) !== $shortNameLowered) {

0 commit comments

Comments
 (0)