Skip to content

Commit 2f72a4a

Browse files
committed
Fixed ignore_files to work with relative paths
1 parent 2e6fd61 commit 2f72a4a

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

config/env-keys-checker.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
declare(strict_types=1);
44

55
return [
6-
// List of all the .env files to ignore while checking the env keys
6+
// List of .env files to ignore while checking (relative paths from project root)
7+
// Examples: '.env.backup' (root only), 'storage/envs/.env.old' (specific path)
78
'ignore_files' => explode(',', (string) env('KEYS_CHECKER_IGNORE_FILES', '')),
89

910
// List of all the env keys to ignore while checking the env keys

src/Actions/FilterFiles.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
namespace Msamgan\LaravelEnvKeysChecker\Actions;
66

7+
use Msamgan\LaravelEnvKeysChecker\Concerns\HelperFunctions;
8+
79
final class FilterFiles
810
{
11+
use HelperFunctions;
12+
913
public function handle(array $envFiles, array $ignoredFiles): array
1014
{
1115
return collect(value: $envFiles)
12-
->reject(callback: fn ($file): bool => in_array(needle: basename((string) $file), haystack: $ignoredFiles))
16+
->reject(callback: fn ($file): bool => in_array(needle: $this->getRelativePath((string) $file), haystack: $ignoredFiles))
1317
->reject(callback: fn ($file): bool => str_ends_with(haystack: basename((string) $file), needle: '.encrypted'))
1418
->toArray();
1519
}

src/Commands/KeysCheckerCommand.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,4 @@ private function showMissingKeysTable(Collection $missingKeys): void
124124
])->toArray()
125125
);
126126
}
127-
128-
private function getRelativePath(string $path): string
129-
{
130-
$basePath = base_path();
131-
if (str_starts_with($path, $basePath)) {
132-
return mb_substr($path, mb_strlen($basePath) + 1);
133-
}
134-
135-
return basename($path);
136-
}
137127
}

src/Concerns/HelperFunctions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ private function getAdditionalEnvLocations(): array
5858

5959
return array_unique($envFiles);
6060
}
61+
62+
private function getRelativePath(string $path): string
63+
{
64+
$basePath = base_path();
65+
if (str_starts_with($path, $basePath)) {
66+
return mb_substr($path, mb_strlen($basePath) + 1);
67+
}
68+
69+
return basename($path);
70+
}
6171
}

0 commit comments

Comments
 (0)