Passed
Push — master ( 99d0e8...9e7049 )
by Ondra
03:35
created

SignerProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 13 3
A __construct() 0 4 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\Signer;
16
17
use Pixidos\GPWebPay\Config\SignerConfigProvider;
18
19
final class SignerProvider implements SignerProviderInterface
20
{
21
    /**
22
     * @var array<SignerInterface>
23
     */
24
    private array $signers = [];
25
26 16
    public function __construct(
27
        private readonly SignerFactoryInterface $signerFactory,
28
        private readonly SignerConfigProvider $configs
29
    ) {
30 16
    }
31
32
    /**
33
     * @param string $gateway
34
     * @return SignerInterface
35
     */
36 15
    public function get(string|null $gateway = null): SignerInterface
37
    {
38 15
        if (null === $gateway) {
39 3
            $gateway = $this->configs->getDefaultGateway();
40
        }
41 15
        if (array_key_exists($gateway, $this->signers)) {
42 6
            return $this->signers[$gateway];
43
        }
44
45 15
        $signer = $this->signerFactory->create($this->configs->getConfig($gateway));
46 15
        $this->signers[$gateway] = $signer;
47
48 15
        return $signer;
49
    }
50
}
51