<commit_before><?php
namespace Laraquick\Controllers\Traits;

use Illuminate\Http\Response;
use Illuminate\Database\Eloquent\Collection;

trait Respond
{

    /**
     * Called when an error occurs while performing an action
     *
     * @param string $message
     * @param mixed $errors
     * @param integer $code
     * @return Response
     */
    protected function error($message, $errors = null, $code = 400)
    {
        $resp = [
            "message" => $message
        ];
        if ($errors) $resp["errors"] = $errors;
        return response()->json($resp, $code);
    }

    /**
     * Called when return a list of paginated items. 
     * 
     * The data is extracted while the others are placed in meta.
     *
     * @param array $items
     * @param integer $code
     * @return void
     */
    protected function paginatedList(array $items, $code = 200) {
        $resp['data'] = $items['data'];
        if (request()->query('length') != 'all' && count($items['data'])) {
            unset($items['data']);
            $meta['pagination'] = $items;
            $resp['meta']['pagination'] = $items;
        }
        return response()->json($resp, $code);
    }
<commit_msg>Captured cases where there's no data key when calling paginatedList()<commit_after><?php
namespace Laraquick\Controllers\Traits;

use Illuminate\Http\Response;
use Illuminate\Database\Eloquent\Collection;

trait Respond
{

    /**
     * Called when an error occurs while performing an action
     *
     * @param string $message
     * @param mixed $errors
     * @param integer $code
     * @return Response
     */
    protected function error($message, $errors = null, $code = 400)
    {
        $resp = [
            "message" => $message
        ];
        if ($errors) $resp["errors"] = $errors;
        return response()->json($resp, $code);
    }

    /**
     * Called when return a list of paginated items. 
     * 
     * The data is extracted while the others are placed in meta.
     *
     * @param array $items
     * @param integer $code
     * @return void
     */
    protected function paginatedList(array $items, $code = 200) {
        $resp['data'] = array_key_exists('data', $items) ? $items['data'] : $items;
        if (request()->query('length') != 'all' && count($resp['data'])) {
            unset($items['data']);
            $meta['pagination'] = $items;
            $resp['meta']['pagination'] = $items;
        }
        return response()->json($resp, $code);
    }

{'fraction_non_alphanumeric': 0.1473768522226672, 'fraction_numerical': 0.004805766920304365, 'mean_word_length': 2.335113484646195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '504363', 'n_tokens_mistral': 730, 'n_tokens_neox': 718, 'n_words': 198}