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

Uninstall   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 49
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteDirectory() 0 8 2
A deleted() 0 3 1
A skipped() 0 5 1
A delete() 0 6 2
A doesntProtect() 0 3 1
A run() 0 10 3
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