Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed getting a list of available locales in lang:remove command calling #342

Merged
merged 1 commit into from
Nov 2, 2023
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
17 changes: 8 additions & 9 deletions src/Console/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
6 changes: 3 additions & 3 deletions src/Console/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}
29 changes: 15 additions & 14 deletions src/Console/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}