Passed
Pull Request — main (#84)
by Andrey
49:37 queued 34:36
created

Uninstall::deleted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Processors;
4
5
use Helldar\LaravelLangPublisher\Constants\Status;
6
use Helldar\LaravelLangPublisher\Facades\Locales;
7
use Helldar\LaravelLangPublisher\Facades\Path;
8
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
9
use Helldar\Support\Facades\Helpers\Filesystem\File;
10
11
final class Uninstall extends Processor
12
{
13
    public function run(): string
14
    {
15
        if ($this->exists() && $this->doesntProtect()) {
16
            $this->delete();
17
            $this->deleteDirectory();
18
19
            return $this->deleted();
20
        }
21
22
        return $this->skipped();
23
    }
24
25
    protected function delete(): void
26
    {
27
        $this->log('Deleting a file: ' . $this->target_path);
28
29
        if (File::exists($this->target_path)) {
30
            File::delete($this->target_path);
31
        }
32
    }
33
34
    protected function deleteDirectory(): void
35
    {
36
        $this->log('Removing the "lang/' . $this->locale . '" directory if it empty.');
37
38
        $path = Path::target($this->locale);
39
40
        if (! File::names($path)) {
41
            Directory::delete($path);
42
        }
43
    }
44
45
    protected function deleted(): string
46
    {
47
        return Status::DELETED;
48
    }
49
50
    protected function skipped(): string
51
    {
52
        $this->log('Skipping file processing: ' . $this->target_path);
53
54
        return Status::SKIPPED;
55
    }
56
57
    protected function doesntProtect(): bool
58
    {
59
        return ! Locales::isProtected($this->locale);
60
    }
61
}
62