Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,14 @@
<?php

// "$value{0}" cannot be parsed by PHPStan, so the class is unknown to reflection and must be skipped, not crash
class SkipClassUnknownToReflection
{
function SkipClassUnknownToReflection()
{
}

function first($value)
{
return $value{0};
}
}
3 changes: 2 additions & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ protected function fetchClassLikeReflection(ClassLike $classLike): ?ClassReflect
return null;
}

// the class can be unknown to reflection, e.g. when the file has syntax that PHPStan cannot parse, like "$value{0}"
if (! $this->reflectionProvider->hasClass($className)) {
throw new ShouldNotHappenException(sprintf('Class "%s" should be known at this point', $className));
return null;
}

return $this->reflectionProvider->getClass($className);
Expand Down
Loading