Company::deleteRelay()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 16
cp 0
rs 9.6666
c 0
b 0
f 0
cc 4
nc 1
nop 5
crap 20
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/hubspot/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/hubspot
7
 */
8
9
namespace Flipbox\HubSpot\Resources;
10
11
use Flipbox\HubSpot\Connections\ConnectionInterface;
12
use Flipbox\HubSpot\HubSpot;
13
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Create;
14
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Delete;
15
use Flipbox\Relay\HubSpot\Builder\Resources\Company\ListByDomain;
16
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Read;
17
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Update;
18
use Psr\Http\Message\ResponseInterface;
19
use Psr\Log\LoggerInterface;
20
use Psr\SimpleCache\CacheInterface;
21
22
/**
23
 * @author Flipbox Factory <[email protected]>
24
 * @since 2.0.0
25
 */
26
class Company
27
{
28
    /**
29
     * @param string|null $identifier
30
     * @return bool
31
     */
32
    protected static function upsertHasId(string $identifier = null): bool
33
    {
34
        return !empty($identifier);
35
    }
36
37
    /*******************************************
38
     * CREATE
39
     *******************************************/
40
41
    /**
42
     * @param array $payload
43
     * @param ConnectionInterface|null $connection
44
     * @param LoggerInterface $logger
45
     * @param array $config
46
     * @return ResponseInterface
47
     */
48
    public static function create(
49
        array $payload,
50
        ConnectionInterface $connection = null,
51
        LoggerInterface $logger = null,
52
        array $config = []
53
    ): ResponseInterface {
54
        return static::createRelay(
55
            $payload,
56
            $connection,
57
            $logger,
58
            $config
59
        )();
60
    }
61
62
    /**
63
     * @param array $payload
64
     * @param ConnectionInterface|null $connection
65
     * @param LoggerInterface $logger
66
     * @param array $config
67
     * @return callable
68
     */
69
    public static function createRelay(
70
        array $payload,
71
        ConnectionInterface $connection = null,
72
        LoggerInterface $logger = null,
73
        array $config = []
74
    ): callable {
75
76
        $builder = new Create(
77
            $payload,
78
            $connection ?: HubSpot::getConnection(),
79
            $logger ?: HubSpot::getLogger(),
80
            $config
81
        );
82
83
        return $builder->build();
84
    }
85
86
87
    /*******************************************
88
     * READ
89
     *******************************************/
90
91
    /**
92
     * @param ConnectionInterface|null $connection
93
     * @param CacheInterface|null $cache
94
     * @param string $identifier
95
     * @param LoggerInterface|null $logger
96
     * @param array $config
97
     * @return ResponseInterface
98
     */
99
    public static function read(
100
        string $identifier,
101
        ConnectionInterface $connection = null,
102
        CacheInterface $cache = null,
103
        LoggerInterface $logger = null,
104
        array $config = []
105
    ): ResponseInterface {
106
        return static::readRelay(
107
            $identifier,
108
            $connection,
109
            $cache,
110
            $logger,
111
            $config
112
        )();
113
    }
114
115
    /**
116
     * @param ConnectionInterface|null $connection
117
     * @param CacheInterface|null $cache
118
     * @param string $identifier
119
     * @param LoggerInterface|null $logger
120
     * @param array $config
121
     * @return callable
122
     */
123
    public static function readRelay(
124
        string $identifier,
125
        ConnectionInterface $connection = null,
126
        CacheInterface $cache = null,
127
        LoggerInterface $logger = null,
128
        array $config = []
129
    ): callable {
130
131
        $builder = new Read(
132
            $identifier,
133
            $connection ?: HubSpot::getConnection(),
134
            $cache ?: HubSpot::getCache(),
135
            $logger ?: HubSpot::getLogger(),
136
            $config
137
        );
138
139
        return $builder->build();
140
    }
141
142
143
    /*******************************************
144
     * UPDATE
145
     *******************************************/
146
147
    /**
148
     * @param string $identifier
149
     * @param array $payload
150
     * @param ConnectionInterface|null $connection
151
     * @param CacheInterface|null $cache
152
     * @param LoggerInterface|null $logger
153
     * @param array $config
154
     * @return ResponseInterface
155
     */
156
    public static function update(
157
        array $payload,
158
        string $identifier,
159
        ConnectionInterface $connection = null,
160
        CacheInterface $cache = null,
161
        LoggerInterface $logger = null,
162
        array $config = []
163
    ): ResponseInterface {
164
        return static::updateRelay(
165
            $payload,
166
            $identifier,
167
            $connection,
168
            $cache,
169
            $logger,
170
            $config
171
        )();
172
    }
173
174
    /**
175
     * @param string $identifier
176
     * @param array $payload
177
     * @param ConnectionInterface|null $connection
178
     * @param CacheInterface|null $cache
179
     * @param LoggerInterface|null $logger
180
     * @param array $config
181
     * @return callable
182
     */
183
    public static function updateRelay(
184
        array $payload,
185
        string $identifier,
186
        ConnectionInterface $connection = null,
187
        CacheInterface $cache = null,
188
        LoggerInterface $logger = null,
189
        array $config = []
190
    ): callable {
191
192
        $builder = new Update(
193
            $identifier,
194
            $payload,
195
            $connection ?: HubSpot::getConnection(),
196
            $cache ?: HubSpot::getCache(),
197
            $logger ?: HubSpot::getLogger(),
198
            $config
199
        );
200
201
        return $builder->build();
202
    }
203
204
205
    /*******************************************
206
     * UPSERT
207
     *******************************************/
208
209
    /**
210
     * @param ConnectionInterface|null $connection
211
     * @param CacheInterface|null $cache
212
     * @param array $payload
213
     * @param string|null $identifier
214
     * @param LoggerInterface|null $logger
215
     * @param array $config
216
     * @return ResponseInterface
217
     */
218
    public static function upsert(
219
        array $payload,
220
        string $identifier = null,
221
        ConnectionInterface $connection = null,
222
        CacheInterface $cache = null,
223
        LoggerInterface $logger = null,
224
        array $config = []
225
    ): ResponseInterface {
226
        return static::upsertRelay(
227
            $payload,
228
            $identifier,
229
            $connection,
230
            $cache,
231
            $logger,
232
            $config
233
        )();
234
    }
235
236
    /**
237
     * @param ConnectionInterface|null $connection
238
     * @param CacheInterface|null $cache
239
     * @param array $payload
240
     * @param string|null $identifier
241
     * @param LoggerInterface|null $logger
242
     * @param array $config
243
     * @return callable
244
     */
245
    public static function upsertRelay(
246
        array $payload,
247
        string $identifier = null,
248
        ConnectionInterface $connection = null,
249
        CacheInterface $cache = null,
250
        LoggerInterface $logger = null,
251
        array $config = []
252
    ): callable {
253
254
        if (!static::upsertHasId($identifier)) {
255
            return static::createRelay(
256
                $payload,
257
                $connection,
258
                $logger,
259
                $config
260
            );
261
        }
262
263
        return static::updateRelay(
264
            $payload,
265
            $identifier,
266
            $connection,
267
            $cache,
268
            $logger,
269
            $config
270
        );
271
    }
272
273
274
    /*******************************************
275
     * DELETE
276
     *******************************************/
277
278
    /**
279
     * @param string $identifier
280
     * @param ConnectionInterface|null $connection
281
     * @param CacheInterface|null $cache
282
     * @param LoggerInterface $logger
283
     * @param array $config
284
     * @return ResponseInterface
285
     */
286
    public static function delete(
287
        string $identifier,
288
        ConnectionInterface $connection = null,
289
        CacheInterface $cache = null,
290
        LoggerInterface $logger = null,
291
        array $config = []
292
    ): ResponseInterface {
293
        return static::deleteRelay(
294
            $identifier,
295
            $connection,
296
            $cache,
297
            $logger,
298
            $config
299
        )();
300
    }
301
302
    /**
303
     * @param string $identifier
304
     * @param ConnectionInterface|null $connection
305
     * @param CacheInterface|null $cache
306
     * @param LoggerInterface $logger
307
     * @param array $config
308
     * @return callable
309
     */
310
    public static function deleteRelay(
311
        string $identifier,
312
        ConnectionInterface $connection = null,
313
        CacheInterface $cache = null,
314
        LoggerInterface $logger = null,
315
        array $config = []
316
    ): callable {
317
318
        $builder = new Delete(
319
            $identifier,
320
            $connection ?: HubSpot::getConnection(),
321
            $cache ?: HubSpot::getCache(),
322
            $logger ?: HubSpot::getLogger(),
323
            $config
324
        );
325
326
        return $builder->build();
327
    }
328
329
330
    /*******************************************
331
     * LIST (by Domain)
332
     *******************************************/
333
334
    /**
335
     * @param string $domain
336
     * @param array $payload
337
     * @param ConnectionInterface|null $connection
338
     * @param CacheInterface|null $cache
339
     * @param LoggerInterface|null $logger
340
     * @param array $config
341
     * @return ResponseInterface
342
     */
343
    public static function listByDomain(
344
        string $domain,
345
        array $payload = [],
346
        ConnectionInterface $connection = null,
347
        CacheInterface $cache = null,
348
        LoggerInterface $logger = null,
349
        array $config = []
350
    ): ResponseInterface {
351
        return static::listByDomainRelay(
352
            $domain,
353
            $payload,
354
            $connection,
355
            $cache,
356
            $logger,
357
            $config
358
        )();
359
    }
360
361
    /**
362
     * @param string $domain
363
     * @param array $payload
364
     * @param ConnectionInterface|null $connection
365
     * @param CacheInterface|null $cache
366
     * @param LoggerInterface|null $logger
367
     * @param array $config
368
     * @return callable
369
     */
370
    public static function listByDomainRelay(
371
        string $domain,
372
        array $payload = [],
373
        ConnectionInterface $connection = null,
374
        CacheInterface $cache = null,
375
        LoggerInterface $logger = null,
376
        array $config = []
377
    ): callable {
378
379
        $builder = new ListByDomain(
380
            $domain,
381
            $payload,
382
            $connection ?: HubSpot::getConnection(),
383
            $cache ?: HubSpot::getCache(),
384
            $logger ?: HubSpot::getLogger(),
385
            $config
386
        );
387
388
        return $builder->build();
389
    }
390
}
391