Completed
Push — master ( 6ac670...9cb93b )
by Luke
03:33 queued 02:19
created

AbstractMethod::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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 1
    public function __construct($certificate)
22
    {
23 1
        $this->client = new Client([
24 1
            'base_uri' => self::BASE_URI,
25 1
            'cert' => $certificate,
26
        ]);
27 1
    }
28
29
    /**
30
     * @return Client
31
     */
32
    public function getClient()
33
    {
34
        return $this->client;
35
    }
36
37
    /**
38
     * @param Client $client
39
     *
40
     * @return static
41
     */
42 1
    public function setClient(Client $client)
43
    {
44 1
        $this->client = $client;
45
46 1
        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 1
    protected function validateAndSend($schemaUri, $uri, \JsonSerializable $object)
59
    {
60 1
        $payload = json_encode($object);
61 1
        $schema = Dereferencer::draft4()->dereference($schemaUri);
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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