Passed
Pull Request — main (#123)
by Andrey
26:46 queued 11:34
created

Manager::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

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
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services\Filesystem;
4
5
use Helldar\LaravelLangPublisher\Concerns\Containable;
6
use Helldar\LaravelLangPublisher\Concerns\Contains;
7
use Helldar\LaravelLangPublisher\Concerns\Logger;
8
use Helldar\LaravelLangPublisher\Contracts\Filesystem as Contract;
9
10
final class Manager implements Contract
11
{
12
    use Containable;
13
    use Contains;
14
    use Logger;
0 ignored issues
show
Bug introduced by
The trait Helldar\LaravelLangPublisher\Concerns\Logger requires the property $output which is not provided by Helldar\LaravelLangPubli...ices\Filesystem\Manager.
Loading history...
15
16 28
    public function load(string $path, string $main_path = null): array
17
    {
18 28
        $this->log('Loading data from an array:', $path, $main_path);
19
20 28
        return $this->filesystem($path)->load($path, $main_path);
21
    }
22
23 28
    public function store(string $path, array $content)
24
    {
25 28
        $this->log('Saving an array to a file:', $path);
26
27 28
        return $this->filesystem($path)->store($path, $content);
28
    }
29
30 28
    public function ensureKeys(string $path): void
31
    {
32 28
        $content = $this->load($path);
33
34 28
        $this->store($path, $content);
35 28
    }
36 28
37
    protected function filesystem(string $path): Contract
38
    {
39
        $this->log('Getting an object for working with files by the path:', $path);
40
41
        return $this->isJson($path)
42
            ? $this->container(Json::class)
43
            : $this->container(Php::class);
44
    }
45
}
46