Passed
Push — main ( f4d82a...ca2db5 )
by Andrey
03:23 queued 12s
created

Config::resources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Helpers;
21
22
use Helldar\Contracts\LangPublisher\Provider;
23
use Helldar\LaravelLangPublisher\Constants\Config as ConfigConst;
24
use Helldar\LaravelLangPublisher\Exceptions\UnknownPluginInstanceException;
25
use Helldar\Support\Facades\Helpers\Ables\Arrayable;
26
use Helldar\Support\Facades\Helpers\Instance;
27
use Illuminate\Support\Facades\Config as Illuminate;
28
29
class Config
30
{
31 62
    public function vendor(): string
32
    {
33 62
        return $this->getPrivate('path.base');
34
    }
35
36 62
    public function resources(): string
37
    {
38 62
        return $this->getPrivate('path.resources');
39
    }
40
41 62
    public function plugins(): array
42
    {
43 62
        $private = $this->getPrivate('plugins');
44 62
        $public  = $this->getPublic('plugins');
45
46 62
        return Arrayable::of($public)
47 62
            ->addUnique($private)
48 62
            ->unique()
49 62
            ->values()
50 62
            ->map(static function (string $plugin) {
51 62
                if (Instance::of($plugin, Provider::class)) {
52 62
                    return new $plugin();
53
                }
54
55 2
                throw new UnknownPluginInstanceException($plugin);
56 62
            })->get();
57
    }
58
59 62
    public function hasInline(): bool
60
    {
61 62
        return $this->getPublic('inline');
62
    }
63
64 62
    public function hasAlignment(): bool
65
    {
66 62
        return $this->getPublic('alignment');
67
    }
68
69 62
    public function excludes(): array
70
    {
71 62
        return $this->getPublic('excludes');
72
    }
73
74 62
    public function case(): int
75
    {
76 62
        return $this->getPublic('case');
77
    }
78
79 62
    protected function getPrivate(string $key)
80
    {
81 62
        $key = $this->privateKey($key);
82
83 62
        return Illuminate::get($key);
84
    }
85
86 62
    protected function getPublic(string $key)
87
    {
88 62
        $key = $this->publicKey($key);
89
90 62
        return Illuminate::get($key);
91
    }
92
93 62
    protected function privateKey(string $suffix): string
94
    {
95 62
        return ConfigConst::PRIVATE_KEY . '.' . $suffix;
96
    }
97
98 62
    protected function publicKey(string $suffix): string
99
    {
100 62
        return ConfigConst::PUBLIC_KEY . '.' . $suffix;
101
    }
102
}
103