HttpRelayBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 48
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A addAuthorization() 0 10 2
A addClient() 0 7 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/relay-hubspot/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/relay-hubspot
7
 */
8
9
namespace Flipbox\Relay\HubSpot\Builder;
10
11
use Flipbox\Relay\Builder\RelayBuilder;
12
use Flipbox\Relay\HubSpot\AuthorizationInterface;
13
use Flipbox\Relay\HubSpot\Middleware\Authorization as AuthorizationMiddleware;
14
use Flipbox\Relay\HubSpot\Middleware\Client as ClientMiddleware;
15
use Psr\Log\LoggerInterface;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class HttpRelayBuilder extends RelayBuilder
22
{
23
    /**
24
     * @param AuthorizationInterface $authorization
25
     * @param LoggerInterface|null $logger
26
     * @param array $config
27
     */
28
    public function __construct(
29
        AuthorizationInterface $authorization,
30
        LoggerInterface $logger = null,
31
        array $config = []
32
    ) {
33
        parent::__construct(
34
            $config
35
        );
36
37
        $this->addClient($logger)
38
            ->addAuthorization($authorization, $logger);
39
    }
40
41
    /**
42
     * @param AuthorizationInterface $authorization
43
     * @param LoggerInterface|null $logger
44
     * @return $this
45
     */
46
    protected function addAuthorization(
47
        AuthorizationInterface $authorization,
48
        LoggerInterface $logger = null
49
    ) {
50
        return $this->addBefore('token', [
51
            'class' => AuthorizationMiddleware::class,
52
            'logger' => $logger ?: $this->getLogger(),
53
            'authorization' => $authorization
54
        ], 'client');
55
    }
56
57
    /**
58
     * @param LoggerInterface|null $logger
59
     * @return $this
60
     */
61
    protected function addClient(LoggerInterface $logger = null)
62
    {
63
        return $this->addAfter('client', [
64
            'class' => ClientMiddleware::class,
65
            'logger' => $logger ?: $this->getLogger(),
66
        ]);
67
    }
68
}
69