Passed
Pull Request — master (#57)
by Andrey
13:11
created

DeleteJson   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 35
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isProtected() 0 3 1
A delete() 0 5 2
A path() 0 3 1
A checkExists() 0 3 1
A run() 0 9 2
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Processing;
4
5
use Helldar\LaravelLangPublisher\Constants\Status;
6
use Helldar\LaravelLangPublisher\Facades\File;
7
use Helldar\LaravelLangPublisher\Facades\Locale;
8
use Helldar\LaravelLangPublisher\Facades\Path;
9
use Illuminate\Support\Facades\File as IlluminateFile;
10
11
final class DeleteJson extends BaseProcess
12
{
13
    protected $extension = '.json';
14
15
    public function run(): array
16
    {
17
        $this->checkExists($this->path());
18
19
        $this->delete()
20
            ? $this->push($this->locale, Status::DELETED)
21
            : $this->push($this->locale, Status::SKIPPED);
22
23
        return $this->result();
24
    }
25
26
    protected function delete(): bool
27
    {
28
        return ! $this->isProtected()
29
            ? IlluminateFile::delete($this->path())
30
            : false;
31
    }
32
33
    protected function path(): string
34
    {
35
        return Path::target($this->locale . $this->extension);
36
    }
37
38
    protected function isProtected(): bool
39
    {
40
        return Locale::isProtected($this->locale);
41
    }
42
43
    protected function checkExists(string $path): void
44
    {
45
        File::exists($path);
46
    }
47
}
48