From c6321ea3392ffbf071424a962172aecae568bf33 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Mon, 30 Sep 2024 20:47:27 +0530 Subject: [PATCH 1/5] Changes for psalm errors detected --- composer.json | 10 +++++----- src/Api/ApigeeX/Controller/ApiProductController.php | 4 ++++ .../Normalizer/ReportCriteriaNormalizer.php | 5 ++++- src/Normalizer/ObjectNormalizer.php | 6 +++++- src/PropertyAccess/PropertyAccessorDecorator.php | 7 +++++-- src/Serializer/EntitySerializer.php | 1 + src/Serializer/EntitySerializerInterface.php | 1 + 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index d246ba42..4d2315f4 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,10 @@ "php-http/message-factory": "^1.0", "phpdocumentor/reflection-docblock": "^5.0", "psr/http-message": "^1.0 || ^2.0", - "symfony/options-resolver": "^6.4.9", - "symfony/property-access": "^6.4.9", - "symfony/property-info": "^6.4.9", - "symfony/serializer": "^6.4.9" + "symfony/options-resolver": "^7", + "symfony/property-access": "^7", + "symfony/property-info": "^7", + "symfony/serializer": "^7" }, "require-dev": { "dms/phpunit-arraysubset-asserts": "^0.4.0", @@ -46,7 +46,7 @@ "phpmetrics/phpmetrics": "^2.7", "phpunit/phpunit": "^9.6", "sebastian/comparator": "^4.0.5", - "symfony/cache": "^6.4.9", + "symfony/cache": "^7", "vimeo/psalm": "^5.20" }, "autoload": { diff --git a/src/Api/ApigeeX/Controller/ApiProductController.php b/src/Api/ApigeeX/Controller/ApiProductController.php index ad51b2c3..183713c1 100755 --- a/src/Api/ApigeeX/Controller/ApiProductController.php +++ b/src/Api/ApigeeX/Controller/ApiProductController.php @@ -70,6 +70,10 @@ public function getAvailableApixProductsByCompany(string $company, bool $active /** * {@inheritdoc} + * + * @return \Apigee\Edge\Api\Monetization\Entity\ApiProductInterface[] + * + * @psalm-return array<\Apigee\Edge\Api\Monetization\Entity\ApiProductInterface> */ public function getEligibleProductsByDeveloper(string $entityId): array { diff --git a/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php b/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php index eb28d0b5..44fd196c 100644 --- a/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php +++ b/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php @@ -63,7 +63,10 @@ public function normalize($object, $format = null, array $context = []) /** @var object $normalized */ $normalized = parent::normalize($object, $format, $context); - $addOrganizationIdCallback = function (string $id) { + $addOrganizationIdCallback = /** + * @psalm-return object{id:string, orgId:string} + */ + function (string $id): object { return (object) ['id' => $id, 'orgId' => $this->organization]; }; diff --git a/src/Normalizer/ObjectNormalizer.php b/src/Normalizer/ObjectNormalizer.php index f04f2d99..44f09ed8 100644 --- a/src/Normalizer/ObjectNormalizer.php +++ b/src/Normalizer/ObjectNormalizer.php @@ -129,8 +129,12 @@ public function setSerializer(SerializerInterface $serializer): void /** * {@inheritDoc} + * + * @param (array|mixed)[] $normalized + * + * @psalm-param array $normalized */ - public function convertToArrayObject($normalized, $array_as_props = ArrayObject::ARRAY_AS_PROPS) + public function convertToArrayObject(array $normalized, $array_as_props = ArrayObject::ARRAY_AS_PROPS): ArrayObject { // default set ARRAY_AS_PROPS flag as we need entries to be accessed as properties. return new ArrayObject($normalized, $array_as_props); diff --git a/src/PropertyAccess/PropertyAccessorDecorator.php b/src/PropertyAccess/PropertyAccessorDecorator.php index 0254c569..940824d0 100644 --- a/src/PropertyAccess/PropertyAccessorDecorator.php +++ b/src/PropertyAccess/PropertyAccessorDecorator.php @@ -171,7 +171,7 @@ private static function processTypeErrorOnGetValue($object, string $property, \T * because it is private. * * @param $message - * @param $trace + * @param (array|int|string)[][] $trace * @param $i * @param $propertyPath * @param $previous @@ -180,8 +180,11 @@ private static function processTypeErrorOnGetValue($object, string $property, \T * * @psalm-suppress PossiblyFalseOperand * @psalm-suppress PossiblyFalseArgument + * + * @psalm-param list'|'::'}> $trace + * @psalm-param 0 $i */ - private static function processTypeErrorOnSetValue($message, $trace, $i, string $propertyPath, $previous = null): void + private static function processTypeErrorOnSetValue(string $message, array $trace, int $i, string $propertyPath, $previous = null): void { if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) { return; diff --git a/src/Serializer/EntitySerializer.php b/src/Serializer/EntitySerializer.php index 87223c94..71332ae5 100755 --- a/src/Serializer/EntitySerializer.php +++ b/src/Serializer/EntitySerializer.php @@ -33,6 +33,7 @@ /** * Serializes, normalizes and denormalizes entities. */ +/** @psalm-method bool supportsNormalization(mixed $data, ?string $format = null, array $context = []) */ class EntitySerializer implements EntitySerializerInterface { /** @var \Symfony\Component\Serializer\Serializer */ diff --git a/src/Serializer/EntitySerializerInterface.php b/src/Serializer/EntitySerializerInterface.php index 4b2c57f9..ff8259e2 100755 --- a/src/Serializer/EntitySerializerInterface.php +++ b/src/Serializer/EntitySerializerInterface.php @@ -29,6 +29,7 @@ /** * Serializes, deserializes, normalizes and denormalizes entities. */ +/** @psalm-method bool supportsNormalization(mixed $data, ?string $format = null, array $context = []) */ interface EntitySerializerInterface extends NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface, SerializerInterface { /** From d895c696efed8ec5b9c15bb5a40f208cc05d4ec6 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Mon, 7 Oct 2024 19:14:56 +0530 Subject: [PATCH 2/5] Removed PHP 8.1 as symfony7 require min. PHP v8.2 --- .github/workflows/php-test-workflow.yml | 4 ---- composer.json | 2 +- src/Serializer/EntitySerializer.php | 1 - src/Serializer/EntitySerializerInterface.php | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/php-test-workflow.yml b/.github/workflows/php-test-workflow.yml index e1227ab2..b1c2b78e 100644 --- a/.github/workflows/php-test-workflow.yml +++ b/.github/workflows/php-test-workflow.yml @@ -11,10 +11,6 @@ jobs: strategy: matrix: include: - - php: '8.1' - dependencies-preference: " " - - php: '8.1' - dependencies-preference: "--prefer-lowest" - php: '8.2' dependencies-preference: " " - php: '8.2' diff --git a/composer.json b/composer.json index 4d2315f4..f8e38690 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "homepage": "http://github.com/apigee/apigee-client-php", "license": "Apache-2.0", "require": { - "php": "~8.1 || ~8.2 || ~8.3", + "php": "~8.2 || ~8.3", "ext-json": "*", "ext-openssl": "*", "ext-reflection": "*", diff --git a/src/Serializer/EntitySerializer.php b/src/Serializer/EntitySerializer.php index 09ceeb91..24e90e31 100755 --- a/src/Serializer/EntitySerializer.php +++ b/src/Serializer/EntitySerializer.php @@ -36,7 +36,6 @@ /** * Serializes, normalizes and denormalizes entities. */ -/** @psalm-method bool supportsNormalization(mixed $data, ?string $format = null, array $context = []) */ class EntitySerializer implements EntitySerializerInterface { /** @var Serializer */ diff --git a/src/Serializer/EntitySerializerInterface.php b/src/Serializer/EntitySerializerInterface.php index 503514f2..b6348a79 100755 --- a/src/Serializer/EntitySerializerInterface.php +++ b/src/Serializer/EntitySerializerInterface.php @@ -29,7 +29,6 @@ /** * Serializes, deserializes, normalizes and denormalizes entities. */ -/** @psalm-method bool supportsNormalization(mixed $data, ?string $format = null, array $context = []) */ interface EntitySerializerInterface extends NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface, SerializerInterface { /** From cf4ef2859db7aab52f71beb209f3b3f1e7ee7edd Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Mon, 14 Oct 2024 20:24:27 +0530 Subject: [PATCH 3/5] Changes reverted --- src/Api/ApigeeX/Controller/ApiProductController.php | 4 ---- .../Monetization/Normalizer/ReportCriteriaNormalizer.php | 5 +---- src/Normalizer/ObjectNormalizer.php | 6 +----- src/PropertyAccess/PropertyAccessorDecorator.php | 7 ++----- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Api/ApigeeX/Controller/ApiProductController.php b/src/Api/ApigeeX/Controller/ApiProductController.php index 871abe71..696eb99a 100755 --- a/src/Api/ApigeeX/Controller/ApiProductController.php +++ b/src/Api/ApigeeX/Controller/ApiProductController.php @@ -70,10 +70,6 @@ public function getAvailableApixProductsByCompany(string $company, bool $active /** * {@inheritdoc} - * - * @return \Apigee\Edge\Api\Monetization\Entity\ApiProductInterface[] - * - * @psalm-return array<\Apigee\Edge\Api\Monetization\Entity\ApiProductInterface> */ public function getEligibleProductsByDeveloper(string $entityId): array { diff --git a/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php b/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php index e3e39c36..ff81fbd4 100644 --- a/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php +++ b/src/Api/Monetization/Normalizer/ReportCriteriaNormalizer.php @@ -64,10 +64,7 @@ public function normalize($object, $format = null, array $context = []) /** @var object $normalized */ $normalized = parent::normalize($object, $format, $context); - $addOrganizationIdCallback = /** - * @psalm-return object{id:string, orgId:string} - */ - function (string $id): object { + $addOrganizationIdCallback = function (string $id) { return (object) ['id' => $id, 'orgId' => $this->organization]; }; diff --git a/src/Normalizer/ObjectNormalizer.php b/src/Normalizer/ObjectNormalizer.php index 08458fe0..644e9d21 100644 --- a/src/Normalizer/ObjectNormalizer.php +++ b/src/Normalizer/ObjectNormalizer.php @@ -129,12 +129,8 @@ public function setSerializer(SerializerInterface $serializer): void /** * {@inheritDoc} - * - * @param (array|mixed)[] $normalized - * - * @psalm-param array $normalized */ - public function convertToArrayObject(array $normalized, $array_as_props = ArrayObject::ARRAY_AS_PROPS): ArrayObject + public function convertToArrayObject($normalized, $array_as_props = ArrayObject::ARRAY_AS_PROPS) { // default set ARRAY_AS_PROPS flag as we need entries to be accessed as properties. return new ArrayObject($normalized, $array_as_props); diff --git a/src/PropertyAccess/PropertyAccessorDecorator.php b/src/PropertyAccess/PropertyAccessorDecorator.php index 996685a4..e47653fa 100644 --- a/src/PropertyAccess/PropertyAccessorDecorator.php +++ b/src/PropertyAccess/PropertyAccessorDecorator.php @@ -177,7 +177,7 @@ private static function processTypeErrorOnGetValue($object, string $property, Ty * because it is private. * * @param $message - * @param (array|int|string)[][] $trace + * @param $trace * @param $i * @param $propertyPath * @param $previous @@ -186,11 +186,8 @@ private static function processTypeErrorOnGetValue($object, string $property, Ty * * @psalm-suppress PossiblyFalseOperand * @psalm-suppress PossiblyFalseArgument - * - * @psalm-param list'|'::'}> $trace - * @psalm-param 0 $i */ - private static function processTypeErrorOnSetValue(string $message, array $trace, int $i, string $propertyPath, $previous = null): void + private static function processTypeErrorOnSetValue($message, $trace, $i, string $propertyPath, $previous = null): void { if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) { return; From 7da33c3a9292ae4c10e51395b519ae50ab194154 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Tue, 15 Oct 2024 17:54:51 +0530 Subject: [PATCH 4/5] Changes for symfony version --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index f8e38690..46e69ebb 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,10 @@ "php-http/message-factory": "^1.0", "phpdocumentor/reflection-docblock": "^5.0", "psr/http-message": "^1.0 || ^2.0", - "symfony/options-resolver": "^7", - "symfony/property-access": "^7", - "symfony/property-info": "^7", - "symfony/serializer": "^7" + "symfony/options-resolver": "^6.4.8 || ^7.1", + "symfony/property-access": "^6.4.9 || ^7.1", + "symfony/property-info": "^6.4.9 || ^7.1", + "symfony/serializer": "^6.4.9 || ^7.1" }, "require-dev": { "dms/phpunit-arraysubset-asserts": "^0.4.0", @@ -46,7 +46,7 @@ "phpmetrics/phpmetrics": "^2.7", "phpunit/phpunit": "^9.6", "sebastian/comparator": "^4.0.5", - "symfony/cache": "^7", + "symfony/cache": "^6.4.9 || ^7.1", "vimeo/psalm": "^5.20" }, "autoload": { From f79885bfae4c2b89356ad738859604600df952fc Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Thu, 17 Oct 2024 13:10:43 +0530 Subject: [PATCH 5/5] Version updates --- .github/workflows/php-test-workflow.yml | 2 ++ composer.json | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/php-test-workflow.yml b/.github/workflows/php-test-workflow.yml index b1c2b78e..f0cb407b 100644 --- a/.github/workflows/php-test-workflow.yml +++ b/.github/workflows/php-test-workflow.yml @@ -11,6 +11,8 @@ jobs: strategy: matrix: include: + - php: '8.1' + dependencies-preference: "--prefer-lowest" - php: '8.2' dependencies-preference: " " - php: '8.2' diff --git a/composer.json b/composer.json index 46e69ebb..85fdb403 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "homepage": "http://github.com/apigee/apigee-client-php", "license": "Apache-2.0", "require": { - "php": "~8.2 || ~8.3", + "php": "~8.1 || ~8.2 || ~8.3", "ext-json": "*", "ext-openssl": "*", "ext-reflection": "*", @@ -28,10 +28,10 @@ "php-http/message-factory": "^1.0", "phpdocumentor/reflection-docblock": "^5.0", "psr/http-message": "^1.0 || ^2.0", - "symfony/options-resolver": "^6.4.8 || ^7.1", - "symfony/property-access": "^6.4.9 || ^7.1", - "symfony/property-info": "^6.4.9 || ^7.1", - "symfony/serializer": "^6.4.9 || ^7.1" + "symfony/options-resolver": "^6.4.8 || ^7.1.1", + "symfony/property-access": "^6.4.9 || ^7.1.4", + "symfony/property-info": "^6.4.9 || ^7.1.3", + "symfony/serializer": "^6.4.9 || ^7.1.5" }, "require-dev": { "dms/phpunit-arraysubset-asserts": "^0.4.0", @@ -46,7 +46,7 @@ "phpmetrics/phpmetrics": "^2.7", "phpunit/phpunit": "^9.6", "sebastian/comparator": "^4.0.5", - "symfony/cache": "^6.4.9 || ^7.1", + "symfony/cache": "^6.4.9 || ^7.1.5", "vimeo/psalm": "^5.20" }, "autoload": {