Skip to content

Commit

Permalink
Revert "Attempt druc#2 to exclude a path."
Browse files Browse the repository at this point in the history
This reverts commit fe90d14.
  • Loading branch information
fszotyi committed Mar 18, 2024
1 parent 0d9b9c7 commit ab7a975
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Commands/LangscannerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class LangscannerCommand extends Command
{
protected $signature = 'langscanner {language?} {--path= : The path to scan for translation keys (ex: --path=app/Modules/Module1 )} {--exclude-path= : Directory to exclude from the scan (ex: --exclude-path=app/Modules/) }';
protected $signature = 'langscanner {language?} {--path= : The path to scan for translation keys (ex: --path=app/Modules/Module1 )} {--exclude-path=* : Directories to exclude from the scan (ex: --exclude-path=app/Modules/) }';
protected $description = "Updates translation files with missing translation keys.";

public function handle(Filesystem $filesystem): void
Expand Down
26 changes: 4 additions & 22 deletions src/RequiredTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Webmozart\Assert\Assert;

class RequiredTranslations
Expand Down Expand Up @@ -56,32 +57,13 @@ public function all(): array

private function files(): array
{
$allFiles = $this->disk->allFiles($this->paths);
$files = $this->disk->allFiles($this->paths);

$excludedPathsAbsolute = array_map(function ($path) {
return realpath($path) ?: $path;
}, $this->excludedPaths);

return Collection::make($allFiles)
->filter(function ($file) use ($excludedPathsAbsolute) {
$filePath = realpath($file->getPathName());

foreach ($excludedPathsAbsolute as $excludedPath) {
if ($this->startsWith($filePath, $excludedPath)) {
return false;
}
}

return true;
})
return Collection::make($files)
->filter(fn ($file) => !Str::startsWith($file->getPathName(), $this->excludedPaths))
->toArray();
}

private function startsWith($haystack, $needle): bool
{
return strncmp($haystack, $needle, strlen($needle)) === 0;
}

private function existingPhpTranslations(): array
{
return Collection::make($this->disk->allFiles($this->langDirPath))
Expand Down

0 comments on commit ab7a975

Please sign in to comment.