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

Filesystem::ensureKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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