Passed
Push — master ( 8f82d1...61929e )
by Ondra
02:08 queued 57s
created

SignerConfigProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addConfig() 0 3 1
A getDefaultGateway() 0 3 1
A getConfig() 0 11 3
A setDefaultGateway() 0 3 1
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