Completed
Branch develop (305bdf)
by Nate
06:50
created

HttpRelayBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

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
     * @param AuthorizationInterface $authorization
42
     * @param LoggerInterface|null $logger
43
     * @return $this
44
     */
45
    protected function addAuthorization(
46
        AuthorizationInterface $authorization,
47
        LoggerInterface $logger = null
48
    ) {
49
        return $this->addBefore('token', [
50
            'class' => AuthorizationMiddleware::class,
51
            'logger' => $logger ?: $this->getLogger(),
52
            'authorization' => $authorization
53
        ], 'client');
54
    }
55
56
    /**
57
     * @param LoggerInterface|null $logger
58
     * @return $this
59
     */
60
    protected function addClient(LoggerInterface $logger = null)
61
    {
62
        return $this->addAfter('client', [
63
            'class' => ClientMiddleware::class,
64
            'logger' => $logger ?: $this->getLogger(),
65
        ]);
66
    }
67
}
68