<commit_before><?php

use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Lecturize\Taxonomies\Taxonomy;

/**
 * Get categories tree as a collection.
 *
 * @param  string|array  $taxonomy
 * @param  string        $route
 * @param  string        $taxable
 * @param  string        $taxable_callback
 * @param  bool          $include_empty
 * @return Collection
 * @throws Exception
 */
function get_categories_collection($taxonomy = 'category', string $route = '', string $taxable = '', string $taxable_callback = '', bool $include_empty = false): Collection {
    $tree = Taxonomy::getTree($taxonomy, $taxable, $taxable_callback);

    return build_categories_collection_from_tree($tree, $taxonomy, $route, $taxable, $include_empty);
}

/**
 * Recursive function to build categories collection from given taxonomies tree.
 *
 * @param  Collection    $tree
 * @param  string|array  $taxonomy
 * @param  string        $route
 * @param  mixed         $taxable
 * @param  bool          $include_empty
 * @param  array         $params
 * @param  array         $attributes
 * @param  bool          $is_child
 * @return Collection
 */
function build_categories_collection_from_tree(Collection $tree, $taxonomy, string $route, string $taxable, bool $include_empty = false, array $params = [], array $attributes = [], bool $is_child = false): Collection {
    $temp  = $params;
    $items = collect();

    $count = 1;
    foreach ($tree as $slug => $properties) {
        $params[] = $properties['slug'];

        $children = null;

        foreach ($properties as $value) {
            if ($value instanceof Collection) {
                $children = build_categories_collection_from_tree($value, $taxonomy, $route, $taxable, $include_empty, $params, $attributes, true);
                break;
            }
        }

        $is_active = taxonomies_is_active_route($route, $params);

        $item = [
            'uuid'             => $properties['uuid'],
            'taxonomy'         => $properties['taxonomy'],
            'title'            => $properties['title'],
            'slug'             => $properties['slug'],
            'content'          => $properties['content'],
            'lead'             => $properties['lead'],
            'route'            => $route,
            'params'           => is_array($properties['alias-params']) ? get_term_link($route, $properties['alias-params']) : $params,
            'link'             => is_array($properties['alias-params']) ? get_term_link($route, $properties['alias-params']) : get_term_link($route, $params),
            'children'         => $children,
            'count'            => $properties['count'],
            'count-cumulative' => $properties['count-cumulative'],
            'active'           => $is_active,
            'active-branch'    => $is_active ?: ($children && $children->where('active-branch', true)->count()),
        ];

        $params = [];
        if ($count !== count($tree))
            $params = $temp;

        $count++;

        if (! $include_empty && $properties['count-cumulative'] < 1) {
             continue;
        } else {<commit_msg>Add new fields to item array<commit_after><?php

use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Lecturize\Taxonomies\Taxonomy;

/**
 * Get categories tree as a collection.
 *
 * @param  string|array  $taxonomy
 * @param  string        $route
 * @param  string        $taxable
 * @param  string        $taxable_callback
 * @param  bool          $include_empty
 * @return Collection
 * @throws Exception
 */
function get_categories_collection($taxonomy = 'category', string $route = '', string $taxable = '', string $taxable_callback = '', bool $include_empty = false): Collection {
    $tree = Taxonomy::getTree($taxonomy, $taxable, $taxable_callback);

    return build_categories_collection_from_tree($tree, $taxonomy, $route, $taxable, $include_empty);
}

/**
 * Recursive function to build categories collection from given taxonomies tree.
 *
 * @param  Collection    $tree
 * @param  string|array  $taxonomy
 * @param  string        $route
 * @param  mixed         $taxable
 * @param  bool          $include_empty
 * @param  array         $params
 * @param  array         $attributes
 * @param  bool          $is_child
 * @return Collection
 */
function build_categories_collection_from_tree(Collection $tree, $taxonomy, string $route, string $taxable, bool $include_empty = false, array $params = [], array $attributes = [], bool $is_child = false): Collection {
    $temp  = $params;
    $items = collect();

    $count = 1;
    foreach ($tree as $slug => $properties) {
        $params[] = $properties['slug'];

        $children = null;

        foreach ($properties as $value) {
            if ($value instanceof Collection) {
                $children = build_categories_collection_from_tree($value, $taxonomy, $route, $taxable, $include_empty, $params, $attributes, true);
                break;
            }
        }

        $is_active = taxonomies_is_active_route($route, $params);

        $item = [
            'uuid'             => $properties['uuid'],
            'taxonomy'         => $properties['taxonomy'],
            'title'            => $properties['title'],
            'slug'             => $properties['slug'],
            'content'          => $properties['content'],
            'lead'             => $properties['lead'],
            'meta_desc'        => $properties['meta_desc'],
            'visible'          => $properties['visible'],
            'searchable'       => $properties['searchable'],
            'route'            => $route,
            'params'           => is_array($properties['alias-params']) ? get_term_link($route, $properties['alias-params']) : $params,
            'link'             => is_array($properties['alias-params']) ? get_term_link($route, $properties['alias-params']) : get_term_link($route, $params),
            'children'         => $children,
            'count'            => $properties['count'],
            'count-cumulative' => $properties['count-cumulative'],
            'active'           => $is_active,
            'active-branch'    => $is_active ?: ($children && $children->where('active-branch', true)->count()),
        ];

        $params = [];
        if ($count !== count($tree))
            $params = $temp;

        $count++;

        if (! $include_empty && $properties['count-cumulative'] < 1) {
             continue;
        } else {
{'fraction_non_alphanumeric': 0.14403922770456634, 'fraction_numerical': 0.0006129328838492185, 'mean_word_length': 2.345463864684777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '2306284', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1769, 'n_words': 407}