1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FAPI\Sylius\Api; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Tobias Nyholm <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
final class Custom extends HttpApi |
16
|
|
|
{ |
17
|
|
View Code Duplication |
public function get(string $path, array $params = [], array $requestHeaders = [], string $class = '') |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$response = parent::httpGet($path, $params, $requestHeaders); |
|
|
|
|
20
|
|
|
if (!$this->hydrator) { |
21
|
|
|
return $response; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
return $this->hydrator->hydrate($response, $class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function post(string $path, array $params = [], array $requestHeaders = [], string $class = '') |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$response = parent::httpPost($path, $params, $requestHeaders); |
|
|
|
|
30
|
|
|
if (!$this->hydrator) { |
31
|
|
|
return $response; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $this->hydrator->hydrate($response, $class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function postRaw(string $path, $body, array $requestHeaders = [], string $class = '') |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$response = parent::httpPostRaw($path, $body, $requestHeaders); |
|
|
|
|
40
|
|
|
if (!$this->hydrator) { |
41
|
|
|
return $response; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->hydrator->hydrate($response, $class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function put(string $path, array $params = [], array $requestHeaders = [], string $class = '') |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$response = parent::httpPut($path, $params, $requestHeaders); |
|
|
|
|
50
|
|
|
if (!$this->hydrator) { |
51
|
|
|
return $response; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->hydrator->hydrate($response, $class); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function patch(string $path, array $params = [], array $requestHeaders = [], string $class = '') |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$response = parent::httpPatch($path, $params, $requestHeaders); |
|
|
|
|
60
|
|
|
if (!$this->hydrator) { |
61
|
|
|
return $response; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->hydrator->hydrate($response, $class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function delete(string $path, array $params = [], array $requestHeaders = [], string $class = '') |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$response = parent::httpDelete($path, $params, $requestHeaders); |
|
|
|
|
70
|
|
|
if (!$this->hydrator) { |
71
|
|
|
return $response; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->hydrator->hydrate($response, $class); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.