<commit_before><?php

namespace Phug\Util;

use Generator;
use IteratorAggregate;
use Traversable;

class Collection implements IteratorAggregate
{
    /**
     * @var iterable
     */
    private $traversable;

    public function __construct($value)
    {
        $this->traversable = static::makeIterable($value);
    }

    /**
     * Polyfill of is_iterable.
     *
     * @see https://www.php.net/manual/en/function.is-iterable.php
     *
     * @param mixed $value
     *
     * @return bool
     */
    public static function isIterable($value)
    {
        return is_array($value) || (is_object($value) && $value instanceof Traversable);
    }

    /**
     * Wrap given value in an array if it's not yet iterable.
     *
     * @param mixed $value
     *
     * @return iterable
     */
    public static function makeIterable($value)
    {
        return static::isIterable($value) ? $value : [$value];
    }

    /**
     * Retrieve an external iterator.
     *
     * @link https://php.net/manual/en/iteratoraggregate.getiterator.php
     *
     * @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
     */
    public function getIterator()
    {
        return $this->traversable instanceof Traversable ? $this->traversable : $this->getGenerator();
    }

    /**
     * Get input data as iterable value.
     *
     * @return iterable
     */
    public function getIterable()
    {
        return $this->traversable;
    }

    /**<commit_msg>Add ReturnTypeWillChange for PHP 8.1<commit_after><?php

namespace Phug\Util;

use Generator;
use IteratorAggregate;
use ReturnTypeWillChange;
use Traversable;

class Collection implements IteratorAggregate
{
    /**
     * @var iterable
     */
    private $traversable;

    public function __construct($value)
    {
        $this->traversable = static::makeIterable($value);
    }

    /**
     * Polyfill of is_iterable.
     *
     * @see https://www.php.net/manual/en/function.is-iterable.php
     *
     * @param mixed $value
     *
     * @return bool
     */
    public static function isIterable($value)
    {
        return is_array($value) || (is_object($value) && $value instanceof Traversable);
    }

    /**
     * Wrap given value in an array if it's not yet iterable.
     *
     * @param mixed $value
     *
     * @return iterable
     */
    public static function makeIterable($value)
    {
        return static::isIterable($value) ? $value : [$value];
    }

    /**
     * Retrieve an external iterator.
     *
     * @link https://php.net/manual/en/iteratoraggregate.getiterator.php
     *
     * @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
     */
    #[ReturnTypeWillChange]
    public function getIterator()
    {
        return $this->traversable instanceof Traversable ? $this->traversable : $this->getGenerator();
    }

    /**
     * Get input data as iterable value.
     *
     * @return iterable
     */
    public function getIterable()
    {
        return $this->traversable;
    }

    /**
{'fraction_non_alphanumeric': 0.12147716229348883, 'fraction_numerical': 0.0006478781988986071, 'mean_word_length': 2.295624332977588, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 4, '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': '5480652', 'n_tokens_mistral': 960, 'n_tokens_neox': 943, 'n_words': 217}