Completed
Push — develop ( d125ce...d62c8c )
by Nate
11:11
created

Limit::readDailyRelayBuilderClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\services\resources;
10
11
use flipbox\hubspot\connections\ConnectionInterface;
12
use flipbox\hubspot\criteria\IntegrationCriteriaInterface;
13
use flipbox\hubspot\helpers\CacheHelper;
14
use flipbox\hubspot\helpers\ConnectionHelper;
15
use flipbox\hubspot\helpers\TransformerHelper;
16
use flipbox\hubspot\HubSpot;
17
use flipbox\hubspot\pipeline\Resource;
18
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
19
use Flipbox\Relay\Builder\RelayBuilderInterface;
20
use Flipbox\Relay\HubSpot\Builder\Resources\Limit\Daily\Read;
21
use League\Pipeline\PipelineBuilderInterface;
22
use Psr\Http\Message\ResponseInterface;
23
use Psr\SimpleCache\CacheInterface;
24
use yii\base\Component;
25
26
/**
27
 * @author Flipbox Factory <[email protected]>
28
 * @since 1.0.0
29
 */
30
class Limit extends Component
31
{
32
    /**
33
     * The HubSpot Resource name
34
     */
35
    const HUBSPOT_RESOURCE = 'limit';
36
37
    /**
38
     * @return string
39
     */
40
    protected static function readDailyRelayBuilderClass(): string
41
    {
42
        return Read::class;
43
    }
44
45
    /**
46
     * @param ConnectionInterface|string|null $connection
47
     * @param CacheInterface|string|null $cache
48
     * @return callable
49
     * @throws \yii\base\InvalidConfigException
50
     */
51
    public function rawHttpReadDailyRelay(
52
        ConnectionInterface $connection = null,
53
        CacheInterface $cache = null
54
    ): callable {
55
        $class = static::readDailyRelayBuilderClass();
56
57
        /** @var RelayBuilderInterface $builder */
58
        $builder = new $class(
59
            ConnectionHelper::resolveConnection($connection),
60
            CacheHelper::resolveCache($cache),
61
            HubSpot::getInstance()->getPsrLogger()
62
        );
63
64
        return $builder->build();
65
    }
66
67
    /**
68
     * @param IntegrationCriteriaInterface $criteria
69
     * @param null $source
70
     * @return mixed
71
     * @throws \yii\base\InvalidConfigException
72
     */
73
    public function readDaily(
74
        IntegrationCriteriaInterface $criteria,
75
        $source = null
76
    ) {
77
        return $this->rawReadDaily(
78
            $criteria->getConnection(),
79
            $criteria->getCache(),
80
            $criteria->getTransformer(),
81
            $source
82
        );
83
    }
84
85
    /**
86
     * @param ConnectionInterface|string|null $connection
87
     * @param CacheInterface|string|null $cache
88
     * @param TransformerCollectionInterface|array|null $transformer
89
     * @param null $source
90
     * @return mixed
91
     * @throws \yii\base\InvalidConfigException
92
     */
93
    public function rawReadDaily(
94
        ConnectionInterface $connection = null,
95
        CacheInterface $cache = null,
96
        TransformerCollectionInterface $transformer = null,
97
        $source = null
98
    ) {
99
        return $this->rawReadDailyPipeline(
100
            $connection,
101
            $cache,
102
            $transformer
103
        )($source);
104
    }
105
106
    /**
107
     * @param IntegrationCriteriaInterface $criteria
108
     * @return PipelineBuilderInterface
109
     * @throws \yii\base\InvalidConfigException
110
     */
111
    public function readDailyPipeline(
112
        IntegrationCriteriaInterface $criteria
113
    ): PipelineBuilderInterface {
114
        return $this->rawReadDailyPipeline(
115
            $criteria->getConnection(),
116
            $criteria->getCache(),
117
            $criteria->getTransformer()
118
        );
119
    }
120
121
    /**
122
     * @param ConnectionInterface|string|null $connection
123
     * @param CacheInterface|string|null $cache
124
     * @param TransformerCollectionInterface|array|null $transformer
125
     * @return PipelineBuilderInterface
126
     * @throws \yii\base\InvalidConfigException
127
     */
128
    public function rawReadDailyPipeline(
129
        ConnectionInterface $connection = null,
130
        CacheInterface $cache = null,
131
        TransformerCollectionInterface $transformer = null
132
    ): PipelineBuilderInterface {
133
        $transformer = TransformerHelper::populateTransformerCollection(
134
            TransformerHelper::resolveCollection($transformer),
135
            [
136
                'resource' => [static::readDailyRelayBuilderClass()]
137
            ]
138
        );
139
140
        return (new Resource(
141
            $this->rawHttpReadDailyRelay(
142
                ConnectionHelper::resolveConnection($connection),
143
                $cache
144
            ),
145
            $transformer,
146
            HubSpot::getInstance()->getPsrLogger()
147
        ));
148
    }
149
150
    /**
151
     * @param IntegrationCriteriaInterface $criteria
152
     * @return ResponseInterface
153
     * @throws \yii\base\InvalidConfigException
154
     */
155
    public function httpReadDaily(
156
        IntegrationCriteriaInterface $criteria
157
    ): ResponseInterface {
158
        return $this->rawHttpReadDaily(
159
            $criteria->getConnection(),
160
            $criteria->getCache()
161
        )();
162
    }
163
164
    /**
165
     * @param ConnectionInterface|string|null $connection
166
     * @param CacheInterface|string|null $cache
167
     * @return ResponseInterface
168
     * @throws \yii\base\InvalidConfigException
169
     */
170
    public function rawHttpReadDaily(
171
        ConnectionInterface $connection = null,
172
        CacheInterface $cache = null
173
    ): ResponseInterface {
174
        return $this->rawHttpReadDailyRelay(
175
            $connection,
176
            $cache
177
        )();
178
    }
179
180
    /**
181
     * @param IntegrationCriteriaInterface $criteria
182
     * @return callable
183
     * @throws \yii\base\InvalidConfigException
184
     */
185
    public function httpReadDailyRelay(
186
        IntegrationCriteriaInterface $criteria
187
    ): callable {
188
        return $this->rawHttpReadDailyRelay(
189
            $criteria->getConnection(),
190
            $criteria->getCache()
191
        );
192
    }
193
}
194