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
3 changes: 1 addition & 2 deletions src/LaravelConfigCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/Support/FileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function check(): Collection
return collect($issues);
}

private function checkForFacadeUsage($content): array
private function checkForFacadeUsage(string $content): array
{
$matches = [];

Expand All @@ -56,7 +56,7 @@ private function checkForFacadeUsage($content): array
return $issues;
}

private function checkForHelperUsage($content): array
private function checkForHelperUsage(string $content): array
{
$matches = [];

Expand Down
16 changes: 13 additions & 3 deletions src/Support/LoadConfigKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
21 changes: 21 additions & 0 deletions tests/LoadConfigKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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'));

Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/subfolders/app/TestClassOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ChrisDiCarlo\LaravelConfigChecker\Tests\fixtures\app;

use Illuminate\Support\Facades\Config;

class TestClassOne
{
public function __construct()
{
config('app.invalid_key');
Config::get('app.invalid_key');
Config::has('app.invalid_key');
}
}
15 changes: 15 additions & 0 deletions tests/fixtures/subfolders/app/TestClassTwo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ChrisDiCarlo\LaravelConfigChecker\Tests\fixtures\app;

use Illuminate\Support\Facades\Config;

class TestClassTwo
{
public function __construct()
{
config('app.invalid_key');
Config::get('app.invalid_key');
Config::has('app.invalid_key');
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/subfolders/config/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'valid_key' => 'Laravel Config Checker',
'nested' => [
'key' => 'value',
],
];
8 changes: 8 additions & 0 deletions tests/fixtures/subfolders/config/settings/inside.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'inside_subfolder_valid_key' => 'Inside Subfolder Laravel Config Checker',
'inside_subfolder_nested' => [
'inside_subfolder_nested_key' => 'value',
],
];
10 changes: 10 additions & 0 deletions tests/fixtures/subfolders/resources/views/test-view-one.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<h1>Test View One</h1>
{{ config('app.invalid_key') }}
{{ Config::get('app.invalid_key') }}
{{ Config::has('app.invalid_key') }}

{{ config('app.valid_key') }}
{{ Config::get('app.valid_key') }}
{{ Config::has('app.valid_key') }}
</div>
10 changes: 10 additions & 0 deletions tests/fixtures/subfolders/resources/views/test-view-two.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<h1>Test View Two</h1>
{{ config('app.invalid_key') }}
{{ Config::get('app.invalid_key') }}
{{ Config::has('app.invalid_key') }}

{{ config('app.valid_key') }}
{{ Config::get('app.valid_key') }}
{{ Config::has('app.valid_key') }}
</div>