1 | <?php |
||
2 | |||
3 | namespace ZpgRtf\Methods; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | |||
7 | /** |
||
8 | * The listing method allows you to list, update or delete listings on the ZPG rtf. |
||
9 | */ |
||
10 | abstract class AbstractMethod |
||
11 | { |
||
12 | /** @var string */ |
||
13 | const BASE_URI = 'https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/'; |
||
14 | |||
15 | /** @var Client */ |
||
16 | private $client; |
||
17 | |||
18 | /** |
||
19 | * @param string $certificate |
||
20 | */ |
||
21 | 2 | public function __construct($certificate) |
|
22 | { |
||
23 | 2 | $this->client = new Client([ |
|
24 | 2 | 'base_uri' => self::BASE_URI, |
|
25 | 2 | 'cert' => $certificate, |
|
26 | ]); |
||
27 | 2 | } |
|
28 | |||
29 | /** |
||
30 | * @return Client |
||
31 | */ |
||
32 | 1 | public function getClient() |
|
33 | { |
||
34 | 1 | return $this->client; |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param Client $client |
||
39 | * |
||
40 | * @return static |
||
41 | */ |
||
42 | 2 | public function setClient(Client $client) |
|
43 | { |
||
44 | 2 | $this->client = $client; |
|
45 | |||
46 | 2 | return $this; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $schemaUri |
||
51 | * @param string $uri |
||
52 | * @param \JsonSerializable $object |
||
53 | * |
||
54 | * @return \GuzzleHttp\Psr7\Response |
||
55 | * |
||
56 | * @throws \Exception If validation fails. Needs a custom exception type. |
||
57 | */ |
||
58 | View Code Duplication | protected function validateAndSend($schemaUri, $uri, \JsonSerializable $object) |
|
0 ignored issues
–
show
|
|||
59 | { |
||
60 | $payload = json_encode($object); |
||
61 | $schema = Dereferencer::draft4()->dereference($schemaUri); |
||
0 ignored issues
–
show
The type
ZpgRtf\Methods\Dereferencer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
62 | $validator = new Validator(json_decode($payload), $schema); |
||
0 ignored issues
–
show
The type
ZpgRtf\Methods\Validator was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
63 | |||
64 | if ($validator->fails()) { |
||
65 | throw new \Exception('Fails validation'); |
||
66 | } |
||
67 | |||
68 | return $this->getClient()->request('POST', $uri, [ |
||
69 | 'body' => $payload |
||
70 | ]); |
||
71 | } |
||
72 | } |
||
73 |
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.