Completed
Push — develop ( 3dabae...af53e6 )
by Nate
02:32
created

Read   A

Complexity

Total Complexity 5

Size/Duplication

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 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\Timeline\Event;
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\ResourceV1;
15
use Psr\Log\LoggerInterface;
16
use Psr\SimpleCache\CacheInterface;
17
18
use Flipbox\Relay\Middleware\SimpleCache as CacheMiddleware;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since 1.0.0
23
 */
24
class Read extends HttpRelayBuilder
25
{
26
    /**
27
     * The node
28
     */
29
    const NODE = 'integrations';
30
31
    /**
32
     * The resource
33
     */
34
    const RESOURCE = 'timeline/event';
35
36
    /**
37
     * @param string $appId
38
     * @param string $eventTypeId
39
     * @param string $id
40
     * @param AuthorizationInterface $authorization
41
     * @param CacheInterface $cache
42
     * @param LoggerInterface|null $logger
43
     * @param array $config
44
     */
45
    public function __construct(
46
        string $appId,
47
        string $eventTypeId,
48
        string $id,
49
        AuthorizationInterface $authorization,
50
        CacheInterface $cache,
51
        LoggerInterface $logger = null,
52
        $config = []
53
    ) {
54
        parent::__construct($authorization, $logger, $config);
55
56
        $cacheKey = self::RESOURCE . ':' . $appId . ':' . $eventTypeId . ':' . $id;
57
58
        $this->addUri($appId, $eventTypeId, $id, $logger)
59
            ->addCache($cache, $cacheKey, $logger);
60
    }
61
62
    /**
63
     * @param CacheInterface $cache
64
     * @param string $key
65
     * @param LoggerInterface|null $logger
66
     * @return $this
67
     */
68
    protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null)
69
    {
70
        return $this->addBefore('cache', [
71
            'class' => CacheMiddleware::class,
72
            'logger' => $logger ?: $this->getLogger(),
73
            'cache' => $cache,
74
            'key' => $key
75
        ], 'token');
76
    }
77
78
    /**
79
     * @param string $appId
80
     * @param string $eventTypeId
81
     * @param string $id
82
     * @param LoggerInterface|null $logger
83
     * @return $this
84
     */
85
    protected function addUri(string $appId, string $eventTypeId, string $id, LoggerInterface $logger = null)
86
    {
87
        return $this->addBefore('uri', [
88
            'class' => ResourceV1::class,
89
            'node' => self::NODE,
90
            'resource' => $appId . '/' . self::RESOURCE . '/' . $eventTypeId . '/' . $id,
91
            'logger' => $logger ?: $this->getLogger()
92
        ]);
93
    }
94
}
95