@param $enum

@return Enum $this
@throws \UnexpectedValueException
433934
protected function setEnum($enum)
    {
        if ($enum === null) {
            $enum = $this->default;
        }

        if (!\array_key_exists($enum, $this->enumsReversed)) {
            throw new \UnexpectedValueException("Enum '{$enum}' does not exist");
        }

        $this->enum = $enum;

        return $this;
    }
337043
public function asEnumerated(): Primitive\Enumerated
    {
        if (!$this->_element instanceof Primitive\Enumerated) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
        }
        return $this->_element;
    }
349051
final public function equals($value)
    {
        if ($value instanceof Enum) {
            return $this->value == $value->getValue();
        }
        return $this->value == $value;
    }
1290892
protected function enum(string $name, array $values): Closure
    {
        $this->createEnum($name, $values);

        return $this->useEnum($name, $name, true);
    }
225383
private static function initializeEnum($enumClass)
    {
        self::$isInInitializationState = true;
        try {
            $classReflection = new ReflectionClass($enumClass);

            // Enumerable must be final:
            if (!$classReflection->isFinal()) {
                throw new LogicException(
                    sprintf('Enumerable class must be final, but "%s" is not final.', $enumClass)
                );
            }

            // Enumerable cannot be Serializable:
            if (is_subclass_of($enumClass, \Serializable::class)) {
                throw new LogicException(
                    sprintf(
                        'Enumerable cannot be serializable, but enum class "%s" implements "Serializable" interface.',
                        $enumClass
                    )
                );
            }

            $methods = $classReflection->getMethods(ReflectionMethod::IS_STATIC);

            self::$enums[$enumClass] = [];
            foreach ($methods as $method) {
                if (self::isServiceMethod($method)) {
                    continue;
                }

                /** @var Enumerable $value */
                $value = $method->invoke(null);

                if (!is_object($value) || get_class($value) !== $enumClass) {
                    throw new LogicException(sprintf(
                        '"%s:%s()" should return an instance of its class. But value of type "%s" returned.',
                        $enumClass,
                        $method,
                        is_object($value) ? get_class($value) : gettype($value)
                    ));
                }

                // Detect duplication of indexes:
                if (array_key_exists($value->getRawValue(), self::$enums[$enumClass])) {
                    throw new LogicException(
                        sprintf('Duplicate of index "%s" in enumerable "%s".', $value->getRawValue(), $enumClass)
                    );
                }
                self::$enums[$enumClass][$value->getRawValue()] = $value;
            }
        } finally {
            self::$isInInitializationState = false;
        }
    }
785588
public function setAttribute($key, $value)
    {
        if ($this->isEnumAttribute($key)) {
            $enumClass = $this->getEnumClass($key);
            if (! $value instanceof $enumClass) {
                $value = new $enumClass($value);
            }

            $this->attributes[$key] = $value->value();

            return $this;
        }

        parent::setAttribute($key, $value);
    }
1203661
public function setValue($value)
	{
		// set default
		if( $value === "" )
		{
			$value = $this->value;
		}

		if( $this->type === "boolean" )
		{
			$value = is_bool($value) ? $value : in_array($value, ['y', 'yes', 'on', '1']);
		}
		else if( $this->type === "number" )
		{
			if( ! is_numeric($value) )
			{
				throw new \InvalidArgumentException($this->getTheTitle() . " must be a number");
			}
			$value = (float) $value;
			if( $this->required && $value === 0 )
			{
				throw new \InvalidArgumentException($this->getTheTitle() . " is required");
			}
		}
		else if( $this->type === "enum" )
		{
			if( ! in_array($value, $this->enum, true) )
			{
				$variant = "'" . implode("' or '", $this->enum) . "'";
				throw new \InvalidArgumentException($this->getTheTitle() . " must be equal " . $variant);
			}
		}
		else
		{
			$value = trim($value);
			if( $this->required && ! strlen($value) )
			{
				throw new \InvalidArgumentException($this->getTheTitle() . " is required");
			}
		}

		if( $this->type_of )
		{
			$value = call_user_func($this->type_of, $value);
			if( $value === false && $this->type !== "boolean" )
			{
				throw new \InvalidArgumentException($this->getTheTitle() . " value is invalid");
			}
		}

		$this->value = $value;
		return $this;
	}
692518
private function setEnum(string $enum): self
    {
        $this->updatePropertyValue(
            EnumFieldInterface::PROP_ENUM,
            $enum
        );

        return $this;
    }
1355736
public function setOptions($var)
    {
        GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class);
        $this->options = $var;
        $this->has_options = true;

        return $this;
    }
1079146
protected function setEnums(array $constants)
    {
        $tempConstants = $constants;

        if (\array_key_exists(self::$defaultKey, $tempConstants)) {
            unset($tempConstants[self::$defaultKey]);
        }

        if (empty($tempConstants)) {
            throw new \UnexpectedValueException("No constants set");
        }

        $this->enums         = $tempConstants;
        $this->enumsReversed = \array_flip($this->enums);

        return $this;
    }
579088
public function setType($type)
    {
        if ($type === null) {
            $this->$type = $type;
        } else {
            $iconSetType = new IconSetTypeEnum($type);
            $this->type = $iconSetType->getValue();
        }

        return $this;
    }
882876
public static function fromValue($value)
    {
        $values = static::getValues();
        if (array_key_exists($value, $values)) {
            return new static($values[$value], $value);
        }
        throw new \InvalidArgumentException("No enum constant value '$value' class " . get_called_class());
    }
1103044
public function set($key, $value)
    {
        $result = $this->allowed($value);
        if ($this->passes($result)) {
            parent::set($key, $this->normalize($value));
        } else {
            throw new \UnexpectedValueException(sprintf(
                'Value of type "%s" forbidden in this instance of %s',
                gettype($value),
                get_class($this)
            ));
        }
    }
82655
public function has(Enum $enum)
    {
        $this->checkType($enum);

        return isset($this->valueMap[$enum->getConstName()]);
    }
29528
public function remove(Enum $enum)
    {
        $this->checkType($enum);

        $enumName = $enum->getConstName();

        if (isset($this->valueMap[$enumName])) {
            $value = $this->valueMap[$enumName];

            unset($this->valueMap[$enumName]);

            $index = array_search($enum, $this->mappedEnums);
            unset($this->mappedEnums[$index]);

            return $value;
        }

        return null;
    }
632852
public function setType($type)
    {
        /**
         * Thoses WordType::__MIN and WordType::__MAX values are
         * only used to check if given type is okay according to
         * what we have in WordType.
         *
         * @see src/Client/Api/Enum/WordType.php
         */
        if (!($type >= WordType::__MIN && $type <= WordType::__MAX)) {
            throw new InvalidWordTypeException();
        }
        $this->type = $type;

        return $this;
    }
355038
public function setValue($var)
    {
        $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class);
        $this->value = $arr;
        $this->has_value = true;

        return $this;
    }