Passed
Pull Request — main (#123)
by Andrey
58:14 queued 43:11
created

Json::loadTranslations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Filesystem;
4
5
use Helldar\LaravelLangPublisher\Facades\Path;
6
use Helldar\PrettyArray\Services\File as Pretty;
7
use Helldar\Support\Facades\Helpers\Arr;
8
9
final class Json extends Filesystem
10 28
{
11
    public function load(string $path, string $filename): array
12 28
    {
13
        $this->log('Loading the contents of the file:', $path);
14 28
15 28
        if ($this->doesntExists($path)) {
16
            $this->log('File not found:', $path);
17 28
18
            return [];
19
        }
20 28
21
        dd($path, $filename);
22 28
23
        $keys   = $this->loadKeys($path);
24 28
        $source = $this->loadTranslations($filename);
25
26 28
        return Arr::only($source, $keys);
27
    }
28
29 28
    public function store(string $path, array $content)
30
    {
31 28
        $this->log('Saving an array to a file:', $path);
32
33 28
        Arr::storeAsJson($path, $content, false, JSON_UNESCAPED_UNICODE ^ JSON_PRETTY_PRINT);
34 28
    }
35
36
    protected function loadKeys(string $path): array
37
    {
38
        $this->log('Loading keys from a file:', $path);
39
40
        return $this->loadFile($path);
41
    }
42
43
    protected function loadTranslations(): array
44
    {
45
        dd(
46
            'aaaa',
47
            Path::sourceFull('laravel-lang/lang', 'en', 'en.json'),
48
        );
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
49
        // $this->log('Loading translations from a file:', $path);
50
    }
51
52
    protected function loadFile(string $path): array
53
    {
54
        $this->log('Loading data from a file:', $path);
55
56
        $content = Pretty::make()->loadRaw($path);
57
58
        $items = json_decode($content, true);
59
60
        return $this->correctValues($items);
61
    }
62
}
63