Passed
Pull Request — main (#123)
by Andrey
42:12 queued 26:54
created

Manager::filesystem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
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\Contracts\Support\Filesystem;
23
use Helldar\LaravelLangPublisher\Concerns\Has;
24
use Helldar\LaravelLangPublisher\Concerns\Paths;
25
use Helldar\Support\Concerns\Resolvable;
26
use Helldar\Support\Facades\Helpers\Arr;
27
28
class Manager
29
{
30
    use Has;
31
    use Paths;
32
    use Resolvable;
33
34
    public function load(string $path): array
35
    {
36
        return $this->filesystem($path)->load($path);
37
    }
38
39
    public function store(string $path, array $content): void
40
    {
41
        $this->filesystem($path)->store($path, $content);
42
    }
43
44
    /**
45
     * @param  array|string  $path
46
     */
47
    public function delete($path): void
48
    {
49
        foreach (Arr::wrap($path) as $name) {
50
            $this->filesystem($name)->delete($name);
51
        }
52
    }
53
54
    protected function filesystem(string $path): Filesystem
55
    {
56
        return $this->hasJson($path)
57
            ? static::resolveInstance(Json::class)
58
            : static::resolveInstance(Php::class);
59
    }
60
}
61