Skip to content

Commit

Permalink
Fix autodetection of config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Dec 27, 2024
1 parent 44d139d commit 501426d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 1 addition & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
intval=>null,
strval=>null,
settype=>null,
exit=>null,
reset=>array_key_first
exit=>null
"
/>
</properties>
Expand Down
18 changes: 12 additions & 6 deletions src/Provider/SymfonyUsageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
use SimpleXMLElement;
use SplFileInfo;
use UnexpectedValueException;
use function array_key_first;
use function array_filter;
use function array_keys;
use function count;
use function explode;
use function file_get_contents;
use function in_array;
use function is_dir;
use function preg_match_all;
use function reset;
use function simplexml_load_string;
use function sprintf;
use function strpos;
use const PHP_VERSION_ID;

class SymfonyUsageProvider implements MemberUsageProvider
Expand Down Expand Up @@ -405,16 +408,19 @@ private function createUsage(ExtendedMethodReflection $methodReflection): ClassM

private function autodetectConfigDir(): ?string
{
$classLoaders = ClassLoader::getRegisteredLoaders();
$vendorDirs = array_filter(array_keys(ClassLoader::getRegisteredLoaders()), static function (string $vendorDir): bool {
return strpos($vendorDir, 'phar://') === false;
});

if (count($classLoaders) !== 1) {
if (count($vendorDirs) !== 1) {
return null;
}

$vendorDir = array_key_first($classLoaders);
$vendorDir = reset($vendorDirs);
$configDir = $vendorDir . '/../config';

if (is_dir($vendorDir . '/../config')) {
return $vendorDir . '/config';
if (is_dir($configDir)) {
return $configDir;
}

return null;
Expand Down

0 comments on commit 501426d

Please sign in to comment.