<commit_before><?php namespace Scriptotek\Sru;

/**
 * When iterating, methods are called in the following order:
 *
 * rewind()
 * valid()
 * current()
 *
 * next()
 * valid()
 * current()
 *
 * ...
 *
 * next()
 * valid()
 */
class Records implements \Iterator
{
    private $position;
    private $count;
    private $extraParams;
    private $cql;
    private $client;
    private $lastResponse;

    private $data = array();

    /**
     * Create a new records iterator
     *
     * @param string $cql Query
     * @param Client $client SRU client reference (optional)
     * @param int $count Number of records to request per request
     * @param array $extraParams Extra GET parameters
     */
    public function __construct($cql, Client $client, $count = 10, $extraParams = array())
    {
        $this->position = 1;
        $this->count = $count; // number of records per request
        $this->extraParams = $extraParams;
        $this->cql = $cql;
        $this->client = $client;
        $this->fetchMore();
    }

    /**
     * Return the number of records
     *
     * @return int|null
     */
    public function numberOfRecords()
    {
        return $this->lastResponse->numberOfRecords;
    }

    /**
     * Fetch more records from the service
     */
    private function fetchMore()
    {
        $url = $this->client->urlTo($this->cql, $this->position, $this->count, $this->extraParams);
        $body = $this->client->request('GET', $url);
        $this->lastResponse = new SearchRetrieveResponse($body);
        $this->data = $this->lastResponse->records;

        if (count($this->data) != 0 && $this->data[0]->position != $this->position) {
            throw new Exceptions\InvalidResponseException('Wrong index of first record in result set. '
                . 'Expected: ' .$this->position . ', got: ' . $this->data[0]->position
            );
        }
    }
<commit_msg>The number of records is mandatory, so should never be null.<commit_after><?php namespace Scriptotek\Sru;

/**
 * When iterating, methods are called in the following order:
 *
 * rewind()
 * valid()
 * current()
 *
 * next()
 * valid()
 * current()
 *
 * ...
 *
 * next()
 * valid()
 */
class Records implements \Iterator
{
    private $position;
    private $count;
    private $extraParams;
    private $cql;
    private $client;
    private $lastResponse;

    private $data = array();

    /**
     * Create a new records iterator
     *
     * @param string $cql Query
     * @param Client $client SRU client reference (optional)
     * @param int $count Number of records to request per request
     * @param array $extraParams Extra GET parameters
     */
    public function __construct($cql, Client $client, $count = 10, $extraParams = array())
    {
        $this->position = 1;
        $this->count = $count; // number of records per request
        $this->extraParams = $extraParams;
        $this->cql = $cql;
        $this->client = $client;
        $this->fetchMore();
    }

    /**
     * Return the number of records
     *
     * @return int
     */
    public function numberOfRecords()
    {
        return $this->lastResponse->numberOfRecords;
    }

    /**
     * Fetch more records from the service
     */
    private function fetchMore()
    {
        $url = $this->client->urlTo($this->cql, $this->position, $this->count, $this->extraParams);
        $body = $this->client->request('GET', $url);
        $this->lastResponse = new SearchRetrieveResponse($body);
        $this->data = $this->lastResponse->records;

        if (count($this->data) != 0 && $this->data[0]->position != $this->position) {
            throw new Exceptions\InvalidResponseException('Wrong index of first record in result set. '
                . 'Expected: ' .$this->position . ', got: ' . $this->data[0]->position
            );
        }
    }

{'fraction_non_alphanumeric': 0.14489372731985484, 'fraction_numerical': 0.003110419906687403, 'mean_word_length': 2.3556521739130436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '3167500', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1107, 'n_words': 308}