<commit_before><?php

namespace G4\CleanCore\Formatter\Collection;

use G4\CleanCore\Formatter\Collection\CollectionAbstract;
use G4\CleanCore\Paginator\Adapter\Iterator;

abstract class SliceAbstract extends CollectionAbstract
{

    public function format()
    {
        if ($this->_hasItems()) {
            foreach ($this->_getResourceCollection() as $resource) {
                $this->_formatOneResource($resource);
            }
        }

        return $this->_getPaginatorResponse();
    }

    public function isCollectionCountable()
    {
        return $this->_getResourceCollection() instanceof \Countable 
            || is_array($this->_getResourceCollection());
    }

    public function isCollectionIterator()
    {
        return $this->_getResourceCollection() instanceof \Iterator;
    }

    protected function _getPaginatorResponse()
    {
        $totalItems = $this->_getTotalItemsCount();

        return array(
            'current_page_number' => $this->_resource['page'],
            'total_item_count'    => $totalItems,
            'item_count_per_page' => $this->_resource['per_page'],
            'current_item_count'  => count($this->_data),
            'page_count'          => ceil($totalItems / $this->_resource['per_page']),
            'current_items'       => $this->_data
        );
    }

    private function _collectionNotCountable()
    {
        throw new \Exception('Collection does not implement Countable', 500);
    }

    private function _getCollectionCount()
    {
        $collection = $this->_getResourceCollection();

        return $this->isCollectionCountable()
            ? count($collection)
            : $this->_collectionNotCountable();
    }

    private function _hasItems()
    {
        return $this->_getCollectionCount() > 0;
    }

    private function _getTotalItemsCount()
    {
        return is_object($this->_getResourceCollection()) && method_exists($this->_getResourceCollection(), 'getTotalItemsCount')
            ? $this->_getResourceCollection()->getTotalItemsCount()
            : $this->_getCollectionCount();
    }
<commit_msg>Formatter Collection SliceAbstract method _getPaginatorResponse() handles case when no $_resource exists<commit_after><?php

namespace G4\CleanCore\Formatter\Collection;

use G4\CleanCore\Formatter\Collection\CollectionAbstract;
use G4\CleanCore\Paginator\Adapter\Iterator;

abstract class SliceAbstract extends CollectionAbstract
{

    public function format()
    {
        if ($this->_hasItems()) {
            foreach ($this->_getResourceCollection() as $resource) {
                $this->_formatOneResource($resource);
            }
        }

        return $this->_getPaginatorResponse();
    }

    public function isCollectionCountable()
    {
        return $this->_getResourceCollection() instanceof \Countable
            || is_array($this->_getResourceCollection());
    }

    public function isCollectionIterator()
    {
        return $this->_getResourceCollection() instanceof \Iterator;
    }

    protected function _getPaginatorResponse()
    {
        $totalItems = $this->_getTotalItemsCount();

        return array(
            'current_page_number' => !empty($this->_resource) ? $this->_resource['page'] : null,
            'total_item_count'    => $totalItems,
            'item_count_per_page' => !empty($this->_resource) ? $this->_resource['per_page'] : null,
            'current_item_count'  => count($this->_data),
            'page_count'          => !empty($this->_resource) ? ceil($totalItems / $this->_resource['per_page']) : 0,
            'current_items'       => $this->_data
        );
    }

    private function _collectionNotCountable()
    {
        throw new \Exception('Collection does not implement Countable', 500);
    }

    private function _getCollectionCount()
    {
        $collection = $this->_getResourceCollection();

        return $this->isCollectionCountable()
            ? count($collection)
            : $this->_collectionNotCountable();
    }

    private function _hasItems()
    {
        return $this->_getCollectionCount() > 0;
    }

    private function _getTotalItemsCount()
    {
        return is_object($this->_getResourceCollection()) && method_exists($this->_getResourceCollection(), 'getTotalItemsCount')
            ? $this->_getResourceCollection()->getTotalItemsCount()
            : $this->_getCollectionCount();
    }

{'fraction_non_alphanumeric': 0.12157573013357482, 'fraction_numerical': 0.003395970115462984, 'mean_word_length': 2.76, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, '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': '1213701', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1123, 'n_words': 204}