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\Support\Actions\Remove as Action; |
8
|
|
|
use Illuminate\Support\Facades\File; |
9
|
|
|
|
10
|
|
|
final class Remove extends BaseCommand |
11
|
|
|
{ |
12
|
|
|
protected $signature = 'lang:rm' |
13
|
|
|
. ' {locales?* : Space-separated list of, eg: de tk it}'; |
14
|
|
|
|
15
|
|
|
protected $description = 'Remove localizations.'; |
16
|
|
|
|
17
|
|
|
protected $action = Action::class; |
18
|
|
|
|
19
|
4 |
|
protected function ran(): void |
20
|
|
|
{ |
21
|
4 |
|
$this->log('Starting processing of the locales list...'); |
22
|
|
|
|
23
|
4 |
|
foreach ($this->locales() as $locale) { |
24
|
4 |
|
$this->log('Localization handling: ' . $locale); |
25
|
|
|
|
26
|
4 |
|
$this->validateLocale($locale); |
27
|
|
|
|
28
|
4 |
|
$this->processing($locale, $locale); |
29
|
|
|
|
30
|
4 |
|
$status = $this->doesntProtect($locale) ? $this->delete($locale) : Status::SKIPPED; |
31
|
|
|
|
32
|
4 |
|
$this->processed($locale, $locale, $status); |
33
|
|
|
} |
34
|
4 |
|
} |
35
|
|
|
|
36
|
3 |
|
protected function delete(string $locale): string |
37
|
|
|
{ |
38
|
3 |
|
$this->log('Removing json and php localization files:', $locale); |
39
|
|
|
|
40
|
3 |
|
$status_dir = $this->deleteDirectory($locale); |
41
|
3 |
|
$status_file = $this->deleteFile($locale); |
42
|
|
|
|
43
|
3 |
|
return $status_dir === $status_file ? $status_dir : Status::DELETED; |
44
|
|
|
} |
45
|
|
|
|
46
|
3 |
|
protected function deleteDirectory(string $locale): string |
47
|
|
|
{ |
48
|
3 |
|
$this->log('Removing the localization directory for the locale:', $locale); |
49
|
|
|
|
50
|
3 |
|
$path = $this->pathTarget($locale); |
51
|
|
|
|
52
|
3 |
|
if (File::exists($path)) { |
53
|
2 |
|
File::deleteDirectory($path); |
54
|
|
|
|
55
|
2 |
|
return Status::DELETED; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
return Status::SKIPPED; |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
protected function deleteFile(string $locale): string |
62
|
|
|
{ |
63
|
3 |
|
$this->log('Removing the json localization file for the locale:', $locale); |
64
|
|
|
|
65
|
3 |
|
$path = $this->pathTargetFull($locale, null, true); |
66
|
|
|
|
67
|
3 |
|
if (File::exists($path)) { |
68
|
|
|
File::delete($path); |
69
|
|
|
|
70
|
|
|
return Status::DELETED; |
71
|
|
|
} |
72
|
|
|
|
73
|
3 |
|
return Status::SKIPPED; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function processor(): Processor |
77
|
|
|
{ |
78
|
|
|
} |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
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: