Passed
Push — 9.x ( 571ce0...ec3d6f )
by Andrey
11:20
created

Php::setFormatterAlignment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
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
    public function load(string $path): array
12
    {
13
        if ($this->doesntExists($path)) {
14
            $this->log('File not found: ' . $path);
15
16
            return [];
17
        }
18
19
        $this->log('Loading data from a file: ' . $path);
20
21
        $items = Pretty::make()->load($path);
22
23
        return $this->correctValues($items);
24
    }
25
26
    public function store(string $path, array $content)
27
    {
28
        $this->log('Saving an array to a file: ' . $path);
29
30
        $service = Formatter::make();
31
32
        $this->setFormatterCase($service);
33
        $this->setFormatterAlignment($service);
34
        $this->setFormatterKeyToString($service);
35
36
        Pretty::make($service->raw($content))->store($path);
37
    }
38
39
    protected function isAlignment(): bool
40
    {
41
        return Config::hasAlignment();
42
    }
43
44
    protected function setFormatterCase(Formatter $formatter): void
45
    {
46
        $this->log('Setting the key conversion label.');
47
48
        $formatter->setCase(Config::getCase());
49
    }
50
51
    protected function setFormatterAlignment(Formatter $formatter): void
52
    {
53
        $this->log('Setting the alignment label of values.');
54
55
        if ($this->isAlignment()) {
56
            $formatter->setEqualsAlign();
57
        }
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