forked from loafle/openapi-generator-original
		
	Small tweaks for php generator, PHPStan level 3 (#7616)
This commit is contained in:
		
							parent
							
								
									ec74b06d2c
								
							
						
					
					
						commit
						240c046f35
					
				@ -77,12 +77,16 @@ class ObjectSerializer
 | 
			
		||||
                foreach ($data::openAPITypes() as $property => $openAPIType) {
 | 
			
		||||
                    $getter = $data::getters()[$property];
 | 
			
		||||
                    $value = $data->$getter();
 | 
			
		||||
                    if ($value !== null
 | 
			
		||||
                        && !in_array($openAPIType, [{{&primitives}}], true)
 | 
			
		||||
                        && method_exists($openAPIType, 'getAllowableEnumValues')
 | 
			
		||||
                        && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
 | 
			
		||||
                        $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
 | 
			
		||||
                        throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
 | 
			
		||||
                    if ($value !== null && !in_array($openAPIType, [{{&primitives}}], true)) {
 | 
			
		||||
                        $callable = [$openAPIType, 'getAllowableEnumValues'];
 | 
			
		||||
                        if (is_callable($callable)) {
 | 
			
		||||
                            /** array $callable */
 | 
			
		||||
                            $allowedEnumTypes = $callable();
 | 
			
		||||
                            if (!in_array($value, $allowedEnumTypes, true)) {
 | 
			
		||||
                                $imploded = implode("', '", $allowedEnumTypes);
 | 
			
		||||
                                throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if ($value !== null) {
 | 
			
		||||
                        $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
 | 
			
		||||
@ -159,8 +163,9 @@ class ObjectSerializer
 | 
			
		||||
     */
 | 
			
		||||
    public static function toHeaderValue($value)
 | 
			
		||||
    {
 | 
			
		||||
        if (method_exists($value, 'toHeaderValue')) {
 | 
			
		||||
            return $value->toHeaderValue();
 | 
			
		||||
        $callable = [$value, 'toHeaderValue'];
 | 
			
		||||
        if (is_callable($callable)) {
 | 
			
		||||
            return $callable();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return self::toString($value);
 | 
			
		||||
@ -307,6 +312,7 @@ class ObjectSerializer
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /** @psalm-suppress ParadoxicalCondition */
 | 
			
		||||
        if (in_array($class, [{{&primitives}}], true)) {
 | 
			
		||||
            settype($data, $class);
 | 
			
		||||
            return $data;
 | 
			
		||||
@ -346,6 +352,8 @@ class ObjectSerializer
 | 
			
		||||
                    $class = $subclass;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /** @var ModelInterface $instance */
 | 
			
		||||
            $instance = new $class();
 | 
			
		||||
            foreach ($instance::openAPITypes() as $property => $type) {
 | 
			
		||||
                $propertySetter = $instance::setters()[$property];
 | 
			
		||||
 | 
			
		||||
@ -87,12 +87,16 @@ class ObjectSerializer
 | 
			
		||||
                foreach ($data::openAPITypes() as $property => $openAPIType) {
 | 
			
		||||
                    $getter = $data::getters()[$property];
 | 
			
		||||
                    $value = $data->$getter();
 | 
			
		||||
                    if ($value !== null
 | 
			
		||||
                        && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
 | 
			
		||||
                        && method_exists($openAPIType, 'getAllowableEnumValues')
 | 
			
		||||
                        && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
 | 
			
		||||
                        $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
 | 
			
		||||
                        throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
 | 
			
		||||
                    if ($value !== null && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
 | 
			
		||||
                        $callable = [$openAPIType, 'getAllowableEnumValues'];
 | 
			
		||||
                        if (is_callable($callable)) {
 | 
			
		||||
                            /** array $callable */
 | 
			
		||||
                            $allowedEnumTypes = $callable();
 | 
			
		||||
                            if (!in_array($value, $allowedEnumTypes, true)) {
 | 
			
		||||
                                $imploded = implode("', '", $allowedEnumTypes);
 | 
			
		||||
                                throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if ($value !== null) {
 | 
			
		||||
                        $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
 | 
			
		||||
@ -169,8 +173,9 @@ class ObjectSerializer
 | 
			
		||||
     */
 | 
			
		||||
    public static function toHeaderValue($value)
 | 
			
		||||
    {
 | 
			
		||||
        if (method_exists($value, 'toHeaderValue')) {
 | 
			
		||||
            return $value->toHeaderValue();
 | 
			
		||||
        $callable = [$value, 'toHeaderValue'];
 | 
			
		||||
        if (is_callable($callable)) {
 | 
			
		||||
            return $callable();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return self::toString($value);
 | 
			
		||||
@ -317,6 +322,7 @@ class ObjectSerializer
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /** @psalm-suppress ParadoxicalCondition */
 | 
			
		||||
        if (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
 | 
			
		||||
            settype($data, $class);
 | 
			
		||||
            return $data;
 | 
			
		||||
@ -356,6 +362,8 @@ class ObjectSerializer
 | 
			
		||||
                    $class = $subclass;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /** @var ModelInterface $instance */
 | 
			
		||||
            $instance = new $class();
 | 
			
		||||
            foreach ($instance::openAPITypes() as $property => $type) {
 | 
			
		||||
                $propertySetter = $instance::setters()[$property];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user