|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Constants\Status; |
|
6
|
|
|
use Helldar\LaravelLangPublisher\Contracts\Processor; |
|
7
|
|
|
use Helldar\LaravelLangPublisher\Facades\Path; |
|
8
|
|
|
use Helldar\LaravelLangPublisher\Support\Actions\Remove as Action; |
|
9
|
|
|
use Illuminate\Support\Facades\File; |
|
10
|
|
|
|
|
11
|
|
|
final class Remove extends BaseCommand |
|
12
|
|
|
{ |
|
13
|
|
|
protected $signature = 'lang:rm' |
|
14
|
|
|
. ' {locales?* : Space-separated list of, eg: de tk it}'; |
|
15
|
|
|
|
|
16
|
|
|
protected $description = 'Remove localizations.'; |
|
17
|
|
|
|
|
18
|
|
|
protected $action = Action::class; |
|
19
|
|
|
|
|
20
|
|
|
protected function ran(): void |
|
21
|
|
|
{ |
|
22
|
|
|
foreach ($this->locales() as $locale) { |
|
23
|
|
|
$this->log('Localization handling: ' . $locale); |
|
24
|
|
|
|
|
25
|
|
|
$this->validateLocale($locale); |
|
26
|
|
|
|
|
27
|
|
|
$status = $this->doesntProtect($locale) ? $this->delete($locale) : Status::SKIPPED; |
|
28
|
|
|
|
|
29
|
|
|
$this->processed($locale, $status); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function delete(string $locale): string |
|
34
|
|
|
{ |
|
35
|
|
|
$status_dir = $this->deleteDirectory($locale); |
|
36
|
|
|
$status_file = $this->deleteFile($locale); |
|
37
|
|
|
|
|
38
|
|
|
return $status_dir === $status_file ? $status_dir : Status::DELETED; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function deleteDirectory(string $locale): string |
|
42
|
|
|
{ |
|
43
|
|
|
$this->log('Removing the localization directory for the locale: ' . $locale); |
|
44
|
|
|
|
|
45
|
|
|
$path = Path::target($locale); |
|
46
|
|
|
|
|
47
|
|
|
if (File::exists($path)) { |
|
48
|
|
|
File::deleteDirectory($path); |
|
49
|
|
|
|
|
50
|
|
|
return Status::DELETED; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return Status::SKIPPED; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function deleteFile(string $locale): string |
|
57
|
|
|
{ |
|
58
|
|
|
$this->log('Removing the json localization file for the locale: ' . $locale); |
|
59
|
|
|
|
|
60
|
|
|
$path = Path::targetFull($locale, null, true); |
|
61
|
|
|
|
|
62
|
|
|
if (File::exists($path)) { |
|
63
|
|
|
File::delete($path); |
|
64
|
|
|
|
|
65
|
|
|
return Status::DELETED; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return Status::SKIPPED; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function processor(): Processor |
|
72
|
|
|
{ |
|
73
|
|
|
} |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: