ReadByEmail   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 66
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
ccs 0
cts 30
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A addUri() 0 9 2
A addCache() 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\Contact;
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 ReadByEmail extends HttpRelayBuilder
23
{
24
    /**
25
     * The node
26
     */
27
    const NODE = 'contacts';
28
29
    /**
30
     * The resource
31
     */
32
    const RESOURCE = 'contact';
33
34
    /**
35
     * Upsert constructor.
36
     * @param AuthorizationInterface $authorization
37
     * @param CacheInterface $cache
38
     * @param string|null $identifier
39
     * @param LoggerInterface|null $logger
40
     * @param array $config
41
     */
42
    public function __construct(
43
        string $identifier,
44
        AuthorizationInterface $authorization,
45
        CacheInterface $cache,
46
        LoggerInterface $logger = null,
47
        $config = []
48
    ) {
49
        parent::__construct($authorization, $logger, $config);
50
51
        $cacheKey = self::RESOURCE . ':' . $identifier;
52
53
        $this->addUri($identifier, $logger)
54
            ->addCache($cache, $cacheKey, $logger);
55
    }
56
57
    /**
58
     * @param string|null $identifier
59
     * @param LoggerInterface|null $logger
60
     * @return $this
61
     */
62
    protected function addUri(string $identifier, LoggerInterface $logger = null)
63
    {
64
        return $this->addBefore('uri', [
65
            'class' => ResourceV1::class,
66
            'node' => self::NODE,
67
            'resource' => self::RESOURCE . '/email/' . $identifier . '/profile',
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