Passed
Pull Request — main (#123)
by Andrey
27:30 queued 12:28
created

Config::vendor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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