From 82a726642204a61b1141035f053cc36a3a44129e Mon Sep 17 00:00:00 2001 From: jdrieghe Date: Wed, 26 Jan 2022 15:44:29 +0100 Subject: [PATCH 1/3] Add tests to prove that nullable reference or shasum in Dist will cause the object hydration to fail --- .../Packagist/Api/Result/Package/DistSpec.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/Packagist/Api/Result/Package/DistSpec.php b/spec/Packagist/Api/Result/Package/DistSpec.php index d09f83e..d55ac25 100644 --- a/spec/Packagist/Api/Result/Package/DistSpec.php +++ b/spec/Packagist/Api/Result/Package/DistSpec.php @@ -43,4 +43,28 @@ public function it_gets_shasum() { $this->getShasum()->shouldReturn('cb0a489db41707d5df078f1f35e028e04ffd9e8e'); } + + public function it_can_deal_with_nullable_reference() + { + $this->fromArray([ + 'type' => 'git', + 'url' => 'https://github.com/Sylius/Sylius.git', + 'reference' => null, + 'shasum' => 'cb0a489db41707d5df078f1f35e028e04ffd9e8e', + ]); + + $this->getReference()->shouldReturn(null); + } + + public function it_can_deal_with_nullable_shasum() + { + $this->fromArray([ + 'type' => 'git', + 'url' => 'https://github.com/Sylius/Sylius.git', + 'reference' => 'cb0a489db41707d5df078f1f35e028e04ffd9e8e', + 'shasum' => null, + ]); + + $this->getShasum()->shouldReturn(null); + } } From c0d32f11bf5b26d4a67abb5e0d2d782e2325d17e Mon Sep 17 00:00:00 2001 From: jdrieghe Date: Wed, 26 Jan 2022 15:46:30 +0100 Subject: [PATCH 2/3] Decouple Dist from Source object. All shared properties were overwritten anyway and the inheritance didn't really make sense --- src/Packagist/Api/Result/Package/Dist.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Packagist/Api/Result/Package/Dist.php b/src/Packagist/Api/Result/Package/Dist.php index c85a5c4..40b6565 100644 --- a/src/Packagist/Api/Result/Package/Dist.php +++ b/src/Packagist/Api/Result/Package/Dist.php @@ -4,7 +4,9 @@ namespace Packagist\Api\Result\Package; -class Dist extends Source +use Packagist\Api\Result\AbstractResult; + +class Dist extends AbstractResult { protected string $shasum; From ca4431777d638980adf2bfb3750d13e24129fe0e Mon Sep 17 00:00:00 2001 From: jdrieghe Date: Wed, 26 Jan 2022 15:48:23 +0100 Subject: [PATCH 3/3] Mark shasum and reference property of Dist as nullable This is the case in, for example, https://packagist.org/packages/roots/wordpress.json --- src/Packagist/Api/Result/Package/Dist.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Packagist/Api/Result/Package/Dist.php b/src/Packagist/Api/Result/Package/Dist.php index 40b6565..2f9cd96 100644 --- a/src/Packagist/Api/Result/Package/Dist.php +++ b/src/Packagist/Api/Result/Package/Dist.php @@ -8,15 +8,15 @@ class Dist extends AbstractResult { - protected string $shasum; + protected ?string $shasum; protected string $type; protected string $url; - protected string $reference; + protected ?string $reference; - public function getShasum(): string + public function getShasum(): ?string { return $this->shasum; } @@ -31,7 +31,7 @@ public function getUrl(): string return $this->url; } - public function getReference(): string + public function getReference(): ?string { return $this->reference; }