Completed
Push — develop ( 639fa1...b48ec5 )
by Nate
02:32
created

CompanyContacts::rawRemovePipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
ccs 0
cts 11
cp 0
rs 9.568
cc 1
nc 1
nop 5
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\TransformerHelper;
17
use flipbox\hubspot\HubSpot;
18
use flipbox\hubspot\pipeline\Resource;
19
use flipbox\hubspot\services\resources\traits\ReadObjectTrait;
20
use flipbox\hubspot\traits\CacheResolverTrait;
21
use flipbox\hubspot\traits\ConnectionResolverTrait;
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 ConnectionResolverTrait,
38
        CacheResolverTrait,
39
        ReadObjectTrait;
40
41
    /**
42
     * The HubSpot Resource name
43
     */
44
    const HUBSPOT_RESOURCE = 'companyContacts';
45
46
    /**
47
     * @param array $config
48
     * @return ObjectCriteriaInterface
49
     */
50
    public function getCriteria(array $config = []): ObjectCriteriaInterface
51
    {
52
        return new CompanyContactsCriteria($config);
53
    }
54
55
    /**
56
     * @param array $config
57
     * @return CompanyContactsBuilderInterface
58
     */
59
    public function getBuilder(array $config = []): CompanyContactsBuilderInterface
60
    {
61
        return new CompanyContactsBuilder($config);
62
    }
63
64
    /*******************************************
65
     * READ
66
     *******************************************/
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function rawReadPipeline(
72
        string $id,
73
        ConnectionInterface $connection = null,
74
        CacheInterface $cache = null,
75
        TransformerCollectionInterface $transformer = null
76
    ): PipelineBuilderInterface {
77
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
78
            'resource' => [All::class]
79
        ]);
80
81
        return (new Resource(
82
            $this->rawHttpReadRelay(
83
                $id,
84
                $connection,
85
                $cache
86
            ),
87
            $transformer,
88
            HubSpot::getInstance()->getPsrLogger()
89
        ));
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function rawHttpReadRelay(
96
        string $id,
97
        ConnectionInterface $connection = null,
98
        CacheInterface $cache = null
99
    ): callable {
100
        return (new All(
101
            $id,
102
            $this->resolveConnection($connection),
103
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 98 can be null; however, flipbox\hubspot\traits\C...erTrait::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...
104
            HubSpot::getInstance()->getPsrLogger()
105
        ))->build();
106
    }
107
108
109
    /*******************************************
110
     * ADD
111
     *******************************************/
112
113
    /**
114
     * @param CompanyContactsBuilderInterface $builder
115
     * @param ConnectionInterface|null $connection
116
     * @param CacheInterface|null $cache
117
     * @param TransformerCollectionInterface|null $transformer
118
     * @param null $source
119
     * @return mixed
120
     * @throws \yii\base\InvalidConfigException
121
     */
122
    public function add(
123
        CompanyContactsBuilderInterface $builder,
124
        ConnectionInterface $connection = null,
125
        CacheInterface $cache = null,
126
        TransformerCollectionInterface $transformer = null,
127
        $source = null
128
    ) {
129
        return $this->rawAdd(
130
            $builder->getCompanyId(),
131
            $builder->getContactId(),
132
            $connection,
133
            $cache,
134
            $transformer,
135
            $source
136
        );
137
    }
138
139
    /**
140
     * @param string $companyId
141
     * @param string $contactId
142
     * @param ConnectionInterface|null $connection
143
     * @param CacheInterface|null $cache
144
     * @param TransformerCollectionInterface|null $transformer
145
     * @return PipelineBuilderInterface
146
     * @throws \yii\base\InvalidConfigException
147
     */
148
    public function rawAddPipeline(
149
        string $companyId,
150
        string $contactId,
151
        ConnectionInterface $connection = null,
152
        CacheInterface $cache = null,
153
        TransformerCollectionInterface $transformer = null
154
    ): PipelineBuilderInterface {
155
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
156
            'resource' => [Add::class]
157
        ]);
158
159
        return (new Resource(
160
            $this->rawHttpAddRelay(
0 ignored issues
show
Documentation introduced by
$this->rawHttpAddRelay($...d, $connection, $cache) is of type callable, but the function expects a object<Flipbox\Relay\Runner\Runner>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
                $companyId,
162
                $contactId,
163
                $connection,
164
                $cache
165
            ),
166
            $transformer,
167
            HubSpot::getInstance()->getPsrLogger()
168
        ));
169
    }
170
171
    /**
172
     * @param string $companyId
173
     * @param string $contactId
174
     * @param ConnectionInterface|null $connection
175
     * @param CacheInterface|null $cache
176
     * @param TransformerCollectionInterface|null $transformer
177
     * @param null $source
178
     * @return mixed
179
     * @throws \yii\base\InvalidConfigException
180
     */
181
    public function rawAdd(
182
        string $companyId,
183
        string $contactId,
184
        ConnectionInterface $connection = null,
185
        CacheInterface $cache = null,
186
        TransformerCollectionInterface $transformer = null,
187
        $source = null
188
    ) {
189
        return $this->rawAddPipeline(
190
            $companyId,
191
            $contactId,
192
            $connection,
193
            $cache,
194
            $transformer
195
        )($source);
196
    }
197
198
199
    /**
200
     * @param CompanyContactsBuilderInterface $builder
201
     * @param ConnectionInterface|null $connection
202
     * @param CacheInterface|null $cache
203
     * @param TransformerCollectionInterface|null $transformer
204
     * @return PipelineBuilderInterface
205
     * @throws \yii\base\InvalidConfigException
206
     */
207
    public function addPipeline(
208
        CompanyContactsBuilderInterface $builder,
209
        ConnectionInterface $connection = null,
210
        CacheInterface $cache = null,
211
        TransformerCollectionInterface $transformer = null
212
    ): PipelineBuilderInterface {
213
        return $this->rawAddPipeline(
214
            $builder->getCompanyId(),
215
            $builder->getContactId(),
216
            $connection,
217
            $cache,
218
            $transformer
219
        );
220
    }
221
222
    /**
223
     * @param CompanyContactsBuilderInterface $builder
224
     * @param ConnectionInterface|null $connection
225
     * @param CacheInterface|null $cache
226
     * @return callable
227
     * @throws \yii\base\InvalidConfigException
228
     */
229
    public function httpAddRelay(
230
        CompanyContactsBuilderInterface $builder,
231
        ConnectionInterface $connection = null,
232
        CacheInterface $cache = null
233
    ): callable {
234
        return $this->rawHttpAddRelay(
235
            $builder->getCompanyId(),
236
            $builder->getContactId(),
237
            $connection,
238
            $cache
239
        );
240
    }
241
242
    /**
243
     * @param string $companyId
244
     * @param string $contactId
245
     * @param ConnectionInterface|null $connection
246
     * @param CacheInterface|null $cache
247
     * @return callable
248
     * @throws \yii\base\InvalidConfigException
249
     */
250
    public function rawHttpAddRelay(
251
        string $companyId,
252
        string $contactId,
253
        ConnectionInterface $connection = null,
254
        CacheInterface $cache = null
255
    ): callable {
256
        return (new Add(
257
            $companyId,
258
            $contactId,
259
            $this->resolveConnection($connection),
260
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 254 can be null; however, flipbox\hubspot\traits\C...erTrait::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...
261
            HubSpot::getInstance()->getPsrLogger()
262
        ))->build();
263
    }
264
265
    /**
266
     * @param CompanyContactsBuilderInterface $builder
267
     * @param ConnectionInterface|null $connection
268
     * @param CacheInterface|null $cache
269
     * @return ResponseInterface
270
     * @throws \yii\base\InvalidConfigException
271
     */
272
    public function httpAdd(
273
        CompanyContactsBuilderInterface $builder,
274
        ConnectionInterface $connection = null,
275
        CacheInterface $cache = null
276
    ): ResponseInterface {
277
        return $this->rawHttpAdd(
278
            $builder->getCompanyId(),
279
            $builder->getContactId(),
280
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 274 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...
281
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 275 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...
282
        );
283
    }
284
285
    /**
286
     * @param string $companyId
287
     * @param string $contactId
288
     * @param ConnectionInterface|null $connection
289
     * @param CacheInterface|null $cache
290
     * @return ResponseInterface
291
     * @throws \yii\base\InvalidConfigException
292
     */
293
    public function rawHttpAdd(
294
        string $companyId,
295
        string $contactId,
296
        ConnectionInterface $connection,
297
        CacheInterface $cache
298
    ): ResponseInterface {
299
        return $this->rawHttpAddRelay(
300
            $companyId,
301
            $contactId,
302
            $connection,
303
            $cache
304
        )();
305
    }
306
307
308
    /*******************************************
309
     * REMOVE
310
     *******************************************/
311
312
    /**
313
     * @param CompanyContactsBuilderInterface $builder
314
     * @param ConnectionInterface|null $connection
315
     * @param CacheInterface|null $cache
316
     * @param TransformerCollectionInterface|null $transformer
317
     * @param null $source
318
     * @return mixed
319
     * @throws \yii\base\InvalidConfigException
320
     */
321
    public function remove(
322
        CompanyContactsBuilderInterface $builder,
323
        ConnectionInterface $connection = null,
324
        CacheInterface $cache = null,
325
        TransformerCollectionInterface $transformer = null,
326
        $source = null
327
    ) {
328
        return $this->rawRemove(
329
            $builder->getCompanyId(),
330
            $builder->getContactId(),
331
            $connection,
332
            $cache,
333
            $transformer,
334
            $source
335
        );
336
    }
337
338
    /**
339
     * @param string $companyId
340
     * @param string $contactId
341
     * @param ConnectionInterface|null $connection
342
     * @param CacheInterface|null $cache
343
     * @param TransformerCollectionInterface|null $transformer
344
     * @param null $source
345
     * @return mixed
346
     * @throws \yii\base\InvalidConfigException
347
     */
348
    public function rawRemove(
349
        string $companyId,
350
        string $contactId,
351
        ConnectionInterface $connection = null,
352
        CacheInterface $cache = null,
353
        TransformerCollectionInterface $transformer = null,
354
        $source = null
355
    ) {
356
        return $this->rawRemovePipeline(
357
            $companyId,
358
            $contactId,
359
            $connection,
360
            $cache,
361
            $transformer
362
        )($source);
363
    }
364
365
    /**
366
     * @param CompanyContactsBuilderInterface $builder
367
     * @param ConnectionInterface|null $connection
368
     * @param CacheInterface|null $cache
369
     * @param TransformerCollectionInterface|null $transformer
370
     * @return PipelineBuilderInterface
371
     * @throws \yii\base\InvalidConfigException
372
     */
373
    public function removePipeline(
374
        CompanyContactsBuilderInterface $builder,
375
        ConnectionInterface $connection = null,
376
        CacheInterface $cache = null,
377
        TransformerCollectionInterface $transformer = null
378
    ): PipelineBuilderInterface {
379
        return $this->rawRemovePipeline(
380
            $builder->getCompanyId(),
381
            $builder->getContactId(),
382
            $connection,
383
            $cache,
384
            $transformer
385
        );
386
    }
387
388
    /**
389
     * @param string $companyId
390
     * @param string $contactId
391
     * @param ConnectionInterface|null $connection
392
     * @param CacheInterface|null $cache
393
     * @param TransformerCollectionInterface|null $transformer
394
     * @return PipelineBuilderInterface
395
     * @throws \yii\base\InvalidConfigException
396
     */
397
    public function rawRemovePipeline(
398
        string $companyId,
399
        string $contactId,
400
        ConnectionInterface $connection = null,
401
        CacheInterface $cache = null,
402
        TransformerCollectionInterface $transformer = null
403
    ): PipelineBuilderInterface {
404
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
405
            'resource' => [Remove::class]
406
        ]);
407
408
        return (new Resource(
409
            $this->rawHttpAddRelay(
0 ignored issues
show
Documentation introduced by
$this->rawHttpAddRelay($...d, $connection, $cache) is of type callable, but the function expects a object<Flipbox\Relay\Runner\Runner>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
410
                $companyId,
411
                $contactId,
412
                $connection,
413
                $cache
414
            ),
415
            $transformer,
416
            HubSpot::getInstance()->getPsrLogger()
417
        ));
418
    }
419
420
    /**
421
     * @param CompanyContactsBuilderInterface $builder
422
     * @param ConnectionInterface|null $connection
423
     * @param CacheInterface|null $cache
424
     * @return callable
425
     * @throws \yii\base\InvalidConfigException
426
     */
427
    public function httpRemoveRelay(
428
        CompanyContactsBuilderInterface $builder,
429
        ConnectionInterface $connection = null,
430
        CacheInterface $cache = null
431
    ): callable {
432
        return $this->rawHttpRemoveRelay(
433
            $builder->getCompanyId(),
434
            $builder->getContactId(),
435
            $connection,
436
            $cache
437
        );
438
    }
439
440
    /**
441
     * @param string $companyId
442
     * @param string $contactId
443
     * @param ConnectionInterface|null $connection
444
     * @param CacheInterface|null $cache
445
     * @return callable
446
     * @throws \yii\base\InvalidConfigException
447
     */
448
    public function rawHttpRemoveRelay(
449
        string $companyId,
450
        string $contactId,
451
        ConnectionInterface $connection = null,
452
        CacheInterface $cache = null
453
    ): callable {
454
        return (new Remove(
455
            $companyId,
456
            $contactId,
457
            $this->resolveConnection($connection),
458
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 452 can be null; however, flipbox\hubspot\traits\C...erTrait::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...
459
            HubSpot::getInstance()->getPsrLogger()
460
        ))->build();
461
    }
462
463
    /**
464
     * @param CompanyContactsBuilderInterface $builder
465
     * @param ConnectionInterface|null $connection
466
     * @param CacheInterface|null $cache
467
     * @return ResponseInterface
468
     * @throws \yii\base\InvalidConfigException
469
     */
470
    public function httpRemove(
471
        CompanyContactsBuilderInterface $builder,
472
        ConnectionInterface $connection = null,
473
        CacheInterface $cache = null
474
    ): ResponseInterface {
475
        return $this->rawHttpRemove(
476
            $builder->getCompanyId(),
477
            $builder->getContactId(),
478
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 472 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...
479
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 473 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...
480
        );
481
    }
482
483
    /**
484
     * @param string $companyId
485
     * @param string $contactId
486
     * @param ConnectionInterface|null $connection
487
     * @param CacheInterface|null $cache
488
     * @return ResponseInterface
489
     * @throws \yii\base\InvalidConfigException
490
     */
491
    public function rawHttpRemove(
492
        string $companyId,
493
        string $contactId,
494
        ConnectionInterface $connection,
495
        CacheInterface $cache
496
    ): ResponseInterface {
497
        return $this->rawHttpRemoveRelay(
498
            $companyId,
499
            $contactId,
500
            $connection,
501
            $cache
502
        )();
503
    }
504
}
505