<commit_before><?php

namespace ZpgRtf\Methods;

use League\JsonGuard\Validator;
use League\JsonReference\Dereferencer;
use ZpgRtf\Objects\BranchObject;

/**
 * The branch method allows you to update a branch.
 */
class BranchMethod extends AbstractMethod
{
    /** @var string */
    const UPDATE_SCHEMA = 'http://realtime-listings.webservices.zpg.co.uk/docs/v1.2/schemas/branch/update.json';

    /** @var string */
    const UPDATE_URI = 'branch/update';

    /**
     * @return bool
     *
     * @throws \Exception If validation fails. Needs a custom exception type.
     */
    public function update(BranchObject $branchObject)
    {
        $payload = json_encode($branchObject);
        $schema = Dereferencer::draft4()->dereference(self::UPDATE_SCHEMA);
        $validator = new Validator(json_decode($payload), $schema);

        if ($validator->fails()) {
            throw new \Exception('Fails validation');
        }

        $result = $this->getClient()->request('POST', self::UPDATE_URI, [
            'body' => $payload
        ]);

        return $result;
    }
}<commit_msg>Update branch method for new abstracted validate and send logic<commit_after><?php

namespace ZpgRtf\Methods;

use League\JsonGuard\Validator;
use League\JsonReference\Dereferencer;
use ZpgRtf\Objects\BranchObject;

/**
 * The branch method allows you to update a branch.
 */
class BranchMethod extends AbstractMethod
{
    /** @var string */
    const UPDATE_SCHEMA = 'http://realtime-listings.webservices.zpg.co.uk/docs/v1.2/schemas/branch/update.json';

    /**
     * @return \GuzzleHttp\Psr7\Response
     */
    public function update(BranchObject $branchObject)
    {
        return $this->validateAndSend(self::UPDATE_SCHEMA, 'branch/update', $branchObject);
    }
}
{'fraction_non_alphanumeric': 0.12952488687782807, 'fraction_numerical': 0.003393665158371041, 'mean_word_length': 3.172169811320755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5189546', 'n_tokens_mistral': 542, 'n_tokens_neox': 532, 'n_words': 115}