Passed
Pull Request — master (#38)
by Ondra
05:21 queued 01:24
created

SignerConfigProvider::setDefaultGateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Pixidos package.
5
 *
6
 *  (c) Ondra Votava <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 *
11
 */
12
13
declare(strict_types=1);
14
15
namespace Pixidos\GPWebPay\Config;
16
17
use Pixidos\GPWebPay\Exceptions\InvalidArgumentException;
18
19
class SignerConfigProvider
20
{
21
    /**
22
     * @var array<SignerConfig>
23
     */
24
    private array $configs = [];
25
26
    private string $defaultGateway = 'default';
27
28
    public function addConfig(SignerConfig $config, string $gateway = 'default'): void
29
    {
30
        $this->configs[$gateway] = $config;
31
    }
32
33
    public function getConfig(string|null $gateway = null): SignerConfig
34
    {
35
        if (null === $gateway) {
36
            $gateway = $this->defaultGateway;
37
        }
38
        if (array_key_exists($gateway, $this->configs)) {
39
            return $this->configs[$gateway];
40
        }
41
42
        throw new InvalidArgumentException(
43
            sprintf('Config for gateway "%s" does not exist. You are probably forgot added or you wrong set default config.', $gateway)
44
        );
45
    }
46
47
    public function setDefaultGateway(string $gateway): void
48
    {
49
        $this->defaultGateway = $gateway;
50
    }
51
52
    public function getDefaultGateway(): string
53
    {
54
        return $this->defaultGateway;
55
    }
56
}
57