Completed
Push — develop ( b48ec5...ad5b3d )
by Nate
08:03
created

CompanyContacts::readRelayBuilderClass()   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
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
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\builders\CompanyContactsBuilder;
12
use flipbox\hubspot\builders\CompanyContactsBuilderInterface;
13
use flipbox\hubspot\connections\ConnectionInterface;
14
use flipbox\hubspot\criteria\CompanyContactsCriteria;
15
use flipbox\hubspot\criteria\ObjectCriteriaInterface;
16
use flipbox\hubspot\helpers\CacheHelper;
17
use flipbox\hubspot\helpers\ConnectionHelper;
18
use flipbox\hubspot\helpers\TransformerHelper;
19
use flipbox\hubspot\HubSpot;
20
use flipbox\hubspot\pipeline\Resource;
21
use flipbox\hubspot\services\resources\traits\ReadObjectTrait;
22
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
23
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Contacts\Add;
24
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Contacts\All;
25
use Flipbox\Relay\HubSpot\Builder\Resources\Company\Contacts\Remove;
26
use League\Pipeline\PipelineBuilderInterface;
27
use Psr\Http\Message\ResponseInterface;
28
use Psr\SimpleCache\CacheInterface;
29
use yii\base\Component;
30
31
/**
32
 * @author Flipbox Factory <[email protected]>
33
 * @since 1.0.0
34
 */
35
class CompanyContacts extends Component
36
{
37
    use ReadObjectTrait;
38
39
    /**
40
     * The HubSpot Resource name
41
     */
42
    const HUBSPOT_RESOURCE = 'companyContacts';
43
44
    /**
45
     * @param array $config
46
     * @return ObjectCriteriaInterface
47
     */
48
    public function getCriteria(array $config = []): ObjectCriteriaInterface
49
    {
50
        return new CompanyContactsCriteria($config);
51
    }
52
53
    /**
54
     * @param array $config
55
     * @return CompanyContactsBuilderInterface
56
     */
57
    public function getBuilder(array $config = []): CompanyContactsBuilderInterface
58
    {
59
        return new CompanyContactsBuilder($config);
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    protected static function readRelayBuilderClass(): string
66
    {
67
        return All::class;
68
    }
69
70
71
72
    /*******************************************
73
     * ADD
74
     *******************************************/
75
76
    /**
77
     * @param CompanyContactsBuilderInterface $builder
78
     * @param ConnectionInterface|null $connection
79
     * @param CacheInterface|null $cache
80
     * @param TransformerCollectionInterface|null $transformer
81
     * @param null $source
82
     * @return mixed
83
     * @throws \yii\base\InvalidConfigException
84
     */
85
    public function add(
86
        CompanyContactsBuilderInterface $builder,
87
        ConnectionInterface $connection = null,
88
        CacheInterface $cache = null,
89
        TransformerCollectionInterface $transformer = null,
90
        $source = null
91
    ) {
92
        return $this->rawAdd(
93
            $builder->getCompanyId(),
94
            $builder->getContactId(),
95
            $connection,
96
            $cache,
97
            $transformer,
98
            $source
99
        );
100
    }
101
102
    /**
103
     * @param string $companyId
104
     * @param string $contactId
105
     * @param ConnectionInterface|null $connection
106
     * @param CacheInterface|null $cache
107
     * @param TransformerCollectionInterface|null $transformer
108
     * @return PipelineBuilderInterface
109
     * @throws \yii\base\InvalidConfigException
110
     */
111
    public function rawAddPipeline(
112
        string $companyId,
113
        string $contactId,
114
        ConnectionInterface $connection = null,
115
        CacheInterface $cache = null,
116
        TransformerCollectionInterface $transformer = null
117
    ): PipelineBuilderInterface {
118
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
119
            'resource' => [Add::class]
120
        ]);
121
122
        return (new Resource(
123
            $this->rawHttpAddRelay(
124
                $companyId,
125
                $contactId,
126
                $connection,
127
                $cache
128
            ),
129
            $transformer,
130
            HubSpot::getInstance()->getPsrLogger()
131
        ));
132
    }
133
134
    /**
135
     * @param string $companyId
136
     * @param string $contactId
137
     * @param ConnectionInterface|null $connection
138
     * @param CacheInterface|null $cache
139
     * @param TransformerCollectionInterface|null $transformer
140
     * @param null $source
141
     * @return mixed
142
     * @throws \yii\base\InvalidConfigException
143
     */
144
    public function rawAdd(
145
        string $companyId,
146
        string $contactId,
147
        ConnectionInterface $connection = null,
148
        CacheInterface $cache = null,
149
        TransformerCollectionInterface $transformer = null,
150
        $source = null
151
    ) {
152
        return $this->rawAddPipeline(
153
            $companyId,
154
            $contactId,
155
            $connection,
156
            $cache,
157
            $transformer
158
        )($source);
159
    }
160
161
162
    /**
163
     * @param CompanyContactsBuilderInterface $builder
164
     * @param ConnectionInterface|null $connection
165
     * @param CacheInterface|null $cache
166
     * @param TransformerCollectionInterface|null $transformer
167
     * @return PipelineBuilderInterface
168
     * @throws \yii\base\InvalidConfigException
169
     */
170
    public function addPipeline(
171
        CompanyContactsBuilderInterface $builder,
172
        ConnectionInterface $connection = null,
173
        CacheInterface $cache = null,
174
        TransformerCollectionInterface $transformer = null
175
    ): PipelineBuilderInterface {
176
        return $this->rawAddPipeline(
177
            $builder->getCompanyId(),
178
            $builder->getContactId(),
179
            $connection,
180
            $cache,
181
            $transformer
182
        );
183
    }
184
185
    /**
186
     * @param CompanyContactsBuilderInterface $builder
187
     * @param ConnectionInterface|null $connection
188
     * @param CacheInterface|null $cache
189
     * @return callable
190
     * @throws \yii\base\InvalidConfigException
191
     */
192
    public function httpAddRelay(
193
        CompanyContactsBuilderInterface $builder,
194
        ConnectionInterface $connection = null,
195
        CacheInterface $cache = null
196
    ): callable {
197
        return $this->rawHttpAddRelay(
198
            $builder->getCompanyId(),
199
            $builder->getContactId(),
200
            $connection,
201
            $cache
202
        );
203
    }
204
205
    /**
206
     * @param string $companyId
207
     * @param string $contactId
208
     * @param ConnectionInterface|null $connection
209
     * @param CacheInterface|null $cache
210
     * @return callable
211
     * @throws \yii\base\InvalidConfigException
212
     */
213
    public function rawHttpAddRelay(
214
        string $companyId,
215
        string $contactId,
216
        ConnectionInterface $connection = null,
217
        CacheInterface $cache = null
218
    ): callable {
219
        return (new Add(
220
            $companyId,
221
            $contactId,
222
            ConnectionHelper::resolveConnection($connection),
223
            CacheHelper::resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 217 can be null; however, flipbox\hubspot\helpers\...eHelper::resolveCache() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
224
            HubSpot::getInstance()->getPsrLogger()
225
        ))->build();
226
    }
227
228
    /**
229
     * @param CompanyContactsBuilderInterface $builder
230
     * @param ConnectionInterface|null $connection
231
     * @param CacheInterface|null $cache
232
     * @return ResponseInterface
233
     * @throws \yii\base\InvalidConfigException
234
     */
235
    public function httpAdd(
236
        CompanyContactsBuilderInterface $builder,
237
        ConnectionInterface $connection = null,
238
        CacheInterface $cache = null
239
    ): ResponseInterface {
240
        return $this->rawHttpAdd(
241
            $builder->getCompanyId(),
242
            $builder->getContactId(),
243
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 237 can be null; however, flipbox\hubspot\services...yContacts::rawHttpAdd() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
244
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 238 can be null; however, flipbox\hubspot\services...yContacts::rawHttpAdd() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
245
        );
246
    }
247
248
    /**
249
     * @param string $companyId
250
     * @param string $contactId
251
     * @param ConnectionInterface|null $connection
252
     * @param CacheInterface|null $cache
253
     * @return ResponseInterface
254
     * @throws \yii\base\InvalidConfigException
255
     */
256
    public function rawHttpAdd(
257
        string $companyId,
258
        string $contactId,
259
        ConnectionInterface $connection,
260
        CacheInterface $cache
261
    ): ResponseInterface {
262
        return $this->rawHttpAddRelay(
263
            $companyId,
264
            $contactId,
265
            $connection,
266
            $cache
267
        )();
268
    }
269
270
271
    /*******************************************
272
     * REMOVE
273
     *******************************************/
274
275
    /**
276
     * @param CompanyContactsBuilderInterface $builder
277
     * @param ConnectionInterface|null $connection
278
     * @param CacheInterface|null $cache
279
     * @param TransformerCollectionInterface|null $transformer
280
     * @param null $source
281
     * @return mixed
282
     * @throws \yii\base\InvalidConfigException
283
     */
284
    public function remove(
285
        CompanyContactsBuilderInterface $builder,
286
        ConnectionInterface $connection = null,
287
        CacheInterface $cache = null,
288
        TransformerCollectionInterface $transformer = null,
289
        $source = null
290
    ) {
291
        return $this->rawRemove(
292
            $builder->getCompanyId(),
293
            $builder->getContactId(),
294
            $connection,
295
            $cache,
296
            $transformer,
297
            $source
298
        );
299
    }
300
301
    /**
302
     * @param string $companyId
303
     * @param string $contactId
304
     * @param ConnectionInterface|null $connection
305
     * @param CacheInterface|null $cache
306
     * @param TransformerCollectionInterface|null $transformer
307
     * @param null $source
308
     * @return mixed
309
     * @throws \yii\base\InvalidConfigException
310
     */
311
    public function rawRemove(
312
        string $companyId,
313
        string $contactId,
314
        ConnectionInterface $connection = null,
315
        CacheInterface $cache = null,
316
        TransformerCollectionInterface $transformer = null,
317
        $source = null
318
    ) {
319
        return $this->rawRemovePipeline(
320
            $companyId,
321
            $contactId,
322
            $connection,
323
            $cache,
324
            $transformer
325
        )($source);
326
    }
327
328
    /**
329
     * @param CompanyContactsBuilderInterface $builder
330
     * @param ConnectionInterface|null $connection
331
     * @param CacheInterface|null $cache
332
     * @param TransformerCollectionInterface|null $transformer
333
     * @return PipelineBuilderInterface
334
     * @throws \yii\base\InvalidConfigException
335
     */
336
    public function removePipeline(
337
        CompanyContactsBuilderInterface $builder,
338
        ConnectionInterface $connection = null,
339
        CacheInterface $cache = null,
340
        TransformerCollectionInterface $transformer = null
341
    ): PipelineBuilderInterface {
342
        return $this->rawRemovePipeline(
343
            $builder->getCompanyId(),
344
            $builder->getContactId(),
345
            $connection,
346
            $cache,
347
            $transformer
348
        );
349
    }
350
351
    /**
352
     * @param string $companyId
353
     * @param string $contactId
354
     * @param ConnectionInterface|null $connection
355
     * @param CacheInterface|null $cache
356
     * @param TransformerCollectionInterface|null $transformer
357
     * @return PipelineBuilderInterface
358
     * @throws \yii\base\InvalidConfigException
359
     */
360
    public function rawRemovePipeline(
361
        string $companyId,
362
        string $contactId,
363
        ConnectionInterface $connection = null,
364
        CacheInterface $cache = null,
365
        TransformerCollectionInterface $transformer = null
366
    ): PipelineBuilderInterface {
367
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
368
            'resource' => [Remove::class]
369
        ]);
370
371
        return (new Resource(
372
            $this->rawHttpAddRelay(
373
                $companyId,
374
                $contactId,
375
                $connection,
376
                $cache
377
            ),
378
            $transformer,
379
            HubSpot::getInstance()->getPsrLogger()
380
        ));
381
    }
382
383
    /**
384
     * @param CompanyContactsBuilderInterface $builder
385
     * @param ConnectionInterface|null $connection
386
     * @param CacheInterface|null $cache
387
     * @return callable
388
     * @throws \yii\base\InvalidConfigException
389
     */
390
    public function httpRemoveRelay(
391
        CompanyContactsBuilderInterface $builder,
392
        ConnectionInterface $connection = null,
393
        CacheInterface $cache = null
394
    ): callable {
395
        return $this->rawHttpRemoveRelay(
396
            $builder->getCompanyId(),
397
            $builder->getContactId(),
398
            $connection,
399
            $cache
400
        );
401
    }
402
403
    /**
404
     * @param string $companyId
405
     * @param string $contactId
406
     * @param ConnectionInterface|null $connection
407
     * @param CacheInterface|null $cache
408
     * @return callable
409
     * @throws \yii\base\InvalidConfigException
410
     */
411
    public function rawHttpRemoveRelay(
412
        string $companyId,
413
        string $contactId,
414
        ConnectionInterface $connection = null,
415
        CacheInterface $cache = null
416
    ): callable {
417
        return (new Remove(
418
            $companyId,
419
            $contactId,
420
            ConnectionHelper::resolveConnection($connection),
421
            CacheHelper::resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 415 can be null; however, flipbox\hubspot\helpers\...eHelper::resolveCache() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
422
            HubSpot::getInstance()->getPsrLogger()
423
        ))->build();
424
    }
425
426
    /**
427
     * @param CompanyContactsBuilderInterface $builder
428
     * @param ConnectionInterface|null $connection
429
     * @param CacheInterface|null $cache
430
     * @return ResponseInterface
431
     * @throws \yii\base\InvalidConfigException
432
     */
433
    public function httpRemove(
434
        CompanyContactsBuilderInterface $builder,
435
        ConnectionInterface $connection = null,
436
        CacheInterface $cache = null
437
    ): ResponseInterface {
438
        return $this->rawHttpRemove(
439
            $builder->getCompanyId(),
440
            $builder->getContactId(),
441
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 435 can be null; however, flipbox\hubspot\services...ntacts::rawHttpRemove() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
442
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 436 can be null; however, flipbox\hubspot\services...ntacts::rawHttpRemove() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
443
        );
444
    }
445
446
    /**
447
     * @param string $companyId
448
     * @param string $contactId
449
     * @param ConnectionInterface|null $connection
450
     * @param CacheInterface|null $cache
451
     * @return ResponseInterface
452
     * @throws \yii\base\InvalidConfigException
453
     */
454
    public function rawHttpRemove(
455
        string $companyId,
456
        string $contactId,
457
        ConnectionInterface $connection,
458
        CacheInterface $cache
459
    ): ResponseInterface {
460
        return $this->rawHttpRemoveRelay(
461
            $companyId,
462
            $contactId,
463
            $connection,
464
            $cache
465
        )();
466
    }
467
}
468