Passed
Push — 10.x ( 0db173...bfcd3c )
by Andrey
10:43
created

Json::correct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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\PrettyArray\Services\File as Pretty;
23
use Helldar\Support\Facades\Helpers\Arr;
24
25
class Json extends Base
26
{
27
    public function load(string $path): array
28
    {
29
        if ($this->doesntExists($path)) {
30
            return [];
31
        }
32
33
        $content = Pretty::make()->loadRaw($path);
34
35
        $items = json_decode($content, true);
36
37
        return $this->correct($items);
38
    }
39
40
    public function store(string $path, $content): string
41
    {
42
        Arr::storeAsJson($path, $content, false, JSON_UNESCAPED_UNICODE ^ JSON_PRETTY_PRINT);
43
44
        return $path;
45
    }
46
}
47