Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO

$shortNameLowered = $fullyQualifiedObjectType->getShortNameLowered();
$fullyQualifiedObjectTypeNamespace = strtolower(
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1)
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1) ?: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note about PHP 7.4? So we don't accidentally remove it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I created new PR to add note for it

the RecastingRemovalRector needs also improvement for it, currently skipped

rector-src/rector.php

Lines 57 to 60 in 21b6091

// todo: properly handle, substr() can return false on php 7.x
RecastingRemovalRector::class => [
__DIR__ . '/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php',
],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this problem is not patched by PHPStan. is it reproducible on the phpstan playground, that we are missing a error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems on phpstan.org, it shows

on php 8.0+, show empy string
on php 7.2+, show false

see https://phpstan.org/r/6c0960c9-23d9-4387-8f95-f13f2f50f33b

Copy link
Contributor

@clxmstaab clxmstaab Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh I just see rector-src does not run PHPStan on PHP7.x.. you are only using a single PHP 8.2 job and therefore miss PHPStan errors on all other PHP versions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created PR to skip remove (string) case on substr() on RecastingRemovalRector on getNativeType() method:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be also good candidate for a downgrade rule

);

foreach ($classLikeNames as $classLikeName) {
Expand Down