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

DeleteObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 158
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 158
c 0
b 0
f 0
ccs 0
cts 35
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
rawDeletePipeline() 0 6 ?
rawHttpDeleteRelay() 0 5 ?
A delete() 0 15 1
A rawDelete() 0 14 1
A deletePipeline() 0 13 1
A httpDeleteRelay() 0 11 1
A httpDelete() 0 11 1
A rawHttpDelete() 0 11 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 DeleteObjectTrait
23
{
24
    /**
25
     * @param string $id
26
     * @param ConnectionInterface|null $connection
27
     * @param CacheInterface|null $cache
28
     * @param TransformerCollectionInterface|null $transformer
29
     * @return PipelineBuilderInterface
30
     * @throws \yii\base\InvalidConfigException
31
     */
32
    public abstract function rawDeletePipeline(
33
        string $id,
34
        ConnectionInterface $connection = null,
35
        CacheInterface $cache = null,
36
        TransformerCollectionInterface $transformer = null
37
    ): PipelineBuilderInterface;
38
39
    /**
40
     * @param string $id
41
     * @param ConnectionInterface|null $connection
42
     * @param CacheInterface|null $cache
43
     * @return callable
44
     * @throws \yii\base\InvalidConfigException
45
     */
46
    public abstract function rawHttpDeleteRelay(
47
        string $id,
48
        ConnectionInterface $connection = null,
49
        CacheInterface $cache = null
50
    ): callable;
51
52
    /**
53
     * @param ObjectBuilderInterface $builder
54
     * @param ConnectionInterface|null $connection
55
     * @param CacheInterface|null $cache
56
     * @param TransformerCollectionInterface|null $transformer
57
     * @param null $source
58
     * @return mixed
59
     * @throws \yii\base\InvalidConfigException
60
     */
61
    public function delete(
62
        ObjectBuilderInterface $builder,
63
        ConnectionInterface $connection = null,
64
        CacheInterface $cache = null,
65
        TransformerCollectionInterface $transformer = null,
66
        $source = null
67
    ) {
68
        return $this->rawDelete(
69
            $builder->getId(),
70
            $connection,
71
            $cache,
72
            $transformer,
73
            $source
74
        );
75
    }
76
77
    /**
78
     * @param string $id
79
     * @param ConnectionInterface|null $connection
80
     * @param CacheInterface|null $cache
81
     * @param TransformerCollectionInterface|null $transformer
82
     * @param null $source
83
     * @return mixed
84
     * @throws \yii\base\InvalidConfigException
85
     */
86
    public function rawDelete(
87
        string $id,
88
        ConnectionInterface $connection = null,
89
        CacheInterface $cache = null,
90
        TransformerCollectionInterface $transformer = null,
91
        $source = null
92
    ) {
93
        return $this->rawDeletePipeline(
94
            $id,
95
            $connection,
96
            $cache,
97
            $transformer
98
        )($source);
99
    }
100
101
    /**
102
     * @param ObjectBuilderInterface $builder
103
     * @param ConnectionInterface|null $connection
104
     * @param CacheInterface|null $cache
105
     * @param TransformerCollectionInterface|null $transformer
106
     * @return PipelineBuilderInterface
107
     * @throws \yii\base\InvalidConfigException
108
     */
109
    public function deletePipeline(
110
        ObjectBuilderInterface $builder,
111
        ConnectionInterface $connection = null,
112
        CacheInterface $cache = null,
113
        TransformerCollectionInterface $transformer = null
114
    ): PipelineBuilderInterface {
115
        return $this->rawDeletePipeline(
116
            $builder->getId(),
117
            $connection,
118
            $cache,
119
            $transformer
120
        );
121
    }
122
123
    /**
124
     * @param ObjectBuilderInterface $builder
125
     * @param ConnectionInterface|null $connection
126
     * @param CacheInterface|null $cache
127
     * @return callable
128
     * @throws \yii\base\InvalidConfigException
129
     */
130
    public function httpDeleteRelay(
131
        ObjectBuilderInterface $builder,
132
        ConnectionInterface $connection = null,
133
        CacheInterface $cache = null
134
    ): callable {
135
        return $this->rawHttpDeleteRelay(
136
            $builder->getId(),
137
            $connection,
138
            $cache
139
        );
140
    }
141
142
    /**
143
     * @param ObjectBuilderInterface $builder
144
     * @param ConnectionInterface|null $connection
145
     * @param CacheInterface|null $cache
146
     * @return ResponseInterface
147
     * @throws \yii\base\InvalidConfigException
148
     */
149
    public function httpDelete(
150
        ObjectBuilderInterface $builder,
151
        ConnectionInterface $connection = null,
152
        CacheInterface $cache = null
153
    ): ResponseInterface {
154
        return $this->rawHttpDelete(
155
            $builder->getId(),
156
            $connection,
0 ignored issues
show
Bug introduced by
It seems like $connection defined by parameter $connection on line 151 can be null; however, flipbox\hubspot\services...tTrait::rawHttpDelete() 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...
157
            $cache
0 ignored issues
show
Bug introduced by
It seems like $cache defined by parameter $cache on line 152 can be null; however, flipbox\hubspot\services...tTrait::rawHttpDelete() 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...
158
        );
159
    }
160
161
    /**
162
     * @param string $id
163
     * @param ConnectionInterface|null $connection
164
     * @param CacheInterface|null $cache
165
     * @return ResponseInterface
166
     * @throws \yii\base\InvalidConfigException
167
     */
168
    public function rawHttpDelete(
169
        string $id,
170
        ConnectionInterface $connection,
171
        CacheInterface $cache
172
    ): ResponseInterface {
173
        return $this->rawHttpDeleteRelay(
174
            $id,
175
            $connection,
176
            $cache
177
        )();
178
    }
179
}
180