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

ContactListContacts::rawReadPipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 0
cts 10
cp 0
rs 9.6
cc 1
nc 1
nop 4
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\ContactListContactsBuilder;
12
use flipbox\hubspot\builders\ObjectBuilderInterface;
13
use flipbox\hubspot\connections\ConnectionInterface;
14
use flipbox\hubspot\criteria\ContactListContactsCriteria;
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\AddObjectTrait;
22
use flipbox\hubspot\services\resources\traits\ReadObjectTrait;
23
use flipbox\hubspot\services\resources\traits\RemoveObjectTrait;
24
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
25
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Contacts\Add;
26
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Contacts\All;
27
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Contacts\Remove;
28
use League\Pipeline\PipelineBuilderInterface;
29
use Psr\SimpleCache\CacheInterface;
30
use yii\base\Component;
31
32
/**
33
 * @author Flipbox Factory <[email protected]>
34
 * @since 1.0.0
35
 */
36
class ContactListContacts extends Component
37
{
38
    use ReadObjectTrait,
39
        AddObjectTrait,
40
        RemoveObjectTrait;
41
42
    /**
43
     * The HubSpot Resource name
44
     */
45
    const HUBSPOT_RESOURCE = 'contactListContacts';
46
47
    /**
48
     * @param array $config
49
     * @return ObjectCriteriaInterface
50
     */
51
    public function getCriteria(array $config = []): ObjectCriteriaInterface
52
    {
53
        return new ContactListContactsCriteria($config);
54
    }
55
56
    /**
57
     * @param array $config
58
     * @return ObjectBuilderInterface
59
     */
60
    public function getBuilder(array $config = []): ObjectBuilderInterface
61
    {
62
        return new ContactListContactsBuilder($config);
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    protected static function readRelayBuilderClass(): string
69
    {
70
        return All::class;
71
    }
72
73
    /*******************************************
74
     * ADD
75
     *******************************************/
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function rawAddPipeline(
81
        string $id,
82
        array $payload,
83
        ConnectionInterface $connection = null,
84
        CacheInterface $cache = null,
85
        TransformerCollectionInterface $transformer = null
86
    ): PipelineBuilderInterface {
87
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
88
            'resource' => [Add::class]
89
        ]);
90
91
        return (new Resource(
92
            $this->rawHttpAddRelay(
93
                $id,
94
                $payload,
95
                $connection,
96
                $cache
97
            ),
98
            $transformer,
99
            HubSpot::getInstance()->getPsrLogger()
100
        ));
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function rawHttpAddRelay(
107
        string $id,
108
        array $payload,
109
        ConnectionInterface $connection = null,
110
        CacheInterface $cache = null
111
    ): callable {
112
        return (new Add(
113
            $id,
114
            $payload,
115
            ConnectionHelper::resolveConnection($connection),
116
            CacheHelper::resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 110 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...
117
            HubSpot::getInstance()->getPsrLogger()
118
        ))->build();
119
    }
120
121
    /*******************************************
122
     * REMOVE
123
     *******************************************/
124
125
    /**
126
     * @inheritdoc
127
     */
128
    public function rawRemovePipeline(
129
        string $id,
130
        array $payload,
131
        ConnectionInterface $connection = null,
132
        CacheInterface $cache = null,
133
        TransformerCollectionInterface $transformer = null
134
    ): PipelineBuilderInterface {
135
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
136
            'resource' => [Remove::class]
137
        ]);
138
139
        return (new Resource(
140
            $this->rawHttpRemoveRelay(
141
                $id,
142
                $payload,
143
                $connection,
144
                $cache
145
            ),
146
            $transformer,
147
            HubSpot::getInstance()->getPsrLogger()
148
        ));
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154
    public function rawHttpRemoveRelay(
155
        string $id,
156
        array $payload,
157
        ConnectionInterface $connection = null,
158
        CacheInterface $cache = null
159
    ): callable {
160
        return (new Remove(
161
            $id,
162
            $payload,
163
            ConnectionHelper::resolveConnection($connection),
164
            CacheHelper::resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 158 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...
165
            HubSpot::getInstance()->getPsrLogger()
166
        ))->build();
167
    }
168
}
169