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

Remove::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
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