From fbb8db40f5c70b1239b69fc9a69c6fdcafa5571a Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 14 Dec 2022 17:02:00 +0900 Subject: [PATCH] fix: spark namespaces cannot show a namespace with mutilple paths --- app/Config/Autoload.php | 3 ++- phpstan-baseline.neon.dist | 5 ----- system/Commands/Utilities/Namespaces.php | 20 +++++++++++++------- system/Config/AutoloadConfig.php | 3 ++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index bd86556062..61721a0f71 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -38,7 +38,8 @@ class Autoload extends AutoloadConfig * ]; *``` * - * @var array + * @var array|string> + * @phpstan-var array> */ public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace diff --git a/phpstan-baseline.neon.dist b/phpstan-baseline.neon.dist index 71f85c8c6b..9649807654 100644 --- a/phpstan-baseline.neon.dist +++ b/phpstan-baseline.neon.dist @@ -20,11 +20,6 @@ parameters: count: 1 path: system/Autoloader/Autoloader.php - - - message: "#^Property Config\\\\Autoload\\:\\:\\$psr4 \\(array\\\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: system/Autoloader/Autoloader.php - - message: "#^Property Config\\\\Cache\\:\\:\\$backupHandler \\(string\\) in isset\\(\\) is not nullable\\.$#" count: 1 diff --git a/system/Commands/Utilities/Namespaces.php b/system/Commands/Utilities/Namespaces.php index 989f02036e..64cad210f7 100644 --- a/system/Commands/Utilities/Namespaces.php +++ b/system/Commands/Utilities/Namespaces.php @@ -74,14 +74,20 @@ class Namespaces extends BaseCommand $tbody = []; - foreach ($config->psr4 as $ns => $path) { - $path = realpath($path) ?: $path; + foreach ($config->psr4 as $ns => $paths) { + if (is_string($paths)) { + $paths = [$paths]; + } - $tbody[] = [ - $ns, - realpath($path) ?: $path, - is_dir($path) ? 'Yes' : 'MISSING', - ]; + foreach ($paths as $path) { + $path = realpath($path) ?: $path; + + $tbody[] = [ + $ns, + realpath($path) ?: $path, + is_dir($path) ? 'Yes' : 'MISSING', + ]; + } } $thead = [ diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 79cad2ab8d..2ac46fa68f 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -45,7 +45,8 @@ class AutoloadConfig * but this should be done prior to creating any namespaced classes, * else you will need to modify all of those classes for this to work. * - * @var array + * @var array|string> + * @phpstan-var array> */ public $psr4 = [];