diff --git a/src/LaravelConfigCheckerServiceProvider.php b/src/LaravelConfigCheckerServiceProvider.php index d21d52f..0810b77 100644 --- a/src/LaravelConfigCheckerServiceProvider.php +++ b/src/LaravelConfigCheckerServiceProvider.php @@ -13,8 +13,7 @@ public function configurePackage(Package $package): void $package->name('laravel-config-checker'); if ($this->app->runningInConsole()) { - $package - ->hasCommand(LaravelConfigCheckerCommand::class); + $package->hasCommand(LaravelConfigCheckerCommand::class); } } } diff --git a/src/Support/FileChecker.php b/src/Support/FileChecker.php index 90b3146..ed38112 100644 --- a/src/Support/FileChecker.php +++ b/src/Support/FileChecker.php @@ -31,7 +31,7 @@ public function check(): Collection return collect($issues); } - private function checkForFacadeUsage($content): array + private function checkForFacadeUsage(string $content): array { $matches = []; @@ -56,7 +56,7 @@ private function checkForFacadeUsage($content): array return $issues; } - private function checkForHelperUsage($content): array + private function checkForHelperUsage(string $content): array { $matches = []; diff --git a/src/Support/LoadConfigKeys.php b/src/Support/LoadConfigKeys.php index 0db5335..6341e3d 100644 --- a/src/Support/LoadConfigKeys.php +++ b/src/Support/LoadConfigKeys.php @@ -28,7 +28,7 @@ public function __invoke(): array|Collection return collect($this->configKeys); } - private function flattenConfig($config, $prefix = '') + private function flattenConfig(array $config, string $prefix = '') { foreach ($config as $key => $value) { $fullKey = $prefix ? "{$prefix}.{$key}" : $key; @@ -48,11 +48,21 @@ private function loadConfigKeys() $finder->files()->in($configPath)->name('*.php'); foreach ($finder as $file) { - $this->configKeys[] = basename($file->getFilename(), '.php'); + $relativePath = $file->getRelativePathname(); $config = include $file->getRealPath(); - $this->flattenConfig($config, basename($file->getFilename(), '.php')); + $key = pathinfo($relativePath, PATHINFO_FILENAME); + + $folder = pathinfo($relativePath, PATHINFO_DIRNAME); + + if ($folder !== '.') { + $key = str_replace('/', '.', $folder).'.'.$key; + } + + $this->configKeys[] = $key; + $config = include $file->getRealPath(); + $this->flattenConfig($config, $key); } } } diff --git a/tests/LoadConfigKeysTest.php b/tests/LoadConfigKeysTest.php index 22c02a9..8e52b04 100644 --- a/tests/LoadConfigKeysTest.php +++ b/tests/LoadConfigKeysTest.php @@ -10,6 +10,17 @@ 'app.nested', 'app.nested.key', ]); + + $this->nestedFolderConfigKeys = collect([ + 'app', + 'app.valid_key', + 'app.nested', + 'app.nested.key', + 'settings.inside', + 'settings.inside.inside_subfolder_valid_key', + 'settings.inside.inside_subfolder_nested', + 'settings.inside.inside_subfolder_nested.inside_subfolder_nested_key', + ]); }); it('loads config keys from the config directory', function () { @@ -30,6 +41,16 @@ expect($configKeys->count())->toBeGreaterThan(2); }); +it('loads config keys from the config directory with nested subfolders', function () { + $loadConfigKeys = new LoadConfigKeys(realpath(__DIR__.'/fixtures/subfolders/config')); + + $configKeys = $loadConfigKeys(); + + foreach ($this->nestedFolderConfigKeys as $configKey) { + expect($configKeys)->toContain($configKey); + } +}); + it('returns a collection of config keys', function () { $loadConfigKeys = new LoadConfigKeys(realpath(__DIR__.'/fixtures/base/config')); diff --git a/tests/fixtures/subfolders/app/TestClassOne.php b/tests/fixtures/subfolders/app/TestClassOne.php new file mode 100644 index 0000000..244c283 --- /dev/null +++ b/tests/fixtures/subfolders/app/TestClassOne.php @@ -0,0 +1,15 @@ + 'Laravel Config Checker', + 'nested' => [ + 'key' => 'value', + ], +]; diff --git a/tests/fixtures/subfolders/config/settings/inside.php b/tests/fixtures/subfolders/config/settings/inside.php new file mode 100644 index 0000000..2c88ff3 --- /dev/null +++ b/tests/fixtures/subfolders/config/settings/inside.php @@ -0,0 +1,8 @@ + 'Inside Subfolder Laravel Config Checker', + 'inside_subfolder_nested' => [ + 'inside_subfolder_nested_key' => 'value', + ], +]; diff --git a/tests/fixtures/subfolders/resources/views/test-view-one.blade.php b/tests/fixtures/subfolders/resources/views/test-view-one.blade.php new file mode 100644 index 0000000..c122855 --- /dev/null +++ b/tests/fixtures/subfolders/resources/views/test-view-one.blade.php @@ -0,0 +1,10 @@ +