<commit_before><?php


namespace Twilio;


use Twilio\Exceptions\DeserializeException;
use Twilio\Http\Response;

abstract class Page implements \Iterator {
    protected static $metaKeys = array(
        'end',
        'first_page_uri',
        'next_page_uri',
        'last_page_uri',
        'page',
        'page_size',
        'previous_page_uri',
        'total',
        'num_pages',
        'start',
        'uri',
    );

    protected $version;
    protected $payload;
    protected $solution;
    protected $records;

    abstract public function buildInstance(array $payload);

    public function __construct(Version $version, Response $response) {
        $payload = $this->processResponse($response);

        $this->version = $version;
        $this->payload = $payload;
        $this->solution = array();
        $this->records = new \ArrayIterator($this->loadPage());
    }

    protected function processResponse(Response $response) {
        if ($response->getStatusCode() != 200 && !$this->isPagingEol($response->getContent())) {
            $message = '[HTTP ' . $response->getStatusCode() . '] Unable to fetch page';
            $code = $response->getStatusCode();

            $content = $response->getContent();

            if (is_array($content)) {
                $message .= isset($content['message']) ? ': ' . $content['message'] : '';
                $code = isset($content['code']) ? $content['code'] : $code;
            }

            throw new DeserializeException($message, $code);
        }
        return $response->getContent();
    }

    protected function isPagingEol($content) {
        return !is_null($content) && array_key_exists('code', $content) && $content['code'] == 20006;
    }

    protected function hasMeta($key) {
        return array_key_exists('meta', $this->payload) && array_key_exists($key, $this->payload['meta']);
    }

    protected function getMeta($key, $default=null) {
        return $this->hasMeta($key) ? $this->payload['meta'][$key] : $default;
    }<commit_msg>Change processResponse to use RestException<commit_after><?php


namespace Twilio;


use Twilio\Exceptions\DeserializeException;
use Twilio\Exceptions\RestException;
use Twilio\Http\Response;

abstract class Page implements \Iterator {
    protected static $metaKeys = array(
        'end',
        'first_page_uri',
        'next_page_uri',
        'last_page_uri',
        'page',
        'page_size',
        'previous_page_uri',
        'total',
        'num_pages',
        'start',
        'uri',
    );

    protected $version;
    protected $payload;
    protected $solution;
    protected $records;

    abstract public function buildInstance(array $payload);

    public function __construct(Version $version, Response $response) {
        $payload = $this->processResponse($response);

        $this->version = $version;
        $this->payload = $payload;
        $this->solution = array();
        $this->records = new \ArrayIterator($this->loadPage());
    }

    protected function processResponse(Response $response) {
        if ($response->getStatusCode() != 200 && !$this->isPagingEol($response->getContent())) {
            $message = '[HTTP ' . $response->getStatusCode() . '] Unable to fetch page';
            $code = $response->getStatusCode();

            $content = $response->getContent();

            if (is_array($content)) {
                $message .= isset($content['message']) ? ': ' . $content['message'] : '';
                $code = isset($content['code']) ? $content['code'] : $code;
            }

            throw new RestException($message, $code, $response->getStatusCode());
        }
        return $response->getContent();
    }

    protected function isPagingEol($content) {
        return !is_null($content) && array_key_exists('code', $content) && $content['code'] == 20006;
    }

    protected function hasMeta($key) {
        return array_key_exists('meta', $this->payload) && array_key_exists($key, $this->payload['meta']);
    }

    protected function getMeta($key, $default=null) {
        return $this->hasMeta($key) ? $this->payload['meta'][$key] : $default;
    }
{'fraction_non_alphanumeric': 0.15416065416065416, 'fraction_numerical': 0.003848003848003848, 'mean_word_length': 2.7233661593554164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, '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': '1595989', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1146, 'n_words': 239}