All   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
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 65
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A addCache() 0 9 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\Company\Contacts;
10
11
use Flipbox\Relay\HubSpot\AuthorizationInterface;
12
use Flipbox\Relay\HubSpot\Builder\HttpRelayBuilder;
13
use Flipbox\Relay\HubSpot\Middleware\ResourceV2;
14
use Flipbox\Relay\Middleware\SimpleCache as CacheMiddleware;
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 All extends HttpRelayBuilder
23
{
24
    /**
25
     * The node
26
     */
27
    const NODE = 'companies';
28
29
    /**
30
     * The resource
31
     */
32
    const RESOURCE = 'companies';
33
34
    /**
35
     * @param string $companyId
36
     * @param CacheInterface $cache
37
     * @param AuthorizationInterface $authorization
38
     * @param LoggerInterface|null $logger
39
     * @param array $config
40
     */
41
    public function __construct(
42
        string $companyId,
43
        AuthorizationInterface $authorization,
44
        CacheInterface $cache,
45
        LoggerInterface $logger = null,
46
        $config = []
47
    ) {
48
        parent::__construct($authorization, $logger, $config);
49
50
        $cacheKey = self::RESOURCE . ':' . $companyId . ':contacts';
51
52
        $this->addUri($companyId, $logger)
53
            ->addCache($cache, $cacheKey, $logger);
54
    }
55
56
    /**
57
     * @param CacheInterface $cache
58
     * @param string $key
59
     * @param LoggerInterface|null $logger
60
     * @return $this
61
     */
62
    protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null)
63
    {
64
        return $this->addBefore('cache', [
65
            'class' => CacheMiddleware::class,
66
            'logger' => $logger ?: $this->getLogger(),
67
            'cache' => $cache,
68
            'key' => $key
69
        ], 'token');
70
    }
71
72
    /**
73
     * @param string $id
74
     * @param LoggerInterface|null $logger
75
     * @return $this
76
     */
77
    protected function addUri(string $id, LoggerInterface $logger = null)
78
    {
79
        return $this->addBefore('uri', [
80
            'class' => ResourceV2::class,
81
            'node' => self::NODE,
82
            'resource' => self::RESOURCE . '/' . $id . 'contacts',
83
            'logger' => $logger ?: $this->getLogger()
84
        ]);
85
    }
86
}
87