<commit_before><?php namespace Nord\Lumen\Elasticsearch\Documents\Bulk;

class BulkResponseAggregator
{

    /**
     * @var array
     */
    private $errors = [];

    /**
     * @param array $response
     *
     * @return $this
     */
    public function addResponse(array $response): self
    {
        $this->parseErrors($response);

        return $this;
    }

    /**
     * @return bool
     */
    public function hasErrors(): bool
    {
        return count($this->errors) > 0;
    }

    /**
     * @return array
     */
    public function getErrors(): array
    {
        return $this->errors;
    }

    /**
     * @param array $response
     */
    protected function parseErrors(array $response): void
    {
        $items = $response['items'] ?? [];

        foreach ($items as $item) {
            $item = $item['type'];

            // Ignore items without errors
            $error = $item['error'] ?? null;

            if ($error === null) {
                continue;
            }

            // Ignore errors without caused_by
            $causedBy = $error['caused_by'] ?? null;

            if ($causedBy === null) {
                continue;
            }

            $this->errors[] = sprintf('Error "%s" reason "%s". Cause "%s" reason "%s". Index "%s", type "%s", id "%s"',
                $error['type'], $error['reason'], $causedBy['type'], $causedBy['reason'], $item['_index'],
                $item['_type'], $item['_id']);
        }
    }

    /**
     * @return $this
     */
    public function reset(): self
    {
        $this->errors = [];

        return $this;
    }
}<commit_msg>Move public methods before protected ones<commit_after><?php namespace Nord\Lumen\Elasticsearch\Documents\Bulk;

class BulkResponseAggregator
{

    /**
     * @var array
     */
    private $errors = [];

    /**
     * @param array $response
     *
     * @return $this
     */
    public function addResponse(array $response): self
    {
        $this->parseErrors($response);

        return $this;
    }

    /**
     * @return bool
     */
    public function hasErrors(): bool
    {
        return count($this->errors) > 0;
    }

    /**
     * @return array
     */
    public function getErrors(): array
    {
        return $this->errors;
    }

    /**
     * @return $this
     */
    public function reset(): self
    {
        $this->errors = [];

        return $this;
    }

    /**
     * @param array $response
     */
    protected function parseErrors(array $response): void
    {
        $items = $response['items'] ?? [];

        foreach ($items as $item) {
            $item = $item['type'];

            // Ignore items without errors
            $error = $item['error'] ?? null;

            if ($error === null) {
                continue;
            }

            // Ignore errors without caused_by
            $causedBy = $error['caused_by'] ?? null;

            if ($causedBy === null) {
                continue;
            }

            $this->errors[] = sprintf('Error "%s" reason "%s". Cause "%s" reason "%s". Index "%s", type "%s", id "%s"',
                $error['type'], $error['reason'], $causedBy['type'], $causedBy['reason'], $item['_index'],
                $item['_type'], $item['_id']);
        }
    }
}
{'fraction_non_alphanumeric': 0.16341463414634147, 'fraction_numerical': 0.0006097560975609756, 'mean_word_length': 1.637459807073955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7240425', 'n_tokens_mistral': 976, 'n_tokens_neox': 930, 'n_words': 221}