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