Passed
Pull Request — main (#96)
by Andrey
79:05 queued 64:02
created

Php   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 56
ccs 25
cts 25
cp 1
rs 10
c 2
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 13 2
A setFormatterCase() 0 5 1
A isAlignment() 0 3 1
A setFormatterAlignment() 0 6 2
A store() 0 11 1
A setFormatterKeyToString() 0 5 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Filesystem;
4
5
use Helldar\LaravelLangPublisher\Facades\Config;
6
use Helldar\PrettyArray\Services\File as Pretty;
7
use Helldar\PrettyArray\Services\Formatter;
8
9
final class Php extends Filesystem
10
{
11 11
    public function load(string $path): array
12
    {
13 11
        if ($this->doesntExists($path)) {
14 5
            $this->log('File not found: ' . $path);
15
16 5
            return [];
17
        }
18
19 11
        $this->log('Loading data from a file: ' . $path);
20
21 11
        $items = Pretty::make()->load($path);
22
23 11
        return $this->correctValues($items);
24
    }
25
26 11
    public function store(string $path, array $content)
27
    {
28 11
        $this->log('Saving an array to a file: ' . $path);
29
30 11
        $service = Formatter::make();
31
32 11
        $this->setFormatterCase($service);
33 11
        $this->setFormatterAlignment($service);
34
        $this->setFormatterKeyToString($service);
35 11
36 11
        Pretty::make($service->raw($content))->store($path);
37
    }
38 11
39
    protected function isAlignment(): bool
40 11
    {
41
        return Config::hasAlignment();
42
    }
43 11
44
    protected function setFormatterCase(Formatter $formatter): void
45 11
    {
46
        $this->log('Setting the key conversion label.');
47 11
48 11
        $formatter->setCase(Config::getCase());
49
    }
50 11
51
    protected function setFormatterAlignment(Formatter $formatter): void
52 11
    {
53
        $this->log('Setting the alignment label of values.');
54 11
55 11
        if ($this->isAlignment()) {
56
            $formatter->setEqualsAlign();
57 11
        }
58
    }
59
60
    protected function setFormatterKeyToString(Formatter $formatter): void
61
    {
62
        $this->log('Setting the label for converting numeric keys to string...');
63
64
        $formatter->setKeyAsString();
65
    }
66
}
67