<commit_before><?php
namespace rtens\collections;

use rtens\smokey\EventDispatcher;
use rtens\collections\iterator\ArrayIterator;
use rtens\collections\events\CollectionEvent;

/**
 * A bunch of elements. Base class for List, Set and Map
 */
abstract class Collection implements \Countable, \IteratorAggregate {

    static $CLASSNAME = __CLASS__;

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

    /**
     * @var \rtens\smokey\EventDispatcher
     */
    private $dispatcher;

    /**
     * @static
     * @param array $array
     * @return Map
     */
    static public function toMap(array $array) {
        $collection = self::toCollections($array);
        return new Map($collection->elements);
    }

    /**
     * @static
     * @param array $array
     * @return Liste
     */
    static public function toList(array $array) {
        $collection = self::toCollections($array);
        return new Liste($collection->elements);
    }

    /**
     * Traverses public attributes of objects and arrays and converts all arrays to Lists and Maps
     *
     * @static
     * @param mixed $object
     * @return mixed
     */
    static public function toCollections($object) {
        if ($object === null) {
            return null;
        }

        if (!is_array($object)) {
            if (is_object($object)) {
                foreach ($object as $key => $value) {
                    $object->$key = self::toCollections($value);
                }
            }
            return $object;
        }

        if (empty($object)) {
            return new Map();
        }

        $elements = array();
        $isList = true;
        $lastKey = -1;

        foreach ($object as $key => $element) {
            if (is_array($element)) {
                /** @var $element array */
                $element = self::toCollections($element);
            }
            $elements[$key] = $element;

            if (!is_int($key) || intval($key) != $lastKey + 1) {
                $isList = false;
            }
            $lastKey = intval($key);
        }

        if ($isList) {
            return new Liste($elements);
        } else {<commit_msg>Fixed bug in recursive toCollection transformation<commit_after><?php
namespace rtens\collections;

use rtens\smokey\EventDispatcher;
use rtens\collections\iterator\ArrayIterator;
use rtens\collections\events\CollectionEvent;

/**
 * A bunch of elements. Base class for List, Set and Map
 */
abstract class Collection implements \Countable, \IteratorAggregate {

    static $CLASSNAME = __CLASS__;

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

    /**
     * @var \rtens\smokey\EventDispatcher
     */
    private $dispatcher;

    /**
     * @static
     * @param array $array
     * @return Map
     */
    static public function toMap(array $array) {
        $collection = self::toCollections($array);
        return new Map($collection->elements);
    }

    /**
     * @static
     * @param array $array
     * @return Liste
     */
    static public function toList(array $array) {
        $collection = self::toCollections($array);
        return new Liste($collection->elements);
    }

    /**
     * Traverses public attributes of objects and arrays and converts all arrays to Lists and Maps
     *
     * @static
     * @param mixed $object
     * @return mixed
     */
    static public function toCollections($object) {
        if ($object === null) {
            return null;
        }

        if (!is_array($object)) {
            if (is_object($object)) {
                foreach ($object as $key => $value) {
                    $object->$key = self::toCollections($value);
                }
            }
            return $object;
        }

        if (empty($object)) {
            return new Map();
        }

        $elements = array();
        $isList = true;
        $lastKey = -1;

        foreach ($object as $key => $element) {
            $elements[$key] = self::toCollections($element);

            if (!is_int($key) || intval($key) != $lastKey + 1) {
                $isList = false;
            }
            $lastKey = intval($key);
        }

        if ($isList) {
            return new Liste($elements);
        } else {
{'fraction_non_alphanumeric': 0.12573581351542265, 'fraction_numerical': 0.0009418412997409936, 'mean_word_length': 1.7947368421052632, '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': '232466', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1157, 'n_words': 302}