Completed
Push — master ( 3d2d99...6ac670 )
by Luke
02:45 queued 01:29
created

src/Methods/BranchMethod.php (1 issue)

1
<?php
2
3
namespace ZpgRtf\Methods;
4
5
use League\JsonGuard\Validator;
6
use League\JsonReference\Dereferencer;
7
use ZpgRtf\Objects\BranchObject;
8
9
/**
10
 * The branch method allows you to update a branch.
11
 */
12
class BranchMethod extends AbstractMethod
13
{
14
    /** @var string */
15
    const UPDATE_SCHEMA = 'http://realtime-listings.webservices.zpg.co.uk/docs/v1.2/schemas/branch/update.json';
16
17
    /** @var string */
18
    const UPDATE_URI = 'branch/update';
19
20
    /**
21
     * @return bool
22
     *
23
     * @throws \Exception If validation fails. Needs a custom exception type.
24
     */
25 2 View Code Duplication
    public function update(BranchObject $branchObject)
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.

Loading history...
26
    {
27 2
        $payload = json_encode($branchObject);
28 2
        $schema = Dereferencer::draft4()->dereference(self::UPDATE_SCHEMA);
29 2
        $validator = new Validator(json_decode($payload), $schema);
30
31 2
        if ($validator->fails()) {
32 1
            throw new \Exception('Fails validation');
33
        }
34
35 1
        $result = $this->getClient()->request('POST', self::UPDATE_URI, [
36 1
            'body' => $payload
37
        ]);
38
39 1
        return $result;
40
    }
41
}
42