<commit_before><?php

namespace Edge\Rest\Mvc\Controller;

use Edge\Exception;
use Edge\Service\Exception as ServiceException;
use PhlyRestfully\ApiProblem;
use Zend\Mvc\Controller\AbstractRestfulController as ZendRestfulController;
use Zend\Paginator\Paginator;
use Zend\Stdlib\ArrayUtils;
use Zend\Http\Response;
use Zend\View\Model\JsonModel;

abstract class AbstractRestfulController extends ZendRestfulController
{
    /**
     * Prepare a paginator from page and limit query strings
     *
     * @param \Zend\Paginator\Paginator $paginator
     * @return \Zend\Paginator\Paginator
     */
    public function preparePaginator(Paginator $paginator)
    {
        $page  = $this->params()->fromQuery('page', 1);
        $limit = $this->params()->fromQuery('limit', null);

        if (null === $limit) {
            $limit = 10;
        }

        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage($limit);

        return $paginator;
    }

    /**
     * Bulk Process Data, handles POST, PUT & DELETE
     *
     * @param array  $data
     * @param string $entityName
     * @param string $entityIdentifier
     * @return JsonModel
     * @throws Exception\InvalidArgumentException
     * @throws Exception\RuntimeException
     */
    public function processBulkData(array $data, $entityName, $entityIdentifier = 'id')
    {
        $data = reset($data);

        if (!is_array($data) || !ArrayUtils::isList($data)) {
            throw new Exception\InvalidArgumentException('Invalid data provided');
        }

        $errors    = false;
        $responses = array();

        foreach ($data as $entityArray) {
            try {
                switch ($this->getRequest()->getMethod()) {
                    case 'POST':
                        $result = $this->create(array($entityName => $entityArray));
                        break;
                    case 'PUT':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->update($id, array($entityName => $entityArray));
                        break;
                    case 'PATCH':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->patch($id, array($entityName => $entityArray));
                        break;
                    case 'DELETE':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->delete($id);<commit_msg>Is list already checks for array type<commit_after><?php

namespace Edge\Rest\Mvc\Controller;

use Edge\Exception;
use Edge\Service\Exception as ServiceException;
use PhlyRestfully\ApiProblem;
use Zend\Mvc\Controller\AbstractRestfulController as ZendRestfulController;
use Zend\Paginator\Paginator;
use Zend\Stdlib\ArrayUtils;
use Zend\Http\Response;
use Zend\View\Model\JsonModel;

abstract class AbstractRestfulController extends ZendRestfulController
{
    /**
     * Prepare a paginator from page and limit query strings
     *
     * @param \Zend\Paginator\Paginator $paginator
     * @return \Zend\Paginator\Paginator
     */
    public function preparePaginator(Paginator $paginator)
    {
        $page  = $this->params()->fromQuery('page', 1);
        $limit = $this->params()->fromQuery('limit', null);

        if (null === $limit) {
            $limit = 10;
        }

        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage($limit);

        return $paginator;
    }

    /**
     * Bulk Process Data, handles POST, PUT & DELETE
     *
     * @param array  $data
     * @param string $entityName
     * @param string $entityIdentifier
     * @return JsonModel
     * @throws Exception\InvalidArgumentException
     * @throws Exception\RuntimeException
     */
    public function processBulkData(array $data, $entityName, $entityIdentifier = 'id')
    {
        $data = reset($data);

        if (!ArrayUtils::isList($data)) {
            throw new Exception\InvalidArgumentException('Invalid bulk data provided');
        }

        $errors    = false;
        $responses = array();

        foreach ($data as $entityArray) {
            try {
                switch ($this->getRequest()->getMethod()) {
                    case 'POST':
                        $result = $this->create(array($entityName => $entityArray));
                        break;
                    case 'PUT':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->update($id, array($entityName => $entityArray));
                        break;
                    case 'PATCH':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->patch($id, array($entityName => $entityArray));
                        break;
                    case 'DELETE':
                        $id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
                        $result = $this->delete($id);
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.0011435105774728416, 'mean_word_length': 2.1425149700598802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1789321', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1345, 'n_words': 299}