Read::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 7
crap 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\ResourceV1;
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 Read extends HttpRelayBuilder
23
{
24
    /**
25
     * The node
26
     */
27
    const NODE = 'integrations';
28
29
    /**
30
     * The resource
31
     */
32
    const RESOURCE = 'timeline/event';
33
34
    /**
35
     * @param string $appId
36
     * @param string $eventTypeId
37
     * @param string $id
38
     * @param AuthorizationInterface $authorization
39
     * @param CacheInterface $cache
40
     * @param LoggerInterface|null $logger
41
     * @param array $config
42
     */
43
    public function __construct(
44
        string $appId,
45
        string $eventTypeId,
46
        string $id,
47
        AuthorizationInterface $authorization,
48
        CacheInterface $cache,
49
        LoggerInterface $logger = null,
50
        $config = []
51
    ) {
52
        parent::__construct($authorization, $logger, $config);
53
54
        $cacheKey = self::RESOURCE . ':' . $appId . ':' . $eventTypeId . ':' . $id;
55
56
        $this->addUri($appId, $eventTypeId, $id, $logger)
57
            ->addCache($cache, $cacheKey, $logger);
58
    }
59
60
    /**
61
     * @param CacheInterface $cache
62
     * @param string $key
63
     * @param LoggerInterface|null $logger
64
     * @return $this
65
     */
66
    protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null)
67
    {
68
        return $this->addBefore('cache', [
69
            'class' => CacheMiddleware::class,
70
            'logger' => $logger ?: $this->getLogger(),
71
            'cache' => $cache,
72
            'key' => $key
73
        ], 'token');
74
    }
75
76
    /**
77
     * @param string $appId
78
     * @param string $eventTypeId
79
     * @param string $id
80
     * @param LoggerInterface|null $logger
81
     * @return $this
82
     */
83
    protected function addUri(string $appId, string $eventTypeId, string $id, LoggerInterface $logger = null)
84
    {
85
        return $this->addBefore('uri', [
86
            'class' => ResourceV1::class,
87
            'node' => self::NODE,
88
            'resource' => $appId . '/' . self::RESOURCE . '/' . $eventTypeId . '/' . $id,
89
            'logger' => $logger ?: $this->getLogger()
90
        ]);
91
    }
92
}
93