Delete::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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