Completed
Push — master ( 13e965...dd1cb7 )
by Nate
11:32 queued 05:17
created

Read::addUri()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 6
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\Limit\Daily;
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 = 'limit/daily';
33
34
    /**
35
     * @param AuthorizationInterface $authorization
36
     * @param CacheInterface $cache
37
     * @param LoggerInterface|null $logger
38
     * @param array $config
39
     */
40
    public function __construct(
41
        AuthorizationInterface $authorization,
42
        CacheInterface $cache,
43
        LoggerInterface $logger = null,
44
        $config = []
45
    ) {
46
        parent::__construct($authorization, $logger, $config);
47
48
        $cacheKey = self::RESOURCE;
49
50
        $this->addUri($logger)
51
            ->addCache($cache, $cacheKey, $logger);
52
    }
53
54
    /**
55
     * @param LoggerInterface|null $logger
56
     * @return $this
57
     */
58
    protected function addUri(LoggerInterface $logger = null)
59
    {
60
        return $this->addBefore('uri', [
61
            'class' => ResourceV1::class,
62
            'node' => self::NODE,
63
            'resource' => self::RESOURCE,
64
            'logger' => $logger ?: $this->getLogger()
65
        ]);
66
    }
67
68
    /**
69
     * @param CacheInterface $cache
70
     * @param string $key
71
     * @param LoggerInterface|null $logger
72
     * @return $this
73
     */
74
    protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null)
75
    {
76
        return $this->addBefore('cache', [
77
            'class' => CacheMiddleware::class,
78
            'logger' => $logger ?: $this->getLogger(),
79
            'cache' => $cache,
80
            'key' => $key
81
        ], 'token');
82
    }
83
}
84