diff --git a/src/Accessor/DefaultAccessorStrategy.php b/src/Accessor/DefaultAccessorStrategy.php index a3c25a326..47d4b27b4 100644 --- a/src/Accessor/DefaultAccessorStrategy.php +++ b/src/Accessor/DefaultAccessorStrategy.php @@ -86,9 +86,7 @@ public function getValue(object $object, PropertyMetadata $metadata, Serializati $accessor = $this->readAccessors[$metadata->class] ?? null; if (null === $accessor) { - $accessor = \Closure::bind(static function ($o, $name) { - return $o->$name; - }, null, $metadata->class); + $accessor = \Closure::bind(static fn($o, $name) => $o->$name, null, $metadata->class); $this->readAccessors[$metadata->class] = $accessor; } diff --git a/src/Annotation/ReadOnly.php b/src/Annotation/ReadOnly.php index 23bff2630..2cc9a61d5 100644 --- a/src/Annotation/ReadOnly.php +++ b/src/Annotation/ReadOnly.php @@ -2,4 +2,4 @@ declare(strict_types=1); -class_alias('JMS\Serializer\Annotation\DeprecatedReadOnly', 'JMS\Serializer\Annotation\ReadOnly'); +class_alias(\JMS\Serializer\Annotation\DeprecatedReadOnly::class, 'JMS\Serializer\Annotation\ReadOnly'); diff --git a/src/Metadata/Driver/AnnotationOrAttributeDriver.php b/src/Metadata/Driver/AnnotationOrAttributeDriver.php index 8e1b52343..4ecfb8fee 100644 --- a/src/Metadata/Driver/AnnotationOrAttributeDriver.php +++ b/src/Metadata/Driver/AnnotationOrAttributeDriver.php @@ -307,9 +307,7 @@ protected function getClassAnnotations(\ReflectionClass $class): array if (PHP_VERSION_ID >= 80000) { $annotations = array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $class->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } @@ -330,9 +328,7 @@ protected function getMethodAnnotations(\ReflectionMethod $method): array if (PHP_VERSION_ID >= 80000) { $annotations = array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $method->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } @@ -353,9 +349,7 @@ protected function getPropertyAnnotations(\ReflectionProperty $property): array if (PHP_VERSION_ID >= 80000) { $annotations = array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $property->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } diff --git a/src/Metadata/Driver/AttributeDriver.php b/src/Metadata/Driver/AttributeDriver.php index e966791c2..0a7949692 100644 --- a/src/Metadata/Driver/AttributeDriver.php +++ b/src/Metadata/Driver/AttributeDriver.php @@ -14,9 +14,7 @@ class AttributeDriver extends AnnotationOrAttributeDriver protected function getClassAnnotations(\ReflectionClass $class): array { return array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $class->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } @@ -27,9 +25,7 @@ static function (\ReflectionAttribute $attribute): object { protected function getMethodAnnotations(\ReflectionMethod $method): array { return array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $method->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } @@ -40,9 +36,7 @@ static function (\ReflectionAttribute $attribute): object { protected function getPropertyAnnotations(\ReflectionProperty $property): array { return array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $property->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF), ); } diff --git a/src/Metadata/Driver/AttributeDriver/AttributeReader.php b/src/Metadata/Driver/AttributeDriver/AttributeReader.php index 91e8aa83a..71a3c98db 100644 --- a/src/Metadata/Driver/AttributeDriver/AttributeReader.php +++ b/src/Metadata/Driver/AttributeDriver/AttributeReader.php @@ -85,9 +85,7 @@ private function buildAnnotation(array $attributes): ?SerializerAttribute private function buildAnnotations(array $attributes): array { return array_map( - static function (\ReflectionAttribute $attribute): object { - return $attribute->newInstance(); - }, + static fn(\ReflectionAttribute $attribute): object => $attribute->newInstance(), $attributes, ); } diff --git a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php index 4e43cf6e0..0bca2deb5 100644 --- a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php +++ b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php @@ -115,17 +115,13 @@ private function getDocBlocTypeHint($reflector): ?string // Generic array syntax: array | array<\Foo\Bar\Product> | array if ($type instanceof GenericTypeNode) { if ($this->isSimpleType($type->type, 'array')) { - $resolvedTypes = array_map(function (TypeNode $node) use ($reflector) { - return $this->resolveTypeFromTypeNode($node, $reflector); - }, $type->genericTypes); + $resolvedTypes = array_map(fn(TypeNode $node) => $this->resolveTypeFromTypeNode($node, $reflector), $type->genericTypes); return 'array<' . implode(',', $resolvedTypes) . '>'; } if ($this->isSimpleType($type->type, 'list')) { - $resolvedTypes = array_map(function (TypeNode $node) use ($reflector) { - return $this->resolveTypeFromTypeNode($node, $reflector); - }, $type->genericTypes); + $resolvedTypes = array_map(fn(TypeNode $node) => $this->resolveTypeFromTypeNode($node, $reflector), $type->genericTypes); return 'array'; } @@ -194,9 +190,7 @@ private function flattenParamTagValueTypes(string $parameterName, array $varTagV */ private function filterNullFromTypes(array $types): array { - return array_values(array_filter(array_map(function (TypeNode $node) { - return $this->isNullType($node) ? null : $node; - }, $types))); + return array_values(array_filter(array_map(fn(TypeNode $node) => $this->isNullType($node) ? null : $node, $types))); } /** @@ -427,9 +421,7 @@ private function getPhpstanType(\ReflectionClass $declaringClass, string $typeHi return sprintf('array<%s>', implode( ',', - array_map(static function (string $type) use ($reflector, $self) { - return $self->resolveType(trim($type), $reflector); - }, $types), + array_map(static fn(string $type) => $self->resolveType(trim($type), $reflector), $types), )); } } diff --git a/src/Ordering/AlphabeticalPropertyOrderingStrategy.php b/src/Ordering/AlphabeticalPropertyOrderingStrategy.php index a60d3cb09..b7c982ae3 100644 --- a/src/Ordering/AlphabeticalPropertyOrderingStrategy.php +++ b/src/Ordering/AlphabeticalPropertyOrderingStrategy.php @@ -15,9 +15,7 @@ public function order(array $properties): array { uasort( $properties, - static function (PropertyMetadata $a, PropertyMetadata $b): int { - return strcmp($a->name, $b->name); - }, + static fn(PropertyMetadata $a, PropertyMetadata $b): int => strcmp($a->name, $b->name), ); return $properties; diff --git a/src/XmlSerializationVisitor.php b/src/XmlSerializationVisitor.php index ae150aa66..8406d75b4 100644 --- a/src/XmlSerializationVisitor.php +++ b/src/XmlSerializationVisitor.php @@ -318,9 +318,7 @@ public function visitProperty(PropertyMetadata $metadata, $v): void } if ($addEnclosingElement = !$this->isInLineCollection($metadata) && !$metadata->inline) { - $namespace = null !== $metadata->xmlNamespace - ? $metadata->xmlNamespace - : $this->getClassDefaultNamespace($this->objectMetadataStack->top()); + $namespace = $metadata->xmlNamespace ?? $this->getClassDefaultNamespace($this->objectMetadataStack->top()); $element = $this->createElement($metadata->serializedName, $namespace); $this->currentNode->appendChild($element);