<commit_before><?php

/**
 * Copyright (c) 2017 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Solid\Collection;

use InvalidArgumentException;
use ReflectionClass;

/**
 * @package Solid\Collection
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 */
abstract class Enum
{
    /**
     * @since 0.1.0
     * @var mixed
     */
    protected $value;

    /**
     * @since 0.1.0
     * @var array
     */
    protected $strings = [];

    /**
     * @api
     * @since 0.1.0
     * @param mixed $value
     */
    final public function __construct($value)
    {
        if (!in_array($value, static::values())) {
            throw new InvalidArgumentException('Invalid value for enum ' . static::class . ": {$value}");
        }

        $this->value = self::getConstantFromValue($value);
    }

    /**
     * @api
     * @since 0.1.0
     * @return string
     */
    final public function __toString(): string
    {
        return (string)array_key_exists($this->getValue(), $this->strings) ?
            $this->strings[$this->getValue()] :
            $this->value;
    }

    /**
     * @api
     * @since 0.1.0
     * @return mixed
     */
    final public function getValue()
    {
        return constant("static::{$this->value}");
    }

    /**
     * @api
     * @since 0.1.0
     * @return array
     */
    final public static function enum(): array
    {
        return array_keys((new ReflectionClass(static::class))->getConstants());
    }

    /**
     * @api
     * @since 0.1.0
     * @return array
     */
    final public static function values(): array
    {
        return array_values((new ReflectionClass(static::class))->getConstants());
    }

    /**
     * @api
     * @since 0.1.0
     * @param mixed $value
     * @return string
     */
    private static function getConstantFromValue($value): string
    {
        return array_flip((new ReflectionClass(static::class))->getConstants())[$value];
    }
}<commit_msg>Made Enum more extendable to allow for instance case insensitive enums<commit_after><?php

/**
 * Copyright (c) 2017 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Solid\Collection;

use InvalidArgumentException;
use ReflectionClass;

/**
 * @package Solid\Collection
 * @author <NAME> <<EMAIL>>
 * @since 0.1.0
 */
abstract class Enum
{
    /**
     * @since 0.1.0
     * @var mixed
     */
    protected $value;

    /**
     * @since 0.1.0
     * @var array
     */
    protected $strings = [];

    /**
     * @api
     * @since 0.1.0
     * @param mixed $value
     */
    public function __construct($value)
    {
        if (!in_array($value, static::values())) {
            throw new InvalidArgumentException('Invalid value for enum ' . static::class . ": {$value}");
        }

        $this->value = self::getConstantFromValue($value);
    }

    /**
     * @api
     * @since 0.1.0
     * @return string
     */
    public function __toString(): string
    {
        return (string)array_key_exists($this->getValue(), $this->strings) ?
            $this->strings[$this->getValue()] :
            $this->value;
    }

    /**
     * @api
     * @since 0.1.0
     * @return mixed
     */
    public function getValue()
    {
        return constant("static::{$this->value}");
    }

    /**
     * @api
     * @since 0.1.0
     * @return array
     */
    public static function enum(): array
    {
        return array_keys((new ReflectionClass(static::class))->getConstants());
    }

    /**
     * @api
     * @since 0.1.0
     * @return array
     */
    public static function values(): array
    {
        return array_values((new ReflectionClass(static::class))->getConstants());
    }

    /**
     * @api
     * @since 0.1.0
     * @param mixed $value
     * @return string
     */
    private static function getConstantFromValue($value): string
    {
        return array_flip((new ReflectionClass(static::class))->getConstants())[$value];
    }
}
{'fraction_non_alphanumeric': 0.14947828197039553, 'fraction_numerical': 0.01504489201650085, 'mean_word_length': 2.1085972850678734, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 31, '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': '6665205', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1222, 'n_words': 295}