Total Complexity | 6 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | class SignerConfigProvider |
||
20 | { |
||
21 | /** |
||
22 | * @var array<SignerConfig> |
||
23 | */ |
||
24 | private array $configs = []; |
||
25 | |||
26 | private string $defaultGateway = 'default'; |
||
27 | |||
28 | 10 | public function addConfig(SignerConfig $config, string $gateway = 'default'): void |
|
29 | { |
||
30 | 10 | $this->configs[$gateway] = $config; |
|
31 | } |
||
32 | |||
33 | 20 | public function getConfig(string|null $gateway = null): SignerConfig |
|
34 | { |
||
35 | 20 | if (null === $gateway) { |
|
36 | 4 | $gateway = $this->defaultGateway; |
|
37 | } |
||
38 | 20 | if (array_key_exists($gateway, $this->configs)) { |
|
39 | 19 | return $this->configs[$gateway]; |
|
40 | } |
||
41 | |||
42 | 1 | throw new InvalidArgumentException( |
|
43 | 1 | sprintf('Config for gateway "%s" does not exist. You are probably forgot added or you wrong set default config.', $gateway) |
|
44 | 1 | ); |
|
45 | } |
||
46 | |||
47 | 9 | public function setDefaultGateway(string $gateway): void |
|
48 | { |
||
49 | 9 | $this->defaultGateway = $gateway; |
|
50 | } |
||
51 | |||
52 | 4 | public function getDefaultGateway(): string |
|
55 | } |
||
56 | } |
||
57 |