Passed
Push — main ( 55f929...127e84 )
by Andrey
161:41 queued 158:10
created

Remove::deleteFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 10
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
    }
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...
74
}
75