CoinbaseGatewayFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 17
c 1
b 0
f 0
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A populateConfig() 0 28 2
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCoinbasePlugin;
12
13
use BitBag\SyliusCoinbasePlugin\ApiClient\CoinbaseApiClientInterface;
14
use Payum\Core\Bridge\Spl\ArrayObject;
15
use Payum\Core\GatewayFactory;
16
17
final class CoinbaseGatewayFactory extends GatewayFactory
18
{
19
    public const FACTORY_NAME = 'coinbase';
20
21
    protected function populateConfig(ArrayObject $config)
22
    {
23
        $config->defaults([
24
            'payum.factory_name' => self::FACTORY_NAME,
25
            'payum.factory_title' => 'coinbase',
26
            'payum.http_client' => '@bitbag_sylius_coinbase_plugin.api_client.coinbase',
27
        ]);
28
29
        if (false === (bool) $config['payum.api']) {
30
            $config['payum.default_options'] = [
31
                'apiKey' => null,
32
            ];
33
34
            $config->defaults($config['payum.default_options']);
35
36
            $config['payum.required_options'] = [
37
                'apiKey',
38
            ];
39
40
            $config['payum.api'] = function (ArrayObject $config) {
41
                $config->validateNotEmpty($config['payum.required_options']);
42
43
                /** @var CoinbaseApiClientInterface $coinbaseApiClient */
44
                $coinbaseApiClient = $config['payum.http_client'];
45
46
                $coinbaseApiClient->initialise($config['apiKey']);
47
48
                return $coinbaseApiClient;
49
            };
50
        }
51
    }
52
}
53