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

ContactLists::updatePipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 14
cp 0
rs 9.52
c 0
b 0
f 0
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\ContactListBuilder;
12
use flipbox\hubspot\builders\ObjectBuilderInterface;
13
use flipbox\hubspot\connections\ConnectionInterface;
14
use flipbox\hubspot\criteria\ContactListCriteria;
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\traits\CacheResolverTrait;
20
use flipbox\hubspot\traits\ConnectionResolverTrait;
21
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
22
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Create;
23
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Delete;
24
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Read;
25
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Update;
26
use League\Pipeline\PipelineBuilderInterface;
27
use Psr\SimpleCache\CacheInterface;
28
use yii\base\Component;
29
30
/**
31
 * @author Flipbox Factory <[email protected]>
32
 * @since 1.0.0
33
 */
34
class ContactLists extends Component
35
{
36
    use ConnectionResolverTrait,
37
        CacheResolverTrait,
38
        traits\SyncByElementTrait,
39
        traits\ReadObjectTrait,
40
        traits\UpsertObjectTrait,
41
        traits\DeleteObjectTrait;
42
43
    /**
44
     * The HubSpot Resource name
45
     */
46
    const HUBSPOT_RESOURCE = 'contactLists';
47
48
    /**
49
     * @param array $config
50
     * @return ObjectCriteriaInterface
51
     */
52
    public function getCriteria(array $config = []): ObjectCriteriaInterface
53
    {
54
        return new ContactListCriteria($config);
55
    }
56
57
    /**
58
     * @param array $config
59
     * @return ObjectBuilderInterface
60
     */
61
    public function getBuilder(array $config = []): ObjectBuilderInterface
62
    {
63
        return new ContactListBuilder($config);
64
    }
65
66
    /*******************************************
67
     * READ
68
     *******************************************/
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function rawReadPipeline(
74
        string $id,
75
        ConnectionInterface $connection = null,
76
        CacheInterface $cache = null,
77
        TransformerCollectionInterface $transformer = null
78
    ): PipelineBuilderInterface {
79
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
80
            'resource' => [Read::class]
81
        ]);
82
83
        return (new Resource(
84
            $this->rawHttpReadRelay(
85
                $id,
86
                $connection,
87
                $cache
88
            ),
89
            $transformer,
90
            HubSpot::getInstance()->getPsrLogger()
91
        ));
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97
    public function rawHttpReadRelay(
98
        string $id,
99
        ConnectionInterface $connection = null,
100
        CacheInterface $cache = null
101
    ): callable {
102
        return (new Read(
103
            $id,
104
            $this->resolveConnection($connection),
105
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 100 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...
106
            HubSpot::getInstance()->getPsrLogger()
107
        ))->build();
108
    }
109
110
111
    /*******************************************
112
     * CREATE
113
     *******************************************/
114
115
    /**
116
     * @inheritdoc
117
     */
118
    public function rawCreatePipeline(
119
        array $payload,
120
        ConnectionInterface $connection = null,
121
        TransformerCollectionInterface $transformer = null
122
    ): PipelineBuilderInterface {
123
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
124
            'resource' => [Create::class]
125
        ]);
126
127
        return (new Resource(
128
            $this->rawHttpCreateRelay(
129
                $payload,
130
                $connection
131
            ),
132
            $transformer,
133
            HubSpot::getInstance()->getPsrLogger()
134
        ));
135
    }
136
137
    /**
138
     * @inheritdoc
139
     */
140
    public function rawHttpCreateRelay(
141
        array $payload,
142
        ConnectionInterface $connection = null
143
    ): callable {
144
        return (new Create(
145
            $payload,
146
            $this->resolveConnection($connection),
147
            HubSpot::getInstance()->getPsrLogger()
148
        ))->build();
149
    }
150
151
    /*******************************************
152
     * UPDATE
153
     *******************************************/
154
155
    /**
156
     * @inheritdoc
157
     */
158
    public function rawUpdatePipeline(
159
        string $id,
160
        array $payload,
161
        ConnectionInterface $connection = null,
162
        CacheInterface $cache = null,
163
        TransformerCollectionInterface $transformer = null
164
    ): PipelineBuilderInterface {
165
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
166
            'resource' => [Update::class]
167
        ]);
168
169
        return (new Resource(
170
            $this->rawHttpUpdateRelay(
171
                $id,
172
                $payload,
173
                $connection,
174
                $cache
175
            ),
176
            $transformer,
177
            HubSpot::getInstance()->getPsrLogger()
178
        ));
179
    }
180
181
    /**
182
     * @inheritdoc
183
     */
184
    public function rawHttpUpdateRelay(
185
        string $id,
186
        array $payload,
187
        ConnectionInterface $connection = null,
188
        CacheInterface $cache = null
189
    ): callable {
190
        return (new Update(
191
            $id,
192
            $payload,
193
            $this->resolveConnection($connection),
194
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 188 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...
195
            HubSpot::getInstance()->getPsrLogger()
196
        ))->build();
197
    }
198
199
    /*******************************************
200
     * DELETE
201
     *******************************************/
202
203
    /**
204
     * @inheritdoc
205
     */
206
    public function rawDeletePipeline(
207
        string $id,
208
        ConnectionInterface $connection = null,
209
        CacheInterface $cache = null,
210
        TransformerCollectionInterface $transformer = null
211
    ): PipelineBuilderInterface {
212
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
213
            'resource' => [Delete::class]
214
        ]);
215
216
        return (new Resource(
217
            $this->rawHttpDeleteRelay(
218
                $id,
219
                $connection,
220
                $cache
221
            ),
222
            $transformer,
223
            HubSpot::getInstance()->getPsrLogger()
224
        ));
225
    }
226
227
    /**
228
     * @inheritdoc
229
     */
230
    public function rawHttpDeleteRelay(
231
        string $id,
232
        ConnectionInterface $connection = null,
233
        CacheInterface $cache = null
234
    ): callable {
235
        return (new Delete(
236
            $id,
237
            $this->resolveConnection($connection),
238
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 233 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...
239
            HubSpot::getInstance()->getPsrLogger()
240
        ))->build();
241
    }
242
}
243