Passed
Pull Request — main (#84)
by Andrey
59:33 queued 44:34
created

Json::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Filesystem;
4
5
use Helldar\PrettyArray\Services\File as Pretty;
6
use Helldar\Support\Facades\Helpers\Arr;
7
8
final class Json extends Filesystem
9
{
10
    public function load(string $path): array
11
    {
12
        if ($this->doesntExists($path)) {
13
            $this->log('File not found: ' . $path);
14
15
            return [];
16
        }
17
18
        $this->log('Loading data from a file: ' . $path);
19
20
        $content = Pretty::make()->loadRaw($path);
21
22
        $items = json_decode($content, true);
23
24
        return $this->correctValues($items);
25
    }
26
27
    public function store(string $path, array $content)
28
    {
29
        $this->log('Saving an array to a file: ' . $path);
30
31
        Arr::storeAsJson($path, $content, false, JSON_UNESCAPED_UNICODE ^ JSON_PRETTY_PRINT);
32
    }
33
}
34