Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a marker interface for annotation/attribute classes #1529

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Annotation/AccessType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Johannes M. Schmitt <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY)]
final class AccessType
final class AccessType implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Accessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Johannes M. Schmitt <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class Accessor
final class Accessor implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/AccessorOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Johannes M. Schmitt <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class AccessorOrder
final class AccessorOrder implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Discriminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class Discriminator
class Discriminator implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Exclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY", "CLASS", "METHOD", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
final class Exclude
final class Exclude implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ExclusionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class ExclusionPolicy
final class ExclusionPolicy implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Expose.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class Expose
final class Expose implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class Groups
final class Groups implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class Inline
final class Inline implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/MaxDepth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class MaxDepth
final class MaxDepth implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/PostDeserialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
* @author Johannes M. Schmitt <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
final class PostDeserialize
final class PostDeserialize implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/PostSerialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @Target("METHOD")
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
final class PostSerialize
final class PostSerialize implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/PreSerialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* @author Johannes M. Schmitt <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
final class PreSerialize
final class PreSerialize implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/ReadOnlyProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @final
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY)]
/* final */ class ReadOnlyProperty
/* final */ class ReadOnlyProperty implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/SerializedName.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY","METHOD", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class SerializedName
final class SerializedName implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
12 changes: 12 additions & 0 deletions src/Annotation/SerializerAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace JMS\Serializer\Annotation;

/**
* Marker interface for serializer attributes
*/
interface SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/SkipWhenEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class SkipWhenEmpty
final class SkipWhenEmpty implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY", "METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class Type
final class Type implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Annotation;

abstract class Version
abstract class Version implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/VirtualProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Alexander Klimenkov <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
final class VirtualProperty
final class VirtualProperty implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY", "METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class XmlAttribute
final class XmlAttribute implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlAttributeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @Target({"PROPERTY", "METHOD"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class XmlAttributeMap
final class XmlAttributeMap implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/XmlCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Annotation;

abstract class XmlCollection
abstract class XmlCollection implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlDiscriminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class XmlDiscriminator
class XmlDiscriminator implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY", "METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class XmlElement
final class XmlElement implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlKeyValuePairs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class XmlKeyValuePairs
final class XmlKeyValuePairs implements SerializerAttribute
{
}
2 changes: 1 addition & 1 deletion src/Annotation/XmlNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
final class XmlNamespace
final class XmlNamespace implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target("CLASS")
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class XmlRoot
final class XmlRoot implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/XmlValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @Target({"PROPERTY","METHOD","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
final class XmlValue
final class XmlValue implements SerializerAttribute
{
use AnnotationUtilsTrait;

Expand Down
30 changes: 7 additions & 23 deletions src/Metadata/Driver/AnnotationOrAttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use JMS\Serializer\Annotation\PreSerialize;
use JMS\Serializer\Annotation\ReadOnlyProperty;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\SerializerAttribute;
use JMS\Serializer\Annotation\Since;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
Expand Down Expand Up @@ -48,8 +49,6 @@
use Metadata\Driver\DriverInterface;
use Metadata\MethodMetadata;

use function array_filter;

class AnnotationOrAttributeDriver implements DriverInterface
{
use ExpressionMetadataTrait;
Expand Down Expand Up @@ -291,7 +290,7 @@
}
}

if (!$configured) {

Check failure on line 293 in src/Metadata/Driver/AnnotationOrAttributeDriver.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.2)

Empty IF statement detected
// return null;
// uncomment the above line afetr a couple of months
}
Expand All @@ -300,7 +299,7 @@
}

/**
* @return list<object>
* @return list<SerializerAttribute>
*/
protected function getClassAnnotations(\ReflectionClass $class): array
{
Expand All @@ -311,12 +310,7 @@
static function (\ReflectionAttribute $attribute): object {
return $attribute->newInstance();
},
array_filter(
$class->getAttributes(),
static function (\ReflectionAttribute $attribute): bool {
return class_exists($attribute->getName());
}
)
$class->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF)
);
}

Expand All @@ -328,7 +322,7 @@
}

/**
* @return list<object>
* @return list<SerializerAttribute>
*/
protected function getMethodAnnotations(\ReflectionMethod $method): array
{
Expand All @@ -339,12 +333,7 @@
static function (\ReflectionAttribute $attribute): object {
return $attribute->newInstance();
},
array_filter(
$method->getAttributes(),
static function (\ReflectionAttribute $attribute): bool {
return class_exists($attribute->getName());
}
)
$method->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF)
);
}

Expand All @@ -356,7 +345,7 @@
}

/**
* @return list<object>
* @return list<SerializerAttribute>
*/
protected function getPropertyAnnotations(\ReflectionProperty $property): array
{
Expand All @@ -367,12 +356,7 @@
static function (\ReflectionAttribute $attribute): object {
return $attribute->newInstance();
},
array_filter(
$property->getAttributes(),
static function (\ReflectionAttribute $attribute): bool {
return class_exists($attribute->getName());
}
)
$property->getAttributes(SerializerAttribute::class, \ReflectionAttribute::IS_INSTANCEOF)
);
}

Expand Down
Loading
Loading