diff --git a/src/Console/Add.php b/src/Console/Add.php index cede1b72..4092e723 100644 --- a/src/Console/Add.php +++ b/src/Console/Add.php @@ -17,6 +17,7 @@ namespace LaravelLang\Publisher\Console; +use LaravelLang\Locales\Enums\Locale; use LaravelLang\Locales\Facades\Locales; use LaravelLang\Publisher\Exceptions\UnknownLocaleCodeException; use LaravelLang\Publisher\Processors\Add as AddProcessor; @@ -38,14 +39,12 @@ protected function locales(): array return Locales::raw()->available(); } - $locales = $this->getLocalesArgument(); - - foreach ($locales as $locale) { - if (! Locales::isAvailable($locale)) { - throw new UnknownLocaleCodeException($locale); - } - } - - return $locales; + return $this->getLocalesArgument() + ->each(function (Locale|string $locale) { + if (! Locales::isAvailable($locale)) { + throw new UnknownLocaleCodeException($locale); + } + }) + ->all(); } } diff --git a/src/Console/Base.php b/src/Console/Base.php index 9b834ac4..d9e809d9 100644 --- a/src/Console/Base.php +++ b/src/Console/Base.php @@ -18,7 +18,7 @@ namespace LaravelLang\Publisher\Console; use Illuminate\Console\Command; -use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use LaravelLang\Locales\Facades\Locales; use LaravelLang\Publisher\Contracts\TextDecorator; use LaravelLang\Publisher\Helpers\Config; @@ -70,8 +70,8 @@ protected function confirmAll(): bool return false; } - protected function getLocalesArgument(): array + protected function getLocalesArgument(): Collection { - return Arr::wrap($this->argument('locales')); + return collect($this->argument('locales')); } } diff --git a/src/Console/Remove.php b/src/Console/Remove.php index fd3a72a9..c926c6f9 100644 --- a/src/Console/Remove.php +++ b/src/Console/Remove.php @@ -17,6 +17,7 @@ namespace LaravelLang\Publisher\Console; +use LaravelLang\Locales\Enums\Locale; use LaravelLang\Locales\Facades\Locales; use LaravelLang\Publisher\Exceptions\ProtectedLocaleException; use LaravelLang\Publisher\Exceptions\UnknownLocaleCodeException; @@ -36,21 +37,21 @@ class Remove extends Base protected function locales(): array { if ($this->confirmAll()) { - return Locales::raw()->installed(false); + return Locales::raw()->installed( + $this->option('force') + ); } - $locales = $this->getLocalesArgument(); - - foreach ($locales as $locale) { - if (! Locales::isAvailable($locale)) { - throw new UnknownLocaleCodeException($locale); - } - - if (Locales::isProtected($locale) && ! $this->option('force')) { - throw new ProtectedLocaleException($locale); - } - } - - return $locales; + return $this->getLocalesArgument() + ->each(function (Locale|string $locale) { + if (! Locales::isAvailable($locale)) { + throw new UnknownLocaleCodeException($locale); + } + + if (Locales::isProtected($locale) && ! $this->option('force')) { + throw new ProtectedLocaleException($locale); + } + }) + ->all(); } }