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

AddObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 172
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 172
c 0
b 0
f 0
ccs 0
cts 41
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
rawAddPipeline() 0 7 ?
rawHttpAddRelay() 0 6 ?
A add() 0 16 1
A rawAdd() 0 16 1
A addPipeline() 0 14 1
A httpAddRelay() 0 12 1
A httpAdd() 0 12 1
A rawHttpAdd() 0 13 1
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\traits;
10
11
use flipbox\hubspot\builders\ObjectBuilderInterface;
12
use flipbox\hubspot\connections\ConnectionInterface;
13
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
14
use League\Pipeline\PipelineBuilderInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use Psr\SimpleCache\CacheInterface;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
trait AddObjectTrait
23
{
24
    /**
25
     * @param string $id
26
     * @param array $payload
27
     * @param ConnectionInterface|null $connection
28
     * @param CacheInterface|null $cache
29
     * @param TransformerCollectionInterface|null $transformer
30
     * @return PipelineBuilderInterface
31
     * @throws \yii\base\InvalidConfigException
32
     */
33
    public abstract function rawAddPipeline(
34
        string $id,
35
        array $payload,
36
        ConnectionInterface $connection = null,
37
        CacheInterface $cache = null,
38
        TransformerCollectionInterface $transformer = null
39
    ): PipelineBuilderInterface;
40
41
    /**
42
     * @param string $id
43
     * @param array $payload
44
     * @param ConnectionInterface|null $connection
45
     * @param CacheInterface|null $cache
46
     * @return callable
47
     * @throws \yii\base\InvalidConfigException
48
     */
49
    public abstract function rawHttpAddRelay(
50
        string $id,
51
        array $payload,
52
        ConnectionInterface $connection = null,
53
        CacheInterface $cache = null
54
    ): callable;
55
56
    /**
57
     * @param ObjectBuilderInterface $builder
58
     * @param ConnectionInterface|null $connection
59
     * @param CacheInterface|null $cache
60
     * @param TransformerCollectionInterface|null $transformer
61
     * @param null $source
62
     * @return mixed
63
     * @throws \yii\base\InvalidConfigException
64
     */
65
    public function add(
66
        ObjectBuilderInterface $builder,
67
        ConnectionInterface $connection = null,
68
        CacheInterface $cache = null,
69
        TransformerCollectionInterface $transformer = null,
70
        $source = null
71
    ) {
72
        return $this->rawAdd(
73
            $builder->getId(),
74
            $builder->getPayload(),
75
            $connection,
76
            $cache,
77
            $transformer,
78
            $source
79
        );
80
    }
81
82
    /**
83
     * @param string $id
84
     * @param array $payload
85
     * @param ConnectionInterface|null $connection
86
     * @param CacheInterface|null $cache
87
     * @param TransformerCollectionInterface|null $transformer
88
     * @param null $source
89
     * @return mixed
90
     * @throws \yii\base\InvalidConfigException
91
     */
92
    public function rawAdd(
93
        string $id,
94
        array $payload,
95
        ConnectionInterface $connection = null,
96
        CacheInterface $cache = null,
97
        TransformerCollectionInterface $transformer = null,
98
        $source = null
99
    ) {
100
        return $this->rawAddPipeline(
101
            $id,
102
            $payload,
103
            $connection,
104
            $cache,
105
            $transformer
106
        )($source);
107
    }
108
109
    /**
110
     * @param ObjectBuilderInterface $builder
111
     * @param ConnectionInterface|null $connection
112
     * @param CacheInterface|null $cache
113
     * @param TransformerCollectionInterface|null $transformer
114
     * @return PipelineBuilderInterface
115
     * @throws \yii\base\InvalidConfigException
116
     */
117
    public function addPipeline(
118
        ObjectBuilderInterface $builder,
119
        ConnectionInterface $connection = null,
120
        CacheInterface $cache = null,
121
        TransformerCollectionInterface $transformer = null
122
    ): PipelineBuilderInterface {
123
        return $this->rawAddPipeline(
124
            $builder->getId(),
125
            $builder->getPayload(),
126
            $connection,
127
            $cache,
128
            $transformer
129
        );
130
    }
131
132
    /**
133
     * @param ObjectBuilderInterface $builder
134
     * @param ConnectionInterface|null $connection
135
     * @param CacheInterface|null $cache
136
     * @return callable
137
     * @throws \yii\base\InvalidConfigException
138
     */
139
    public function httpAddRelay(
140
        ObjectBuilderInterface $builder,
141
        ConnectionInterface $connection = null,
142
        CacheInterface $cache = null
143
    ): callable {
144
        return $this->rawHttpAddRelay(
145
            $builder->getId(),
146
            $builder->getPayload(),
147
            $connection,
148
            $cache
149
        );
150
    }
151
152
    /**
153
     * @param ObjectBuilderInterface $builder
154
     * @param ConnectionInterface|null $connection
155
     * @param CacheInterface|null $cache
156
     * @return ResponseInterface
157
     * @throws \yii\base\InvalidConfigException
158
     */
159
    public function httpAdd(
160
        ObjectBuilderInterface $builder,
161
        ConnectionInterface $connection = null,
162
        CacheInterface $cache = null
163
    ): ResponseInterface {
164
        return $this->rawHttpAdd(
165
            $builder->getId(),
166
            $builder->getPayload(),
167
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 161 can be null; however, flipbox\hubspot\services...jectTrait::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...
168
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 162 can be null; however, flipbox\hubspot\services...jectTrait::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...
169
        );
170
    }
171
172
    /**
173
     * @param string $id
174
     * @param array $payload
175
     * @param ConnectionInterface|null $connection
176
     * @param CacheInterface|null $cache
177
     * @return ResponseInterface
178
     * @throws \yii\base\InvalidConfigException
179
     */
180
    public function rawHttpAdd(
181
        string $id,
182
        array $payload,
183
        ConnectionInterface $connection,
184
        CacheInterface $cache
185
    ): ResponseInterface {
186
        return $this->rawHttpAddRelay(
187
            $id,
188
            $payload,
189
            $connection,
190
            $cache
191
        )();
192
    }
193
}
194