Skip to content

Commit 22325b6

Browse files
minor symfony#53542 [ErrorHandler] Fix RecursiveDirectoryIterator exception with wrong composer autoload (symfonyaml)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Fix `RecursiveDirectoryIterator` exception with wrong composer autoload | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | Issues | Fix symfony#53541 | License | MIT ### Issue When defining an autoload directory in `composer.json` that actually points to a file _(rather than a directory)_, we have the following error : ``` Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/path/to/file): Failed to open directory: Not a directory ``` See all details and how to reproduce it in the issue symfony#53541 ### Solution In this PR : - Make sure that the [ClassNotFoundErrorEnhancer::findClassInPath()](https://github.com/symfony/error-handler/blob/7.0/ErrorEnhancer/ClassNotFoundErrorEnhancer.php#L108) method checks if the `$path` is a directory. - Fixed coding standards proposed by fabbot.io Commits ------- 7809765 [ErrorHandler] Fix `RecursiveDirectoryIterator` exception with wrong composer autoload
2 parents db2c6e4 + 7809765 commit 22325b6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Symfony/Component/ErrorHandler/ErrorEnhancer/ClassNotFoundErrorEnhancer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
*/
2222
class ClassNotFoundErrorEnhancer implements ErrorEnhancerInterface
2323
{
24-
/**
25-
* {@inheritdoc}
26-
*/
2724
public function enhance(\Throwable $error): ?\Throwable
2825
{
2926
// Some specific versions of PHP produce a fatal error when extending a not found class.
@@ -110,7 +107,8 @@ private function getClassCandidates(string $class): array
110107

111108
private function findClassInPath(string $path, string $class, string $prefix): array
112109
{
113-
if (!$path = realpath($path.'/'.strtr($prefix, '\\_', '//')) ?: realpath($path.'/'.\dirname(strtr($prefix, '\\_', '//'))) ?: realpath($path)) {
110+
$path = realpath($path.'/'.strtr($prefix, '\\_', '//')) ?: realpath($path.'/'.\dirname(strtr($prefix, '\\_', '//'))) ?: realpath($path);
111+
if (!$path || !is_dir($path)) {
114112
return [];
115113
}
116114

0 commit comments

Comments
 (0)