Completed
Push — master ( e318b6...c1c436 )
by Nate
02:57 queued 01:51
created

All::__construct()   A

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
ccs 0
cts 12
cp 0
rs 9.7998
c 0
b 0
f 0
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\Blog\Posts;
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\ResourceV2;
15
use Flipbox\Relay\Middleware\SimpleCache as CacheMiddleware;
16
use Psr\Log\LoggerInterface;
17
use Psr\SimpleCache\CacheInterface;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.3.0
22
 */
23
class All extends HttpRelayBuilder
24
{
25
    /**
26
     * The node
27
     */
28
    const NODE = 'content/api';
29
30
    /**
31
     * The resource
32
     */
33
    const RESOURCE = 'blog-posts';
34
35
    /**
36
     * @param array $params
37
     * @param CacheInterface $cache
38
     * @param AuthorizationInterface $authorization
39
     * @param LoggerInterface|null $logger
40
     * @param array $config
41
     */
42
    public function __construct(
43
        array $params,
44
        AuthorizationInterface $authorization,
45
        CacheInterface $cache,
46
        LoggerInterface $logger = null,
47
        $config = []
48
    ) {
49
        parent::__construct($authorization, $logger, $config);
50
51
        $cacheKey = self::RESOURCE . md5(serialize($params));
52
53
        $this->addUri($params, $logger)
54
            ->addCache($cache, $cacheKey, $logger);
55
    }
56
57
    /**
58
     * @param CacheInterface $cache
59
     * @param string $key
60
     * @param LoggerInterface|null $logger
61
     * @return $this
62
     */
63
    protected function addCache(CacheInterface $cache, string $key, LoggerInterface $logger = null)
64
    {
65
        return $this->addAfter('cache', [
66
            'class' => CacheMiddleware::class,
67
            'logger' => $logger ?: $this->getLogger(),
68
            'cache' => $cache,
69
            'key' => $key
70
        ], 'body');
71
    }
72
73
    /**
74
     * @param string $domain
0 ignored issues
show
Bug introduced by
There is no parameter named $domain. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
75
     * @param LoggerInterface|null $logger
76
     * @return $this
77
     */
78
    protected function addUri(array $params, LoggerInterface $logger = null)
79
    {
80
        return $this->addBefore('uri', [
81
            'class' => ResourceV2::class,
82
            'method' => 'GET',
83
            'params' => $params,
84
            'node' => self::NODE,
85
            'resource' => self::RESOURCE,
86
            'logger' => $logger ?: $this->getLogger()
87
        ]);
88
    }
89
}
90