Passed
Push — main ( 3f2cb1...ed2a6d )
by Andrey
86:25 queued 84:06
created

Remove   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 52
ccs 22
cts 24
cp 0.9167
rs 10
c 1
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteDirectory() 0 13 2
A run() 0 3 2
A deleteFile() 0 13 2
A doesntProtect() 0 5 1
A delete() 0 8 2
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Processors;
4
5
use Helldar\LaravelLangPublisher\Constants\Status;
6
use Helldar\LaravelLangPublisher\Facades\Locales;
7
use Illuminate\Support\Facades\File;
8
9
final class Remove extends Processor
10
{
11 4
    public function run(): string
12
    {
13 4
        return $this->doesntProtect() ? $this->delete() : Status::SKIPPED;
14
    }
15
16 4
    protected function doesntProtect(): bool
17
    {
18 4
        $this->log('Check if the localization is among the protected:', $this->locale);
19
20 4
        return ! Locales::isProtected($this->locale);
21
    }
22
23 3
    protected function delete(): string
24
    {
25 3
        $this->log('Removing json and php localization files:', $this->locale);
26
27 3
        $status_dir  = $this->deleteDirectory($this->locale);
28 3
        $status_file = $this->deleteFile($this->locale);
29
30 3
        return $status_dir === $status_file ? $status_dir : Status::DELETED;
31
    }
32
33 3
    protected function deleteDirectory(string $locale): string
34
    {
35 3
        $this->log('Removing the localization directory for the locale:', $locale);
36
37 3
        $path = $this->pathTarget($locale);
38
39 3
        if (File::exists($path)) {
40 2
            File::deleteDirectory($path);
41
42 2
            return Status::DELETED;
43
        }
44
45 1
        return Status::SKIPPED;
46
    }
47
48 3
    protected function deleteFile(string $locale): string
49
    {
50 3
        $this->log('Removing the json localization file for the locale:', $locale);
51
52 3
        $path = $this->pathTargetFull($locale, null, true);
53
54 3
        if (File::exists($path)) {
55
            File::delete($path);
56
57
            return Status::DELETED;
58
        }
59
60 3
        return Status::SKIPPED;
61
    }
62
}
63