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
|
4 |
|
protected function ran(): void |
21
|
|
|
{ |
22
|
4 |
|
foreach ($this->locales() as $locale) { |
23
|
4 |
|
$this->log('Localization handling: ' . $locale); |
24
|
|
|
|
25
|
4 |
|
$this->validateLocale($locale); |
26
|
|
|
|
27
|
4 |
|
$status = $this->doesntProtect($locale) ? $this->delete($locale) : Status::SKIPPED; |
28
|
|
|
|
29
|
4 |
|
$this->processed($locale, $locale, $status); |
30
|
|
|
} |
31
|
4 |
|
} |
32
|
|
|
|
33
|
3 |
|
protected function delete(string $locale): string |
34
|
|
|
{ |
35
|
3 |
|
$status_dir = $this->deleteDirectory($locale); |
36
|
3 |
|
$status_file = $this->deleteFile($locale); |
37
|
|
|
|
38
|
3 |
|
return $status_dir === $status_file ? $status_dir : Status::DELETED; |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
protected function deleteDirectory(string $locale): string |
42
|
|
|
{ |
43
|
3 |
|
$this->log('Removing the localization directory for the locale: ' . $locale); |
44
|
|
|
|
45
|
3 |
|
$path = Path::target($locale); |
46
|
|
|
|
47
|
3 |
|
if (File::exists($path)) { |
48
|
2 |
|
File::deleteDirectory($path); |
49
|
|
|
|
50
|
2 |
|
return Status::DELETED; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
return Status::SKIPPED; |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
protected function deleteFile(string $locale): string |
57
|
|
|
{ |
58
|
3 |
|
$this->log('Removing the json localization file for the locale: ' . $locale); |
59
|
|
|
|
60
|
3 |
|
$path = Path::targetFull($locale, null, true); |
61
|
|
|
|
62
|
3 |
|
if (File::exists($path)) { |
63
|
|
|
File::delete($path); |
64
|
|
|
|
65
|
|
|
return Status::DELETED; |
66
|
|
|
} |
67
|
|
|
|
68
|
3 |
|
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: