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

ContactListContacts::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\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\TransformerHelper;
17
use flipbox\hubspot\HubSpot;
18
use flipbox\hubspot\pipeline\Resource;
19
use flipbox\hubspot\services\resources\traits\AddObjectTrait;
20
use flipbox\hubspot\services\resources\traits\ReadObjectTrait;
21
use flipbox\hubspot\services\resources\traits\RemoveObjectTrait;
22
use flipbox\hubspot\traits\CacheResolverTrait;
23
use flipbox\hubspot\traits\ConnectionResolverTrait;
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 ConnectionResolverTrait,
39
        CacheResolverTrait,
40
        ReadObjectTrait,
41
        AddObjectTrait,
42
        RemoveObjectTrait;
43
44
    /**
45
     * The HubSpot Resource name
46
     */
47
    const HUBSPOT_RESOURCE = 'contactListContacts';
48
49
    /**
50
     * @param array $config
51
     * @return ObjectCriteriaInterface
52
     */
53
    public function getCriteria(array $config = []): ObjectCriteriaInterface
54
    {
55
        return new ContactListContactsCriteria($config);
56
    }
57
58
    /**
59
     * @param array $config
60
     * @return ObjectBuilderInterface
61
     */
62
    public function getBuilder(array $config = []): ObjectBuilderInterface
63
    {
64
        return new ContactListContactsBuilder($config);
65
    }
66
67
    /*******************************************
68
     * READ
69
     *******************************************/
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function rawReadPipeline(
75
        string $id,
76
        ConnectionInterface $connection = null,
77
        CacheInterface $cache = null,
78
        TransformerCollectionInterface $transformer = null
79
    ): PipelineBuilderInterface {
80
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
81
            'resource' => [All::class]
82
        ]);
83
84
        return (new Resource(
85
            $this->rawHttpReadRelay(
86
                $id,
87
                $connection,
88
                $cache
89
            ),
90
            $transformer,
91
            HubSpot::getInstance()->getPsrLogger()
92
        ));
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function rawHttpReadRelay(
99
        string $id,
100
        ConnectionInterface $connection = null,
101
        CacheInterface $cache = null
102
    ): callable {
103
        return (new All(
104
            $id,
105
            $this->resolveConnection($connection),
106
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 101 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...
107
            HubSpot::getInstance()->getPsrLogger()
108
        ))->build();
109
    }
110
111
    /*******************************************
112
     * ADD
113
     *******************************************/
114
115
    /**
116
     * @inheritdoc
117
     */
118
    public function rawAddPipeline(
119
        string $id,
120
        array $payload,
121
        ConnectionInterface $connection = null,
122
        CacheInterface $cache = null,
123
        TransformerCollectionInterface $transformer = null
124
    ): PipelineBuilderInterface {
125
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
126
            'resource' => [Add::class]
127
        ]);
128
129
        return (new Resource(
130
            $this->rawHttpAddRelay(
131
                $id,
132
                $payload,
133
                $connection,
134
                $cache
135
            ),
136
            $transformer,
137
            HubSpot::getInstance()->getPsrLogger()
138
        ));
139
    }
140
141
    /**
142
     * @inheritdoc
143
     */
144
    public function rawHttpAddRelay(
145
        string $id,
146
        array $payload,
147
        ConnectionInterface $connection = null,
148
        CacheInterface $cache = null
149
    ): callable {
150
        return (new Add(
151
            $id,
152
            $payload,
153
            $this->resolveConnection($connection),
154
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 148 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...
155
            HubSpot::getInstance()->getPsrLogger()
156
        ))->build();
157
    }
158
159
    /*******************************************
160
     * REMOVE
161
     *******************************************/
162
163
    /**
164
     * @inheritdoc
165
     */
166
    public function rawRemovePipeline(
167
        string $id,
168
        array $payload,
169
        ConnectionInterface $connection = null,
170
        CacheInterface $cache = null,
171
        TransformerCollectionInterface $transformer = null
172
    ): PipelineBuilderInterface {
173
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
174
            'resource' => [Remove::class]
175
        ]);
176
177
        return (new Resource(
178
            $this->rawHttpRemoveRelay(
179
                $id,
180
                $payload,
181
                $connection,
182
                $cache
183
            ),
184
            $transformer,
185
            HubSpot::getInstance()->getPsrLogger()
186
        ));
187
    }
188
189
    /**
190
     * @inheritdoc
191
     */
192
    public function rawHttpRemoveRelay(
193
        string $id,
194
        array $payload,
195
        ConnectionInterface $connection = null,
196
        CacheInterface $cache = null
197
    ): callable {
198
        return (new Remove(
199
            $id,
200
            $payload,
201
            $this->resolveConnection($connection),
202
            $this->resolveCache($cache),
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 196 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...
203
            HubSpot::getInstance()->getPsrLogger()
204
        ))->build();
205
    }
206
}
207