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

Config::publicKey()   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 1
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
            ->tap(static function (string $plugin) {
50
                if (! Instance::of($plugin, Provider::class)) {
51
                    throw new UnknownPluginInstanceException($plugin);
52
                }
53
            })
54
            ->sort()
55
            ->get();
56
    }
57
58
    public function hasInline(): bool
59
    {
60
        return $this->getPublic('inline');
61
    }
62
63
    public function hasAlignment(): bool
64
    {
65
        return $this->getPublic('alignment');
66
    }
67
68
    public function excludes(): array
69
    {
70
        return $this->getPublic('excludes');
71
    }
72
73
    public function case(): int
74
    {
75
        return $this->getPublic('case');
76
    }
77
78
    protected function getPrivate(string $key)
79
    {
80
        $key = $this->privateKey($key);
81
82
        return Illuminate::get($key);
83
    }
84
85
    protected function getPublic(string $key)
86
    {
87
        $key = $this->publicKey($key);
88
89
        return Illuminate::get($key);
90
    }
91
92
    protected function privateKey(string $suffix): string
93
    {
94
        return ConfigConst::PRIVATE_KEY . '.' . $suffix;
95
    }
96
97
    protected function publicKey(string $suffix): string
98
    {
99
        return ConfigConst::PUBLIC_KEY . '.' . $suffix;
100
    }
101
}
102