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

GetContacts   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 61
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 addPayload() 0 8 2
A addUri() 0 9 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\Resources\ContactList;
10
11
use Flipbox\Relay\HubSpot\AuthorizationInterface;
12
use Flipbox\Relay\HubSpot\Builder\HttpRelayBuilder;
13
use Flipbox\Relay\HubSpot\Middleware\JsonRequest as JsonMiddleware;
14
use Flipbox\Relay\HubSpot\Middleware\Resources\ResourceV1;
15
use Psr\Log\LoggerInterface;
16
use Psr\SimpleCache\CacheInterface;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
class GetContacts extends HttpRelayBuilder
23
{
24
    /**
25
     * The node
26
     */
27
    const NODE = 'contacts';
28
29
    /**
30
     * The resource
31
     */
32
    const RESOURCE = 'lists';
33
34
    /**
35
     * @param string $id
36
     * @param CacheInterface $cache
37
     * @param AuthorizationInterface $authorization
38
     * @param LoggerInterface|null $logger
39
     * @param array $config
40
     */
41
    public function __construct(
42
        string $id,
43
        AuthorizationInterface $authorization,
44
        CacheInterface $cache,
45
        LoggerInterface $logger = null,
46
        $config = []
47
    ) {
48
        parent::__construct($authorization, $logger, $config);
49
50
        $this->addUri($id, $logger)
51
            ->addPayload($payload, $logger);
0 ignored issues
show
Bug introduced by
The variable $payload does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
52
    }
53
54
    /**
55
     * @param array $payload
56
     * @param LoggerInterface|null $logger
57
     * @return $this
58
     */
59
    protected function addPayload(array $payload, LoggerInterface $logger = null)
60
    {
61
        return $this->addAfter('body', [
62
            'class' => JsonMiddleware::class,
63
            'payload' => $payload,
64
            'logger' => $logger ?: $this->getLogger()
65
        ], 'uri');
66
    }
67
68
    /**
69
     * @param string $id
70
     * @param LoggerInterface|null $logger
71
     * @return $this
72
     */
73
    protected function addUri(string $id, LoggerInterface $logger = null)
74
    {
75
        return $this->addBefore('uri', [
76
            'class' => ResourceV1::class,
77
            'node' => self::NODE,
78
            'resource' => self::RESOURCE . '/' . $id . 'contacts/all',
79
            'logger' => $logger ?: $this->getLogger()
80
        ]);
81
    }
82
}
83