Passed
Pull Request — main (#123)
by Andrey
29:01 queued 13:53
created

Php::setAlignment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the "andrey-helldar/laravel-lang-publisher" project.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @author Andrey Helldar <[email protected]>
10
 *
11
 * @copyright 2021 Andrey Helldar
12
 *
13
 * @license MIT
14
 *
15
 * @see https://github.com/andrey-helldar/laravel-lang-publisher
16
 */
17
18
declare(strict_types=1);
19
20
namespace Helldar\LaravelLangPublisher\Support\Filesystem;
21
22
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
23
use Helldar\PrettyArray\Services\File as Pretty;
24
use Helldar\PrettyArray\Services\Formatter;
25
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
26
27
class Php extends Base
28
{
29
    public function load(string $path)
30
    {
31
        if ($this->doesntExists($path)) {
32
            return [];
33
        }
34
35
        $items = Pretty::make()->load($path);
36
37
        return $this->correct($items);
38
    }
39
40
    public function store(string $path, $content): string
41
    {
42
        $service = $this->formatter();
43
44
        Pretty::make($service->raw($content))->store($path);
45
46
        return $path;
47
    }
48
49
    public function delete(string $path): void
50
    {
51
        Directory::ensureDelete($path);
52
    }
53
54
    protected function formatter(): Formatter
55
    {
56
        $formatter = Formatter::make();
57
58
        $this->setCase($formatter);
59
        $this->setAlignment($formatter);
60
        $this->setKeyToString($formatter);
61
62
        return $formatter;
63
    }
64
65
    protected function setCase(Formatter $formatter): void
66
    {
67
        $formatter->setCase(
68
            $this->getCase()
69
        );
70
    }
71
72
    protected function setAlignment(Formatter $formatter): void
73
    {
74
        if ($this->hasAlignment()) {
75
            $formatter->setEqualsAlign();
76
        }
77
    }
78
79
    protected function setKeyToString(Formatter $formatter): void
80
    {
81
        $formatter->setKeyAsString();
82
    }
83
84
    protected function getCase(): int
85
    {
86
        return Config::case();
87
    }
88
89
    protected function hasAlignment(): bool
90
    {
91
        return Config::hasAlignment();
92
    }
93
}
94