Config::excludeBodyConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Joesama\Webhook\Web;
4
5
use GuzzleHttp\RequestOptions;
6
use Illuminate\Support\Collection;
7
8
class Config
9
{
10
    /**
11
     * Default webhook config directory.
12
     */
13
    public const CONF_DIR = 'webhooks.';
14
15
    /**
16
     * Default webhook request key.
17
     */
18
    public const REQUEST_URI = 'request';
19
20
    /**
21
     * Http configuration parameters.
22
     *
23
     * @var array
24
     */
25
    public array $configs;
26
27
    /**
28
     * WebHook configuration parameters.
29
     *
30
     * @var array
31
     */
32
    public array $hooks;
33
34
    /**
35
     * Configuration parameters.
36
     *
37
     * @var Collection
38
     */
39
    private Collection $configurable;
40 3
41
    public function __construct($config)
42 3
    {
43
        if (is_string($config)) {
44 3
            $config = config($config, config(self::CONF_DIR . $config, []));
45 2
        }
46 2
47
        $this->configurable = new Collection($config);
48
49 1
        $this->configs = $this->excludeBodyConfig();
50
51
        $this->hooks = $this->configurable->get(self::REQUEST_URI, []);
52 2
    }
53 2
54
    /**
55
     * Exclude configurable from body
56
     */
57
    protected function excludeBodyConfig(): array
58
    {
59
        return $this->configurable->except([
60
            RequestOptions::BODY,
61 1
            RequestOptions::FORM_PARAMS,
62
            RequestOptions::JSON,
63 1
            RequestOptions::MULTIPART,
64
            RequestOptions::QUERY,
65 1
            self::REQUEST_URI,
66 1
        ])->toArray();
67
    }
68
69
    /**
70
     * Provide configuration parameter as array.
71
     *
72
     * @return array
73 2
     */
74
    public function toArray(): array
75 2
    {
76 2
        return $this->configurable->toArray();
77 2
    }
78
}
79