<commit_before><?php

/**
 * Sorting Utility Collection
 *
 * Licensed under The MIT License
 * Redistribution of these files must retain the above copyright notice.
 *
 * @copyright Copyright 2007-2014, <NAME>
 * @license   http://www.opensource.org/licenses/mit-license.html
 * @link      https://github.com/joshtronic/pickles
 * @package   Pickles
 */

namespace Pickles;

/**
 * Sort Class
 *
 * I got tired of writing separate usort functions to sort by different array
 * keys in the array, this class solves that.
 */
class Sort
{
    /**
     * Ascending
     *
     * Variable to utilize ascending sort
     *
     * @var string
     */
    const ASC = 'ASC';

    /**
     * Descending
     *
     * Variable to utilize descending sort
     *
     * @var string
     */
    const DESC = 'DESC';

    /**
     * Sort By
     *
     * Sorts an array by the specified column, optionally in either direction.
     *
     * @param string $field field to sort by
     * @param array $array array to sort
     * @param string $direction optional direction to sort
     * @return boolean true because sorting is done by reference
     */
    public static function by($field, &$array, $direction = Sort::ASC)
    {
        usort($array, create_function('$a, $b', '
            $a = $a["' . $field . '"];
            $b = $b["' . $field . '"];

            if ($a == $b)
            {
                return 0;
            }

            return ($a ' . ($direction == Sort::DESC ? '>' : '<') .' $b) ? -1 : 1;
        '));

        return true;
    }
}
<commit_msg>Use anonymous function as suggested by PHP manual<commit_after><?php

/**
 * Sorting Utility Collection
 *
 * Licensed under The MIT License
 * Redistribution of these files must retain the above copyright notice.
 *
 * @copyright Copyright 2007-2014, <NAME>
 * @license   http://www.opensource.org/licenses/mit-license.html
 * @link      https://github.com/joshtronic/pickles
 * @package   Pickles
 */

namespace Pickles;

/**
 * Sort Class
 *
 * I got tired of writing separate usort functions to sort by different array
 * keys in the array, this class solves that.
 */
class Sort
{
    /**
     * Ascending
     *
     * Variable to utilize ascending sort
     *
     * @var string
     */
    const ASC = 'ASC';

    /**
     * Descending
     *
     * Variable to utilize descending sort
     *
     * @var string
     */
    const DESC = 'DESC';

    /**
     * Sort By
     *
     * Sorts an array by the specified column, optionally in either direction.
     *
     * @param string $field field to sort by
     * @param array $array array to sort
     * @param string $direction optional direction to sort
     * @return boolean true because sorting is done by reference
     */
    public static function by($field, &$array, $direction = Sort::ASC)
    {
        usort($array, function ($a, $b) use ($field, $direction) {
            $a = $a[$field];
            $b = $b[$field];

            if ($a === $b) {
                return 0;
            }

            return ($a < $b ? -1 : 1) * ($direction === Sort::DESC ? -1 : 1);
        });

        return true;
    }
}
{'fraction_non_alphanumeric': 0.12241653418124006, 'fraction_numerical': 0.007631160572337043, 'mean_word_length': 1.9763481551561022, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4064587', 'n_tokens_mistral': 942, 'n_tokens_neox': 893, 'n_words': 311}