Passed
Pull Request — main (#123)
by Andrey
26:46 queued 11:34
created

Filesystem   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A doesntExists() 0 5 1
A ensureKeys() 0 7 1
A correctValues() 0 12 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Filesystem;
4
5
use Helldar\LaravelLangPublisher\Concerns\Logger;
6
use Helldar\LaravelLangPublisher\Contracts\Filesystem as Contract;
7
use Helldar\Support\Facades\Helpers\Ables\Arrayable;
8
use Helldar\Support\Facades\Helpers\Filesystem\File;
9
10
abstract class Filesystem implements Contract
11
{
12
    use Logger;
0 ignored issues
show
Bug introduced by
The trait Helldar\LaravelLangPublisher\Concerns\Logger requires the property $output which is not provided by Helldar\LaravelLangPubli...s\Filesystem\Filesystem.
Loading history...
13
14 28
    public function ensureKeys(string $path): void
15
    {
16 28
        $this->log('Ensure array keys exist for a file', $path);
17
18 28
        $content = $this->load($path);
19 28
20 28
        $this->store($path, $content);
21
    }
22 28
23 28
    protected function correctValues(array $items): array
24 28
    {
25 28
        $this->log('Correcting array values...');
26
27
        $callback = static function ($value) {
28 28
            return stripslashes($value);
29
        };
30 28
31
        return Arrayable::of($items)
32 28
            ->map($callback, true)
33
            ->renameKeys($callback)
34
            ->get();
35
    }
36
37
    protected function doesntExists(string $path): bool
38
    {
39
        $this->log('Checking for the existence of a path:', $path);
40
41
        return ! File::exists($path);
42
    }
43
}
44