Passed
Push — master ( b40bc2...29ef41 )
by Mr
07:40
created

PaymentServiceMapProvisioner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 27
ccs 0
cts 23
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A provision() 0 25 3
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/money-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Money\Service;
10
11
use Auryn\Injector;
12
use Daikon\Boot\Service\Provisioner\ProvisionerInterface;
13
use Daikon\Boot\Service\ServiceDefinitionInterface;
14
use Daikon\Config\ConfigProviderInterface;
15
use Daikon\Dbal\Connector\ConnectorMap;
16
17
final class PaymentServiceMapProvisioner implements ProvisionerInterface
18
{
19
    public function provision(
20
        Injector $injector,
21
        ConfigProviderInterface $configProvider,
22
        ServiceDefinitionInterface $serviceDefinition
23
    ): void {
24
        $serviceConfigs = $configProvider->get('payments.services', []);
25
        $factory = function (ConnectorMap $connectorMap) use ($injector, $serviceConfigs): PaymentServiceMap {
26
            $services = [];
27
            foreach ($serviceConfigs as $serviceName => $serviceConfig) {
28
                $serviceClass = $serviceConfig['class'];
29
                $services[$serviceName] = $injector->define(
30
                    $serviceClass,
31
                    [
32
                        ':connector' =>
33
                            $serviceConfig['connector'] ? $connectorMap->get($serviceConfig['connector']) : null,
34
                        ':settings' => $serviceConfig['settings'] ?? []
35
                    ]
36
                )->make($serviceClass);
37
            }
38
            return new PaymentServiceMap($services);
39
        };
40
41
        $injector
42
            ->share(PaymentServiceMap::class)
43
            ->delegate(PaymentServiceMap::class, $factory);
44
    }
45
}
46