From 363a1409550fd0250ac8f21ab50cf2f6de2ec4b8 Mon Sep 17 00:00:00 2001 From: Marcin Czarnecki Date: Sun, 30 Jul 2023 00:54:45 +0200 Subject: [PATCH 1/2] chore(composer): Update doctrine code standards --- composer.json | 2 +- phpcs.xml.dist | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 6b7f66e93..beaa350cd 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^8.1", + "doctrine/coding-standard": "^9.0", "doctrine/orm": "~2.1", "doctrine/persistence": "^1.3.3|^2.0|^3.0", "doctrine/phpcr-odm": "^1.3|^2.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index f9ad2f0e9..bc27fa482 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -96,10 +96,6 @@ tests/* - - tests/* - - From 0a8d24187115a194d5ea10f0cf42cc03cceeba59 Mon Sep 17 00:00:00 2001 From: Marcin Czarnecki Date: Sun, 30 Jul 2023 14:57:22 +0200 Subject: [PATCH 2/2] chore(composer): Update doctrine code standards to 12.x --- composer.json | 2 +- phpcs.xml.dist | 13 ++++++++++++- src/GraphNavigator/SerializationGraphNavigator.php | 1 + src/Handler/FormErrorHandler.php | 2 +- src/Handler/LazyHandlerRegistry.php | 2 ++ src/JsonDeserializationStrictVisitor.php | 1 + src/Metadata/ClassMetadata.php | 1 + .../Driver/DocBlockDriver/DocBlockTypeResolver.php | 1 + src/Metadata/Driver/XmlDriver.php | 1 + src/Twig/SerializerExtension.php | 1 + tests/Benchmark/Memory/JsonMultipleRunBench.php | 1 + tests/Benchmark/Memory/JsonSingleRunBench.php | 1 + tests/Benchmark/Memory/XmlMutlipleRunBench.php | 1 + tests/Benchmark/Memory/XmlSingleRunBench.php | 1 + tests/Fixtures/AuthorDeprecatedReadOnly.php | 1 - .../Discriminator/Serialization/ExtendedUser.php | 1 + tests/Fixtures/Discriminator/Serialization/User.php | 1 + .../CollectionOfInterfacesFromGlobalNamespace.php | 5 ++++- tests/Fixtures/Doctrine/Entity/Author.php | 3 ++- tests/Fixtures/Doctrine/Entity/AuthorExcludedId.php | 3 ++- tests/Fixtures/Doctrine/Entity/BlogPost.php | 4 +++- tests/Fixtures/Doctrine/Entity/Comment.php | 3 ++- .../Doctrine/SingleTableInheritance/Clazz.php | 6 +++++- .../SingleTableInheritance/Organization.php | 6 +++++- .../Doctrine/SingleTableInheritance/Person.php | 6 +++++- tests/Fixtures/GetSetObject.php | 5 ++++- tests/Fixtures/ObjectWithIntListAndIntMap.php | 10 ++++++++-- tests/Fixtures/ObjectWithNamespacesAndList.php | 1 - tests/Fixtures/SimpleInternalObject.php | 1 + 29 files changed, 69 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index beaa350cd..13dc0c866 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^9.0", + "doctrine/coding-standard": "^12.0", "doctrine/orm": "~2.1", "doctrine/persistence": "^1.3.3|^2.0|^3.0", "doctrine/phpcr-odm": "^1.3|^2.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index bc27fa482..95a364845 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -37,7 +37,6 @@ - @@ -60,6 +59,18 @@ + + + + + + + + + + + + diff --git a/src/GraphNavigator/SerializationGraphNavigator.php b/src/GraphNavigator/SerializationGraphNavigator.php index 975788b73..1de6e3bb7 100644 --- a/src/GraphNavigator/SerializationGraphNavigator.php +++ b/src/GraphNavigator/SerializationGraphNavigator.php @@ -104,6 +104,7 @@ public function initialize(VisitorInterface $visitor, Context $context): void assert($context instanceof SerializationContext); parent::initialize($visitor, $context); + $this->shouldSerializeNull = $context->shouldSerializeNull(); } diff --git a/src/Handler/FormErrorHandler.php b/src/Handler/FormErrorHandler.php index dde738d0a..48a8d8a0a 100644 --- a/src/Handler/FormErrorHandler.php +++ b/src/Handler/FormErrorHandler.php @@ -141,7 +141,7 @@ private function getErrorMessage(FormError $error): ?string private function convertFormToArray(SerializationVisitorInterface $visitor, FormInterface $data): \ArrayObject { - /** @var \ArrayObject{errors?: string[], children?: array} $form */ + /** @var \ArrayObject{errors?:array,children?:array} $form */ $form = new \ArrayObject(); $errors = []; foreach ($data->getErrors() as $error) { diff --git a/src/Handler/LazyHandlerRegistry.php b/src/Handler/LazyHandlerRegistry.php index a569dca43..7914aeaf3 100644 --- a/src/Handler/LazyHandlerRegistry.php +++ b/src/Handler/LazyHandlerRegistry.php @@ -31,6 +31,7 @@ public function __construct($container, array $handlers = []) } parent::__construct($handlers); + $this->container = $container; } @@ -40,6 +41,7 @@ public function __construct($container, array $handlers = []) public function registerHandler(int $direction, string $typeName, string $format, $handler): void { parent::registerHandler($direction, $typeName, $format, $handler); + unset($this->initializedHandlers[$direction][$typeName][$format]); } diff --git a/src/JsonDeserializationStrictVisitor.php b/src/JsonDeserializationStrictVisitor.php index 83299e3c5..3c4e69a85 100644 --- a/src/JsonDeserializationStrictVisitor.php +++ b/src/JsonDeserializationStrictVisitor.php @@ -29,6 +29,7 @@ public function __construct( public function setNavigator(GraphNavigatorInterface $navigator): void { parent::setNavigator($navigator); + $this->wrappedDeserializationVisitor->setNavigator($navigator); } diff --git a/src/Metadata/ClassMetadata.php b/src/Metadata/ClassMetadata.php index c8e90b913..805ec294b 100644 --- a/src/Metadata/ClassMetadata.php +++ b/src/Metadata/ClassMetadata.php @@ -185,6 +185,7 @@ public function setAccessorOrder(string $order, array $customOrder = []): void public function addPropertyMetadata(BasePropertyMetadata $metadata): void { parent::addPropertyMetadata($metadata); + $this->sortProperties(); if ($metadata instanceof PropertyMetadata && $metadata->excludeIf) { $this->usingExpression = true; diff --git a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php index 0a3d515e5..0b49017ac 100644 --- a/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php +++ b/src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php @@ -26,6 +26,7 @@ final class DocBlockTypeResolver { /** resolve single use statements */ private const SINGLE_USE_STATEMENTS_REGEX = '/^[^\S\r\n]*use[\s]*([^;\n]*)[\s]*;$/m'; + /** resolve group use statements */ private const GROUP_USE_STATEMENTS_REGEX = '/^[^\S\r\n]*use[[\s]*([^;\n]*)[\s]*{([a-zA-Z0-9\s\n\r,]*)};$/m'; private const GLOBAL_NAMESPACE_PREFIX = '\\'; diff --git a/src/Metadata/Driver/XmlDriver.php b/src/Metadata/Driver/XmlDriver.php index 2d8cca3e3..dd5436709 100644 --- a/src/Metadata/Driver/XmlDriver.php +++ b/src/Metadata/Driver/XmlDriver.php @@ -39,6 +39,7 @@ class XmlDriver extends AbstractFileDriver public function __construct(FileLocatorInterface $locator, PropertyNamingStrategyInterface $namingStrategy, ?ParserInterface $typeParser = null, ?CompilableExpressionEvaluatorInterface $expressionEvaluator = null) { parent::__construct($locator); + $this->typeParser = $typeParser ?? new Parser(); $this->namingStrategy = $namingStrategy; $this->expressionEvaluator = $expressionEvaluator; diff --git a/src/Twig/SerializerExtension.php b/src/Twig/SerializerExtension.php index 9a45ca36c..d769517f8 100644 --- a/src/Twig/SerializerExtension.php +++ b/src/Twig/SerializerExtension.php @@ -24,6 +24,7 @@ class SerializerExtension extends SerializerBaseExtension public function __construct(SerializerInterface $serializer, string $serializationFunctionsPrefix = '') { $this->serializer = $serializer; + parent::__construct($serializationFunctionsPrefix); } diff --git a/tests/Benchmark/Memory/JsonMultipleRunBench.php b/tests/Benchmark/Memory/JsonMultipleRunBench.php index f6a3e713e..3a637adc4 100644 --- a/tests/Benchmark/Memory/JsonMultipleRunBench.php +++ b/tests/Benchmark/Memory/JsonMultipleRunBench.php @@ -9,6 +9,7 @@ class JsonMultipleRunBench extends JsonSingleRunBench public function __construct() { $this->iterations = 10000; + parent::__construct(); } } diff --git a/tests/Benchmark/Memory/JsonSingleRunBench.php b/tests/Benchmark/Memory/JsonSingleRunBench.php index 91b6f9207..72ac96f54 100644 --- a/tests/Benchmark/Memory/JsonSingleRunBench.php +++ b/tests/Benchmark/Memory/JsonSingleRunBench.php @@ -12,6 +12,7 @@ public function __construct() { $this->amountOfComments = 1; $this->amountOfPosts = 1; + parent::__construct(); } diff --git a/tests/Benchmark/Memory/XmlMutlipleRunBench.php b/tests/Benchmark/Memory/XmlMutlipleRunBench.php index 152f16068..816bd7405 100644 --- a/tests/Benchmark/Memory/XmlMutlipleRunBench.php +++ b/tests/Benchmark/Memory/XmlMutlipleRunBench.php @@ -9,6 +9,7 @@ class XmlMutlipleRunBench extends XmlSingleRunBench public function __construct() { $this->iterations = 10000; + parent::__construct(); } diff --git a/tests/Benchmark/Memory/XmlSingleRunBench.php b/tests/Benchmark/Memory/XmlSingleRunBench.php index 8de6c8f0e..4e1f5df59 100644 --- a/tests/Benchmark/Memory/XmlSingleRunBench.php +++ b/tests/Benchmark/Memory/XmlSingleRunBench.php @@ -12,6 +12,7 @@ public function __construct() { $this->amountOfComments = 1; $this->amountOfPosts = 1; + parent::__construct(); } diff --git a/tests/Fixtures/AuthorDeprecatedReadOnly.php b/tests/Fixtures/AuthorDeprecatedReadOnly.php index 3e31e1dc2..50d213580 100644 --- a/tests/Fixtures/AuthorDeprecatedReadOnly.php +++ b/tests/Fixtures/AuthorDeprecatedReadOnly.php @@ -5,7 +5,6 @@ namespace JMS\Serializer\Tests\Fixtures; use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\ReadOnly; use JMS\Serializer\Annotation\SerializedName; use JMS\Serializer\Annotation\Type; use JMS\Serializer\Annotation\XmlRoot; diff --git a/tests/Fixtures/Discriminator/Serialization/ExtendedUser.php b/tests/Fixtures/Discriminator/Serialization/ExtendedUser.php index e7f4e2a75..bfdbc4ef8 100644 --- a/tests/Fixtures/Discriminator/Serialization/ExtendedUser.php +++ b/tests/Fixtures/Discriminator/Serialization/ExtendedUser.php @@ -20,6 +20,7 @@ class ExtendedUser extends User public function __construct($id, $name, $description, $extendAttribute) { parent::__construct($id, $name, $description); + $this->extendAttribute = $extendAttribute; } } diff --git a/tests/Fixtures/Discriminator/Serialization/User.php b/tests/Fixtures/Discriminator/Serialization/User.php index 89efb92da..9b74931b8 100644 --- a/tests/Fixtures/Discriminator/Serialization/User.php +++ b/tests/Fixtures/Discriminator/Serialization/User.php @@ -38,6 +38,7 @@ class User extends Entity public function __construct(int $id, string $name, string $description) { parent::__construct($id); + $this->name = $name; $this->description = $description; } diff --git a/tests/Fixtures/DocBlockType/Collection/CollectionOfInterfacesFromGlobalNamespace.php b/tests/Fixtures/DocBlockType/Collection/CollectionOfInterfacesFromGlobalNamespace.php index a166a623f..5736da14d 100644 --- a/tests/Fixtures/DocBlockType/Collection/CollectionOfInterfacesFromGlobalNamespace.php +++ b/tests/Fixtures/DocBlockType/Collection/CollectionOfInterfacesFromGlobalNamespace.php @@ -4,11 +4,14 @@ namespace JMS\Serializer\Tests\Fixtures\DocBlockType\Collection; +use JMS\Serializer\Tests\Fixtures\DocBlockType\Collection\Details\ProductColor; + class CollectionOfInterfacesFromGlobalNamespace { /** * phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName - * @var \JMS\Serializer\Tests\Fixtures\DocBlockType\Collection\Details\ProductColor[] + * + * @var ProductColor[] */ public array $productColors; } diff --git a/tests/Fixtures/Doctrine/Entity/Author.php b/tests/Fixtures/Doctrine/Entity/Author.php index 6d2c4ef78..5c04d19ee 100644 --- a/tests/Fixtures/Doctrine/Entity/Author.php +++ b/tests/Fixtures/Doctrine/Entity/Author.php @@ -12,7 +12,8 @@ class Author { /** - * @ORM\Id @ORM\Column(type="integer") + * @ORM\Id + * @ORM\Column(type="integer") * * @Groups({"id_group"}) */ diff --git a/tests/Fixtures/Doctrine/Entity/AuthorExcludedId.php b/tests/Fixtures/Doctrine/Entity/AuthorExcludedId.php index 8a87003b3..215160554 100644 --- a/tests/Fixtures/Doctrine/Entity/AuthorExcludedId.php +++ b/tests/Fixtures/Doctrine/Entity/AuthorExcludedId.php @@ -12,7 +12,8 @@ class AuthorExcludedId { /** - * @ORM\Id @ORM\Column(type="integer") + * @ORM\Id + * @ORM\Column(type="integer") * * @Exclude */ diff --git a/tests/Fixtures/Doctrine/Entity/BlogPost.php b/tests/Fixtures/Doctrine/Entity/BlogPost.php index 43ffcb5c6..d49b7e903 100644 --- a/tests/Fixtures/Doctrine/Entity/BlogPost.php +++ b/tests/Fixtures/Doctrine/Entity/BlogPost.php @@ -23,7 +23,9 @@ class BlogPost { /** - * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue(strategy="AUTO") + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; diff --git a/tests/Fixtures/Doctrine/Entity/Comment.php b/tests/Fixtures/Doctrine/Entity/Comment.php index a8fad7e41..402685f70 100644 --- a/tests/Fixtures/Doctrine/Entity/Comment.php +++ b/tests/Fixtures/Doctrine/Entity/Comment.php @@ -11,7 +11,8 @@ class Comment { /** - * @ORM\Id @ORM\Column(type="integer") + * @ORM\Id + * @ORM\Column(type="integer") */ protected $id; diff --git a/tests/Fixtures/Doctrine/SingleTableInheritance/Clazz.php b/tests/Fixtures/Doctrine/SingleTableInheritance/Clazz.php index 4a994d744..001f9223e 100644 --- a/tests/Fixtures/Doctrine/SingleTableInheritance/Clazz.php +++ b/tests/Fixtures/Doctrine/SingleTableInheritance/Clazz.php @@ -12,7 +12,11 @@ */ class Clazz extends AbstractModel { - /** @ORM\Id @ORM\GeneratedValue(strategy = "AUTO") @ORM\Column(type = "integer") */ + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ private $id; /** @ORM\ManyToOne(targetEntity = "JMS\Serializer\Tests\Fixtures\Doctrine\SingleTableInheritance\Teacher") */ diff --git a/tests/Fixtures/Doctrine/SingleTableInheritance/Organization.php b/tests/Fixtures/Doctrine/SingleTableInheritance/Organization.php index 0309bead2..8c2edb809 100644 --- a/tests/Fixtures/Doctrine/SingleTableInheritance/Organization.php +++ b/tests/Fixtures/Doctrine/SingleTableInheritance/Organization.php @@ -16,6 +16,10 @@ */ abstract class Organization { - /** @ORM\Id @ORM\GeneratedValue(strategy = "AUTO") @ORM\Column(type = "integer") */ + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ private $id; } diff --git a/tests/Fixtures/Doctrine/SingleTableInheritance/Person.php b/tests/Fixtures/Doctrine/SingleTableInheritance/Person.php index 107ad52b5..b10e33ee1 100644 --- a/tests/Fixtures/Doctrine/SingleTableInheritance/Person.php +++ b/tests/Fixtures/Doctrine/SingleTableInheritance/Person.php @@ -17,6 +17,10 @@ */ abstract class Person extends AbstractModel { - /** @ORM\Id @ORM\GeneratedValue(strategy = "AUTO") @ORM\Column(type = "integer") */ + /** + * @ORM\Id + * @ORM\Column(type = "integer") + * @ORM\GeneratedValue(strategy = "AUTO") + */ private $id; } diff --git a/tests/Fixtures/GetSetObject.php b/tests/Fixtures/GetSetObject.php index ba4c48efa..088f9758e 100644 --- a/tests/Fixtures/GetSetObject.php +++ b/tests/Fixtures/GetSetObject.php @@ -13,7 +13,10 @@ #[AccessType(type: 'public_method')] class GetSetObject { - /** @AccessType("property") @Type("integer") */ + /** + * @AccessType("property") + * @AccessType("property") + @Type("integer") */ #[AccessType(type: 'property')] #[Type(name: 'integer')] private $id = 1; diff --git a/tests/Fixtures/ObjectWithIntListAndIntMap.php b/tests/Fixtures/ObjectWithIntListAndIntMap.php index 9cf6fe28a..9c0e804de 100644 --- a/tests/Fixtures/ObjectWithIntListAndIntMap.php +++ b/tests/Fixtures/ObjectWithIntListAndIntMap.php @@ -8,12 +8,18 @@ class ObjectWithIntListAndIntMap { - /** @Serializer\Type("array") @Serializer\XmlList */ + /** + * @Serializer\Type("array") + * @Serializer\Type("array") + @Serializer\XmlList */ #[Serializer\Type(name: 'array')] #[Serializer\XmlList] private $list; - /** @Serializer\Type("array") @Serializer\XmlMap */ + /** + * @Serializer\Type("array") + * @Serializer\Type("array") + @Serializer\XmlMap */ #[Serializer\Type(name: 'array')] #[Serializer\XmlMap] private $map; diff --git a/tests/Fixtures/ObjectWithNamespacesAndList.php b/tests/Fixtures/ObjectWithNamespacesAndList.php index ff069eed2..a936a7665 100644 --- a/tests/Fixtures/ObjectWithNamespacesAndList.php +++ b/tests/Fixtures/ObjectWithNamespacesAndList.php @@ -114,7 +114,6 @@ class ObjectWithNamespacesAndList #[Type(name: 'array')] #[SerializedName(name: 'phones')] #[XmlList(entry: 'phone', inline: false)] - public $phonesAlternativeD; /** * @Type("array") diff --git a/tests/Fixtures/SimpleInternalObject.php b/tests/Fixtures/SimpleInternalObject.php index 638a6a45b..01a847e1d 100644 --- a/tests/Fixtures/SimpleInternalObject.php +++ b/tests/Fixtures/SimpleInternalObject.php @@ -19,6 +19,7 @@ class SimpleInternalObject extends \Exception public function __construct($foo, $bar) { parent::__construct($foo); + $this->bar = $bar; } }