From b872b41140493b169977817dfb74c536c267f579 Mon Sep 17 00:00:00 2001 From: Aerendir Date: Sat, 12 Oct 2024 09:58:31 +0200 Subject: [PATCH 1/5] Disable Dependabot. --- .github/{dependabot.yml => disabled_dependabot.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{dependabot.yml => disabled_dependabot.yml} (100%) diff --git a/.github/dependabot.yml b/.github/disabled_dependabot.yml similarity index 100% rename from .github/dependabot.yml rename to .github/disabled_dependabot.yml From 46e3b1cb550540a8456e272b2c90c23a459a163d Mon Sep 17 00:00:00 2001 From: Aerendir Date: Sat, 19 Oct 2024 13:33:01 +0200 Subject: [PATCH 2/5] Improve creation of a `SubscribedRechargeableFeature` from array. --- .../SubscribedRechargeableFeature.php | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php index 91a09a2d..03807549 100644 --- a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php +++ b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php @@ -18,7 +18,6 @@ use function Safe\json_decode; use function Safe\json_encode; -use function Safe\sprintf; final class SubscribedRechargeableFeature extends AbstractSubscribedFeature implements SubscribedFeatureInterface, CanBeConsumedInterface { @@ -33,21 +32,29 @@ final class SubscribedRechargeableFeature extends AbstractSubscribedFeature impl private SubscribedRechargeableFeaturePack $rechargingPack; /** @var int $remainedQuantity The amount of remained units */ - private $remainedQuantity = 0; + private int $remainedQuantity = 0; public function __construct(string $name, array $details = []) { // Set the type $details[self::FIELD_TYPE] = self::TYPE_RECHARGEABLE; - $this->setRemainedQuantity($details['remained_quantity']); - $this->lastRechargeOn = $details['last_recharge_on']; - $this->lastRechargeQuantity = $details['last_recharge_quantity']; + if (false === array_key_exists('remained_quantity', $details) || null === $details['remained_quantity']) { + throw new \InvalidArgumentException('The key "remained_quantity" is mandatory for a subscribed rechargeable feature. You must provide it.'); + } - if (null !== $this->lastRechargeOn && ! $this->lastRechargeOn instanceof \DateTime) { - $this->lastRechargeOn = new \DateTime($this->lastRechargeOn['date'], new \DateTimeZone($this->lastRechargeOn['timezone'])); + if (false === array_key_exists('last_recharge_on', $details) || null === $details['last_recharge_on']) { + throw new \InvalidArgumentException('The key "last_recharge_on" is mandatory for a subscribed rechargeable feature. You must provide it.'); } + if (false === array_key_exists('last_recharge_quantity', $details) || null === $details['last_recharge_quantity']) { + throw new \InvalidArgumentException('The key "last_recharge_quantity" is mandatory for a subscribed rechargeable feature. You must provide it.'); + } + + $this->setRemainedQuantity($details['remained_quantity']); + $this->setLastRechargedOn($details['last_recharge_on']); + $this->lastRechargeQuantity = $details['last_recharge_quantity']; + parent::__construct($name, $details); } @@ -102,4 +109,14 @@ public function toArray(): array 'last_recharge_quantity' => $this->getLastRechargeQuantity(), ], parent::toArray(), $this->consumedToArray()); } + + private function setLastRechargedOn(\DateTimeInterface|array $lastRechargeOn): SubscribedRechargeableFeature + { + if (is_array($lastRechargeOn)) { + $lastRechargeOn = new \DateTime($lastRechargeOn['date'], new \DateTimeZone($lastRechargeOn['timezone'])); + } + $this->lastRechargeOn = $lastRechargeOn; + + return $this; + } } From 61a2df621249bccd5ed559b0268d2d3a4d1b3385 Mon Sep 17 00:00:00 2001 From: Aerendir Date: Sat, 19 Oct 2024 13:33:54 +0200 Subject: [PATCH 3/5] Fix `SubscribedRechargeableFeature::setRechargingPack()` method name. --- src/Form/DataTransformer/RechargeableFeatureTransformer.php | 2 +- src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Form/DataTransformer/RechargeableFeatureTransformer.php b/src/Form/DataTransformer/RechargeableFeatureTransformer.php index 2f7ea3c7..1500d839 100644 --- a/src/Form/DataTransformer/RechargeableFeatureTransformer.php +++ b/src/Form/DataTransformer/RechargeableFeatureTransformer.php @@ -44,7 +44,7 @@ public function reverseTransform($pack): SubscribedRechargeableFeature /** @var SubscribedRechargeableFeature $subscribedFeature */ $subscribedFeature = $this->getCurrentTransformingFeature(); - $subscribedFeature->setRecharginPack($subscribedPack); + $subscribedFeature->setRechargingPack($subscribedPack); // Call recharge, so the form can automatically update the feature $subscribedFeature->recharge(); diff --git a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php index 03807549..6693f914 100644 --- a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php +++ b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php @@ -95,7 +95,7 @@ public function recharge(): SubscribedRechargeableFeature return $this; } - public function setRecharginPack(SubscribedRechargeableFeaturePack $rechargingPack): SubscribedRechargeableFeature + public function setRechargingPack(SubscribedRechargeableFeaturePack $rechargingPack): SubscribedRechargeableFeature { $this->rechargingPack = $rechargingPack; From 1f78188dab217e97ef3c75d925c18a535aeab7d6 Mon Sep 17 00:00:00 2001 From: Aerendir Date: Sat, 19 Oct 2024 13:34:02 +0200 Subject: [PATCH 4/5] Update baselines. --- .baseline-phan.php | 6 +- .baseline-phpstan.neon | 155 ----------------------------------------- .baseline-psalm.xml | 19 ----- psalm.xml | 1 - 4 files changed, 3 insertions(+), 178 deletions(-) diff --git a/.baseline-phan.php b/.baseline-phan.php index f0118228..1291a4d2 100644 --- a/.baseline-phan.php +++ b/.baseline-phan.php @@ -18,11 +18,12 @@ // PhanUndeclaredProperty : 8 occurrences // PhanTypeMismatchDeclaredReturn : 6 occurrences // PhanUnreferencedProtectedMethod : 6 occurrences + // PhanTypeMismatchReturnSuperType : 5 occurrences // PhanTypeMismatchArgumentSuperType : 4 occurrences - // PhanTypeMismatchReturnSuperType : 4 occurrences // PhanTypeMismatchArgumentNullable : 3 occurrences // PhanUnusedPublicFinalMethodParameter : 3 occurrences // PhanWriteOnlyPrivateProperty : 3 occurrences + // PhanCompatibleUnionType : 2 occurrences // PhanTypeArraySuspicious : 2 occurrences // PhanTypeMismatchDimAssignment : 2 occurrences // PhanUndeclaredTypeParameter : 2 occurrences @@ -30,7 +31,6 @@ // ConstReferenceClassNotImported : 1 occurrence // PhanAccessClassInternal : 1 occurrence // PhanCompatiblePHP7 : 1 occurrence - // PhanCompatibleUnionType : 1 occurrence // PhanPossiblyNullTypeMismatchProperty : 1 occurrence // PhanReadOnlyPrivateProperty : 1 occurrence // PhanTypeInvalidLeftOperandOfNumericOp : 1 occurrence @@ -73,7 +73,7 @@ 'src/Model/Feature/Subscribed/SubscribedBooleanFeature.php' => ['PhanUnreferencedPrivateProperty'], 'src/Model/Feature/Subscribed/SubscribedCountableFeature.php' => ['ConstReferenceClassNotImported', 'PhanUndeclaredMethod'], 'src/Model/Feature/Subscribed/SubscribedFeaturesCollection.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchDeclaredReturn', 'PhanUnreferencedProtectedMethod'], - 'src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php' => ['PhanDeprecatedFunction', 'PhanWriteOnlyPrivateProperty'], + 'src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php' => ['PhanCompatibleUnionType', 'PhanTypeMismatchReturnSuperType', 'PhanWriteOnlyPrivateProperty'], 'src/Model/Invoice.php' => ['PhanDeprecatedFunction', 'PhanParamSignatureMismatch', 'PhanTypeArraySuspicious', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimAssignment', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnNullable'], 'src/Model/InvoiceInterface.php' => ['PhanUnextractableAnnotationElementName', 'PhanUnextractableAnnotationSuffix'], 'src/Model/InvoiceLine.php' => ['PhanPossiblyNullTypeMismatchProperty'], diff --git a/.baseline-phpstan.neon b/.baseline-phpstan.neon index e20ffd85..ec53e09a 100644 --- a/.baseline-phpstan.neon +++ b/.baseline-phpstan.neon @@ -80,26 +80,6 @@ parameters: count: 1 path: src/InvoiceDrawer/PlainTextDrawer.php - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\AbstractFeature\\:\\:__construct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/AbstractFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\AbstractFeaturePack\\:\\:__construct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/AbstractFeaturePack.php - - - - message: "#^Cannot clone non\\-object variable \\$element of type mixed\\.$#" - count: 1 - path: src/Model/Feature/AbstractFeaturesCollection.php - - - - message: "#^Class SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\AbstractFeaturesCollection extends generic class Doctrine\\\\Common\\\\Collections\\\\ArrayCollection but does not specify its types\\: TKey, T$#" - count: 1 - path: src/Model/Feature/AbstractFeaturesCollection.php - - message: "#^Argument of an invalid type array\\|Countable supplied for foreach, only iterables are supported\\.$#" count: 1 @@ -430,11 +410,6 @@ parameters: count: 1 path: src/Model/Feature/Configured/ConfiguredRechargeableFeaturePack.php - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\FeatureInterface\\:\\:__construct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/FeatureInterface.php - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Property\\\\HasRecurringPricesInterface\\:\\:getPrices\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -485,61 +460,6 @@ parameters: count: 1 path: src/Model/Feature/Subscribed/SubscribedBooleanFeature.php - - - message: "#^Class DateTime is unsafe to use\\. Its methods can return FALSE instead of throwing an exception\\. Please add 'use Safe\\\\DateTime;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#" - count: 6 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Instanceof between SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeaturePack and SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Configured\\\\ConfiguredCountableFeaturePack will always evaluate to false\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeature\\:\\:RecurringFeatureConstruct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeature\\:\\:__construct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeature\\:\\:consumedToArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeature\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Property SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedCountableFeature\\:\\:\\$remainedQuantity has no type specified\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Strict comparison using \\=\\=\\= between null and DateTimeInterface will always evaluate to false\\.$#" - count: 2 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Strict comparison using \\=\\=\\= between null and int will always evaluate to false\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedCountableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedFeatureInterface\\:\\:setConfiguredFeature\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedFeatureInterface.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedFeatureInterface\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedFeatureInterface.php - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedFeaturePack\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -595,26 +515,6 @@ parameters: count: 1 path: src/Model/Feature/Subscribed/SubscribedFeaturesCollection.php - - - message: "#^Class DateTime is unsafe to use\\. Its methods can return FALSE instead of throwing an exception\\. Please add 'use Safe\\\\DateTime;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#" - count: 2 - path: src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedRechargeableFeature\\:\\:__construct\\(\\) has parameter \\$details with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedRechargeableFeature\\:\\:consumedToArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\Feature\\\\Subscribed\\\\SubscribedRechargeableFeature\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php - - message: "#^Cannot access offset '_header' on SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSection\\.$#" count: 1 @@ -695,36 +595,6 @@ parameters: count: 2 path: src/Model/Invoice.php - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceInterface\\:\\:getLine\\(\\) has parameter \\$id with no type specified\\.$#" - count: 1 - path: src/Model/InvoiceInterface.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceInterface\\:\\:getLines\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/InvoiceInterface.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceInterface\\:\\:getSections\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/InvoiceInterface.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceInterface\\:\\:jsonUnserialize\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Model/InvoiceInterface.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceInterface\\:\\:setHeader\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Model/InvoiceInterface.php - - - - message: "#^PHPDoc tag @param has invalid value \\(string\\!int \\$id\\)\\: Unexpected token \"\\!\", expected variable at offset 102$#" - count: 1 - path: src/Model/InvoiceInterface.php - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceLine\\:\\:__toArray\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -745,31 +615,6 @@ parameters: count: 1 path: src/Model/InvoiceLine.php - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSection\\:\\:getLines\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/InvoiceSection.php - - - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSection\\:\\:jsonSerialize\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Model/InvoiceSection.php - - - - message: "#^Property SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSection\\:\\:\\$header \\(SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSectionHeader\\) does not accept null\\.$#" - count: 1 - path: src/Model/InvoiceSection.php - - - - message: "#^Result of && is always false\\.$#" - count: 1 - path: src/Model/InvoiceSection.php - - - - message: "#^Strict comparison using \\=\\=\\= between false and true will always evaluate to false\\.$#" - count: 1 - path: src/Model/InvoiceSection.php - - message: "#^Method SerendipityHQ\\\\Bundle\\\\FeaturesBundle\\\\Model\\\\InvoiceSectionHeader\\:\\:__toArray\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 diff --git a/.baseline-psalm.xml b/.baseline-psalm.xml index 6392b209..d5440b6e 100644 --- a/.baseline-psalm.xml +++ b/.baseline-psalm.xml @@ -42,10 +42,6 @@ - - - - @@ -59,10 +55,6 @@ - - - - @@ -73,10 +65,6 @@ - - - - @@ -90,10 +78,6 @@ - - - - @@ -534,9 +518,6 @@ - - - features]]> features]]> diff --git a/psalm.xml b/psalm.xml index 5341c3db..809cbf6d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,5 @@ Date: Sat, 19 Oct 2024 13:34:53 +0200 Subject: [PATCH 5/5] Use `isset()` in `SubscribedRechargeableFeature::hasRechargingPack()`. --- src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php index 6693f914..e0db1168 100644 --- a/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php +++ b/src/Model/Feature/Subscribed/SubscribedRechargeableFeature.php @@ -82,7 +82,7 @@ public function getRechargingPack(): SubscribedRechargeableFeaturePack public function hasRechargingPack(): bool { - return null !== $this->rechargingPack; + return isset($this->rechargingPack); } public function recharge(): SubscribedRechargeableFeature