Passed
Push — master ( 5b31c8...ce99ce )
by AHMED JOHARI
02:52
created

Config::excludeConfigurable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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