Passed
Push — main ( 9ad958...bccbba )
by Andrey
72:16 queued 69:33
created

Remove   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 89.66%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 68
ccs 26
cts 29
cp 0.8966
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ran() 0 14 3
A processor() 0 2 1
A delete() 0 8 2
A deleteDirectory() 0 13 2
A deleteFile() 0 13 2
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
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Helldar\LaravelLangPublisher\Contracts\Processor. Consider adding a return statement or allowing null as return value.

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:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
79
}
80