<commit_before><?php namespace App\Http\Controllers;

use App\Genre;

class GenreController extends Controller {

    public function index()
    {
        // Only include certain information
        $include = ['id', 'parent_id', 'name'];

        $genres = Genre::root()->getDescendantsAndSelf($include)->toHierarchy();

        $genres = $this->cleanup($genres->toArray());

        return $genres[1];
    }

    /**
     * Recursively renames `name` to `text` and `children` to `nodes`
     *
     * @param array $array
     *
     * @return array
     */
    private function cleanup(array $array)
    {
        foreach($array as &$value)
        {
            $value['text'] = $value['name'];
            $value['nodes'] = $value['children'];
            unset($value['name']);
            unset($value['children']);

            if (empty($value['nodes']))
            {
                unset($value['nodes']);
            }
            else
            {
                $value['nodes'] = $this->cleanup($value['nodes']);
            }
        }

        return $array;
    }

}<commit_msg>Hide more fields in JSON genre response<commit_after><?php namespace App\Http\Controllers;

use App\Genre;

class GenreController extends Controller {

    public function index()
    {
        // Only include certain information
        $include = ['id', 'parent_id', 'name'];

        $genres = Genre::root()->getDescendantsAndSelf($include)->toHierarchy();

        $genres = $this->cleanup($genres->toArray());

        return $genres[1];
    }

    /**
     * Recursively renames `name` to `text` and `children` to `nodes`
     *
     * @param array $array
     *
     * @return array
     */
    private function cleanup(array $array)
    {
        foreach($array as &$value)
        {
            $value['text'] = $value['name'];
            $value['nodes'] = $value['children'];

            unset($value['name']);
            unset($value['children']);
            unset($value['id']);
            unset($value['parent_id']);

            if (empty($value['nodes']))
            {
                unset($value['nodes']);
            }
            else
            {
                $value['nodes'] = $this->cleanup($value['nodes']);
            }
        }

        return $array;
    }

}
{'fraction_non_alphanumeric': 0.16114982578397213, 'fraction_numerical': 0.0008710801393728223, 'mean_word_length': 1.8218673218673218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '512916', 'n_tokens_mistral': 648, 'n_tokens_neox': 635, 'n_words': 130}