<commit_before><?php

namespace Deft\DataTables\DataSource;

use Deft\DataTables\Request\Request;

class ArrayDataSource implements DataSourceInterface
{
    /**
     * @var Request
     */
    protected $request;

    /**
     * @var array
     */
    protected $data;

    /**
     * Filtered and sorted data
     *
     * @var array
     */
    private $displayData;

    /**
     * @param array $data
     */
    public function __construct(array $data)
    {
        $this->data = $data;
    }

    public function createDataSet(Request $request)
    {
        $displayData = $this->sortData(
            $request,
            $this->filterData($request, $this->data)
        );

        $dataSet = new DataSet();
        $dataSet->numberOfTotalRecords = count($this->data);
        $dataSet->numberOfFilteredRecords = count($displayData);
        $dataSet->data = array_values(
            array_slice(
                $displayData,
                $request->displayStart,
                $request->displayLength
            )
        );

        return $dataSet;
    }

    protected function filterData(Request $request, $data)
    {
        if (count($request->columnFilters) == 0) return $data;
        return array_filter(
            $data,
            function ($row) use ($request) {
                $filterResults = [];
                array_walk($request->columnFilters, function ($filter, $column) use ($row, &$filterResults) {
                    $filterResults[] = false !== strpos($row[$column], $filter);
                });

                return !in_array(false, $filterResults);
            }
        );
    }

    protected function sortData(Request $request, $data)
    {
        $sorts = $request->columnSorts;
        if (count($sorts) == 0) return $data;

        usort($data, function ($a, $b) use ($sorts) {
            foreach ($sorts as $column => $direction) {
                if ($a[$column] == $b[$column]) continue;
                $result = $a[$column] < $b[$column] ? -1 : 1;

                return $direction == 'asc' ? $result : $result * -1;<commit_msg>Case insensitive filtering in ArrayDataSource<commit_after><?php

namespace Deft\DataTables\DataSource;

use Deft\DataTables\Request\Request;

class ArrayDataSource implements DataSourceInterface
{
    /**
     * @var Request
     */
    protected $request;

    /**
     * @var array
     */
    protected $data;

    /**
     * Filtered and sorted data
     *
     * @var array
     */
    private $displayData;

    /**
     * @param array $data
     */
    public function __construct(array $data)
    {
        $this->data = $data;
    }

    public function createDataSet(Request $request)
    {
        $displayData = $this->sortData(
            $request,
            $this->filterData($request, $this->data)
        );

        $dataSet = new DataSet();
        $dataSet->numberOfTotalRecords = count($this->data);
        $dataSet->numberOfFilteredRecords = count($displayData);
        $dataSet->data = array_values(
            array_slice(
                $displayData,
                $request->displayStart,
                $request->displayLength
            )
        );

        return $dataSet;
    }

    protected function filterData(Request $request, $data)
    {
        if (count($request->columnFilters) == 0) return $data;
        return array_filter(
            $data,
            function ($row) use ($request) {
                $filterResults = [];
                array_walk($request->columnFilters, function ($filter, $column) use ($row, &$filterResults) {
                    $filterResults[] = false !== strpos(strtolower($row[$column]), strtolower($filter));
                });

                return !in_array(false, $filterResults);
            }
        );
    }

    protected function sortData(Request $request, $data)
    {
        $sorts = $request->columnSorts;
        if (count($sorts) == 0) return $data;

        usort($data, function ($a, $b) use ($sorts) {
            foreach ($sorts as $column => $direction) {
                if ($a[$column] == $b[$column]) continue;
                $result = $a[$column] < $b[$column] ? -1 : 1;

                return $direction == 'asc' ? $result : $result * -1;
{'fraction_non_alphanumeric': 0.13647058823529412, 'fraction_numerical': 0.002352941176470588, 'mean_word_length': 1.854936198791135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '249064', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1165, 'n_words': 259}