Passed
Pull Request — main (#84)
by Andrey
196:26 queued 181:26
created

Php::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
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->setCase($service);
33
        $this->setAlignment($service);
34
35
        Pretty::make($service->raw($content))->store($path);
36
    }
37
38
    protected function isAlignment(): bool
39
    {
40
        return Config::hasAlignment();
41
    }
42
43
    protected function setCase(Formatter $formatter): void
44
    {
45
        $this->log('Setting the key conversion label.');
46
47
        $formatter->setCase(Config::getCase());
48
    }
49
50
    protected function setAlignment(Formatter $formatter): void
51
    {
52
        $this->log('Setting the alignment label of values.');
53
54
        if ($this->isAlignment()) {
55
            $formatter->setEqualsAlign();
56
        }
57
    }
58
}
59