Try to recreate an enum type with new values

@param string $typeName name of the enum type
@param string[] $values new values of the enum type
@throws \Exception
504398
public static function recreate($typeName, $values)
    {
        $db = static::getDb();
        $quotedType = $db->quoteColumnName($typeName);

        $transaction = $db->beginTransaction();
        try {
            $columns = static::columns($typeName);

            do {
                $tmpTypeName = md5(rand());
            } while (static::exists($tmpTypeName));

            static::rename($typeName, $tmpTypeName);
            static::create($typeName, $values);

            $schema = $db->getSchema();
            foreach ($columns as $column) {
                $quotedColumn = $db->quoteColumnName($column['column_name']);
                $db->createCommand(
                    'ALTER TABLE ' . $db->quoteTableName($column['table_name'])
                    . ' ALTER ' . $quotedColumn
                    . ' TYPE ' . $quotedType
                    . ' USING ' . $quotedColumn . '::text::' . $quotedType
                )->execute();
                $schema->refreshTableSchema($column['table_name']);
            }

            static::drop($tmpTypeName);

            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();
            throw $e;
        }
    }
693172
private function valid($types, $value) {
        $types = (array) $types;

        foreach($types as $type) {
            switch($type) {
            case self::T_NULL:
                if(is_null($value)) {
                    return true;
                }
                break;
            case self::T_INT:
                if(is_int($value)) {
                    return true;
                }
                break;
            case self::T_STR:
                if(is_string($value)) {
                    return true;
                }
                break;
            case self::T_ARR:
                if(is_array($value)) {
                    return true;
                }
                break;
            }
        }

        return false;
    }
588859
public function is_type($name, $value, $types){
        if(! $this->not_empty($name, $value)){
            return TRUE;
        }
        $types= explode(',', $types);
        $ok= TRUE;
        if($this->isMultiple($value)){
            foreach ($value['type'] as $type) {
                if (in_array($type, $types)){
                    $ok= FALSE;
                    break;
                }
            }
        }else{
            $ok= in_array($value['type'], $types);
        }        
        
        if($ok){
            return TRUE;
        }else{
            $this->add_message($name, 'is_type', array('types' => $types));
            return FALSE;
        }
    }
568028
public static function wrap(array &$values)
    {
        $types = new Dictionary;
        self::determineTypes($values, $types);

        return new TypedDictionary($types, $values);
    }
508621
protected function createEnum(string $name, array $values): void
    {
        assert(empty($name) === false);

        // check all values are strings
        assert(
            call_user_func(function () use ($values): bool {
                $allAreStrings = true;
                foreach ($values as $value) {
                    $allAreStrings = $allAreStrings && is_string($value);
                }

                return $allAreStrings;
            }) === true,
            'All enum values should be strings.'
        );

        assert(array_key_exists($name, $this->enumerations) === false, "Enum name `$name` has already been used.");
        $this->enumerations[$name] = $values;

        $connection = $this->getConnection();
        if ($connection->getDriver()->getName() === 'pdo_pgsql') {
            $valueList = implode("', '", $values);
            $sql       = "CREATE TYPE $name AS ENUM ('$valueList');";
            $connection->exec($sql);
        }
    }
157819
public static function assert($value, $varName) {
        NotNil::assert($value, $varName);
        return !is_string($value) ? Exceptions::InvalidTypeException('string', $varName, $value) : $value;
    }
354817
public function toObject($value)
    {
        if (!is_array($value)) {
            throw new TypeCastException('Is not array');
        }

        foreach ($this->rules as $class => $rule) {
            if ($this->isMatch($rule, $value)) {
                return $this->createInstance($class, $value);
            }
        }

        throw new TypeCastException('Rule not found');
    }
926908
public function setValues(array $values, $caseSensitive = false)
	{
		if (!is_bool($caseSensitive))
		{
			throw new InvalidArgumentException('Argument 2 passed to ' . __METHOD__ . ' must be a boolean');
		}

		// Create a regexp based on the list of allowed values
		$regexp = RegexpBuilder::fromList($values, ['delimiter' => '/']);
		$regexp = '/^' . $regexp . '$/D';

		// Add the case-insensitive flag if applicable
		if (!$caseSensitive)
		{
			$regexp .= 'i';
		}

		// Add the Unicode flag if the regexp isn't purely ASCII
		if (!preg_match('#^[[:ascii:]]*$#D', $regexp))
		{
			$regexp .= 'u';
		}

		// Set the regexp associated with this list of values
		$this->setRegexp($regexp);
	}
1295412
public static function validate($types, ...$values): bool
    {
        try {
            return self::typeOf($types, ...$values);
        } catch (Throwable $t) {
            // We won't do anything
        }

        return false;
    }
1030659
public static function setDataTypes(array $types) : void
    {
        // Datatypes key validation
        foreach ($types as $key => $value) {
            if (!preg_match('/^[A-Za-z0-9-_]+$/', $key)) {
                throw new \UnexpectedValueException("<b>$key</b> is not a valid datatype key", 1);

            } elseif (!is_string($value)) {
                throw new \LogicException("<b>$key</b> must have a string value", 1);
            }
        }

        // Put keys between brackets
        self::$datatypes = array_combine(
            array_map(function ($t) {
                return '/\{' . $t . '\}/';
            }, array_keys($types)),
            $types
        );
    }
1137035
public static function add($typeName, $values, $before = null)
    {
        $values = (array) $values;

        $db = static::getDb();
        if ($db->getTransaction()) {
            // It cannot add a value during a transaction.
            // Start new connection without transactions.
            $db = static::newConnection();
        }

        $query = 'ALTER TYPE ' . $db->quoteColumnName($typeName)
            . ' ADD VALUE IF NOT EXISTS ';

        $beforeQuery = $before !== null
            ? ' BEFORE ' . $db->quoteValue($before)
            : '';

        foreach ($values as $value) {
            $db->createCommand($query . $db->quoteValue($value) . $beforeQuery)->execute();
        }
    }
190825
protected function combineTypes(&$types, $value)
    {
        $type = Types::guessType($value);
        switch ($type) {
            case Types::PARAM_INT:
            case Types::PARAM_BOOL:
                $types .= 'i';
                break;
            default:
                $types .= 's';
                break;
        }
    }
212582
protected function setOptionalValueInArray(string $name, &$values)
    {
        if ($this->isOptional($name) && !array_key_exists($name, $values)) {
            $default = $this->getFieldProperty($name, 'default');

            if (is_null($default)) {
                $type = $this->getFieldProperty($name, 'type');

                switch ($type) {
                    case 'list':
                        $default = array();
                        break;
                    case 'bool':
                        $default = false;
                        break;
                }
            }

            $values[$name] = $default;
        }

        return $this;
    }
27955
public function setValue($value)
    {
        if (!$this->isValid($value)) {
            throw new \UnexpectedValueException("Value '$value' is not part of the enum ".get_called_class());
        }
        $this->value = $value;
    }
164573
public function setTypeName(string $typeName, array $use = [], string $nameSpace = ''): TypeModel
    {
        $types = ['string', 'int', 'float', 'array', 'bool', 'callable'];
        $this->typeName = $typeName;
        if (!in_array($typeName, $types) && strpos($typeName, '|') === false) {
            foreach ($use as $item) {
                $items = explode('\\', $item);
                $className = array_pop($items);
                if ($className == $typeName) {
                    $this->setClassName('\\'.$item);
                    break;
                }
            }
            if (!$this->getClassName()) {
                if (strpos($typeName, '\\') !== false) {
                    $this->setClassName($typeName);
                } else {
                    $this->setClassName($nameSpace.'\\'.$typeName);
                }
            }
        }

        return $this;
    }
869607
public function create(string $className, string $typeName): Type
    {
        $type = new InputObjectType([
            'name' => $typeName,
            'description' => 'Type to specify join tables in a filter',
            'fields' => function () use ($className): array {
                return $this->getJoinsFields($className);
            },
        ]);

        return $type;
    }
282235
public function create(string $className, string $typeName): Type
    {
        $description = $this->getDescription($className);

        $fieldsGetter = function () use ($className): array {
            $factory = new InputFieldsConfigurationFactory($this->types, $this->entityManager);
            $configuration = $factory->create($className);

            return $configuration;
        };

        return new InputObjectType([
            'name' => $typeName,
            'description' => $description,
            'fields' => $fieldsGetter,
        ]);
    }