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

Json   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 5 1
A load() 0 15 2
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