This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace prgTW\BaseCRM\Transport; |
||
4 | |||
5 | use GuzzleHttp\Exception\BadResponseException; |
||
6 | use GuzzleHttp\Exception\ClientException; |
||
7 | use GuzzleHttp\Exception\ServerException; |
||
8 | use GuzzleHttp\Message\ResponseInterface; |
||
9 | use prgTW\BaseCRM\Client\ClientInterface; |
||
10 | use prgTW\BaseCRM\Client\GuzzleClient; |
||
11 | use prgTW\BaseCRM\Exception\RepresentationErrorException; |
||
12 | use prgTW\BaseCRM\Utils\Convert; |
||
13 | |||
14 | class Transport |
||
15 | { |
||
16 | const TOKEN_FUTUERSIMPLE_NAME = 'X-Futuresimple-Token'; |
||
17 | const TOKEN_PIPEJUMP_NAME = 'X-Pipejump-Auth'; |
||
18 | |||
19 | /** @var ClientInterface */ |
||
20 | private $client; |
||
21 | |||
22 | /** @var string */ |
||
23 | private $token; |
||
24 | |||
25 | /** @var ResponseInterface */ |
||
26 | protected $lastResponse; |
||
27 | |||
28 | /** |
||
29 | * @param string $token |
||
30 | * @param ClientInterface $client |
||
0 ignored issues
–
show
|
|||
31 | */ |
||
32 | public function __construct($token = '', ClientInterface $client = null) |
||
33 | { |
||
34 | $this->client = null !== $client ? $client : new GuzzleClient; |
||
0 ignored issues
–
show
It seems like
null !== $client ? $clie...M\Client\GuzzleClient() can also be of type object<prgTW\BaseCRM\Client\GuzzleClient> . However, the property $client is declared as type object<prgTW\BaseCRM\Client\ClientInterface> . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
35 | $this->token = $token; |
||
36 | $this->lastResponse = null; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param string $uri |
||
41 | * @param string $key |
||
0 ignored issues
–
show
Should the type for parameter
$key not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
42 | * @param array $options |
||
43 | * |
||
44 | * @return array|bool |
||
45 | */ |
||
46 | View Code Duplication | public function get($uri, $key = null, array $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
47 | { |
||
48 | $options = $this->getOptions($options); |
||
49 | $response = $this->client->request('GET', $this->getUri($uri), $options); |
||
50 | $decoded = $this->processResponse($response, $key); |
||
51 | |||
52 | return $decoded; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $uri |
||
57 | * @param string $key |
||
0 ignored issues
–
show
Should the type for parameter
$key not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
58 | * @param array $options |
||
59 | * |
||
60 | * @return array|bool |
||
61 | */ |
||
62 | View Code Duplication | public function post($uri, $key = null, array $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
63 | { |
||
64 | $options = $this->getOptions($options); |
||
65 | $response = $this->client->request('POST', $this->getUri($uri), $options); |
||
66 | $decoded = $this->processResponse($response, $key); |
||
67 | |||
68 | return $decoded; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param string $uri |
||
73 | * @param string $key |
||
0 ignored issues
–
show
Should the type for parameter
$key not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
74 | * @param array $options |
||
75 | * |
||
76 | * @return array|bool |
||
77 | */ |
||
78 | View Code Duplication | public function put($uri, $key = null, array $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
79 | { |
||
80 | $options = $this->getOptions($options); |
||
81 | $response = $this->client->request('PUT', $this->getUri($uri), $options); |
||
82 | $decoded = $this->processResponse($response, $key); |
||
83 | |||
84 | return $decoded; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param string $uri |
||
89 | * @param string $key |
||
0 ignored issues
–
show
Should the type for parameter
$key not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
90 | * @param array $options |
||
91 | * |
||
92 | * @return array|bool |
||
93 | */ |
||
94 | View Code Duplication | public function delete($uri, $key = null, array $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
95 | { |
||
96 | $options = $this->getOptions($options); |
||
97 | $response = $this->client->request('DELETE', $this->getUri($uri), $options); |
||
98 | $decoded = $this->processResponse($response, $key); |
||
99 | |||
100 | return $decoded; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param ResponseInterface $response |
||
105 | * @param string $key |
||
0 ignored issues
–
show
Should the type for parameter
$key not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
106 | * |
||
107 | * @throws RepresentationErrorException on 422 response |
||
108 | * @throws ClientException on 4xx errors |
||
109 | * @throws ServerException on 5xx errors |
||
110 | * @throws BadResponseException when key is not found in response data |
||
111 | * @return array|bool |
||
112 | */ |
||
113 | private function processResponse(ResponseInterface $response, $key = null) |
||
114 | { |
||
115 | $status = $response->getStatusCode(); |
||
116 | if (204 == $status) |
||
117 | { |
||
118 | return true; |
||
119 | } |
||
120 | |||
121 | $decoded = $response->json(); |
||
122 | $decoded = Convert::objectToArray($decoded); |
||
123 | |||
124 | if (422 == $status) |
||
125 | { |
||
126 | //@codeCoverageIgnoreStart |
||
127 | throw new RepresentationErrorException('', $this->client->getLastRequest(), $response); |
||
0 ignored issues
–
show
The method
getLastRequest() does not exist on prgTW\BaseCRM\Client\ClientInterface . Did you maybe mean request() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
128 | //@codeCoverageIgnoreEnd |
||
129 | } |
||
130 | |||
131 | if (200 <= $status && 300 > $status) |
||
132 | { |
||
133 | $this->lastResponse = $response; |
||
134 | |||
135 | if (null === $key) |
||
136 | { |
||
137 | return $decoded; |
||
0 ignored issues
–
show
The return type of
return $decoded; (array|integer|double|string|null|boolean|resource ) is incompatible with the return type documented by prgTW\BaseCRM\Transport\Transport::processResponse of type array|boolean .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
138 | } |
||
139 | |||
140 | if (false === array_key_exists($key, $decoded)) |
||
141 | { |
||
142 | //@codeCoverageIgnoreStart |
||
143 | $message = sprintf('Key "%s" not found in data', $key); |
||
144 | throw new BadResponseException($message, $this->client->getLastRequest(), $response); |
||
0 ignored issues
–
show
The method
getLastRequest() does not exist on prgTW\BaseCRM\Client\ClientInterface . Did you maybe mean request() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
145 | //@codeCoverageIgnoreEnd |
||
146 | } |
||
147 | |||
148 | return $decoded[$key]; |
||
149 | } |
||
150 | |||
151 | //@codeCoverageIgnoreStart |
||
152 | throw BadResponseException::create($this->client->getLastRequest(), $response); |
||
0 ignored issues
–
show
The method
getLastRequest() does not exist on prgTW\BaseCRM\Client\ClientInterface . Did you maybe mean request() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
153 | //@codeCoverageIgnoreEnd |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param string $uri |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | protected function getUri($uri) |
||
162 | { |
||
163 | return $uri . '.json'; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @param array $options |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | private function getOptions(array $options) |
||
172 | { |
||
173 | $options = array_merge_recursive([ |
||
174 | 'headers' => [ |
||
175 | self::TOKEN_PIPEJUMP_NAME => $this->token, |
||
176 | self::TOKEN_FUTUERSIMPLE_NAME => $this->token, |
||
177 | ], |
||
178 | ], $options); |
||
179 | |||
180 | return $options; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getToken() |
||
187 | { |
||
188 | return $this->token; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string $token |
||
193 | * |
||
194 | * @return $this |
||
195 | */ |
||
196 | public function setToken($token) |
||
197 | { |
||
198 | $this->token = $token; |
||
199 | |||
200 | return $this; |
||
201 | } |
||
202 | } |
||
203 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.