From 605ff66148c8bdb0a866789dbcd8cd4a5b482eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 21:55:54 +0200 Subject: [PATCH 1/7] Specify BuilderCollection element type This stops PHPStan from complaining: Class Ramsey\Uuid\Builder\BuilderCollection extends generic class Ramsey\Collection\AbstractCollection but does not specify its types: T --- src/Builder/BuilderCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Builder/BuilderCollection.php b/src/Builder/BuilderCollection.php index 0997971..81072af 100644 --- a/src/Builder/BuilderCollection.php +++ b/src/Builder/BuilderCollection.php @@ -26,6 +26,8 @@ use Traversable; /** * A collection of UuidBuilderInterface objects + * + * @extends AbstractCollection */ class BuilderCollection extends AbstractCollection { From aeb5e4d297d4884579cc377b3e62aa59275e72ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:00:21 +0200 Subject: [PATCH 2/7] Specify NodeProviderCollection element type This stops PHPStan from complaining: Class Ramsey\Uuid\Provider\Node\NodeProviderCollection extends generic class Ramsey\Collection\AbstractCollection but does not specify its types: T --- src/Provider/Node/NodeProviderCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Provider/Node/NodeProviderCollection.php b/src/Provider/Node/NodeProviderCollection.php index c49398e..11854b0 100644 --- a/src/Provider/Node/NodeProviderCollection.php +++ b/src/Provider/Node/NodeProviderCollection.php @@ -20,6 +20,8 @@ use Ramsey\Uuid\Type\Hexadecimal; /** * A collection of NodeProviderInterface objects + * + * @extends AbstractCollection */ class NodeProviderCollection extends AbstractCollection { From 63231900f95e0b4e6c8956065dc5e8ad0e7caa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:14:18 +0200 Subject: [PATCH 3/7] Ignore some PHPStan "no effect" errors in tests PHPStan errors like these: Call to method Ramsey\Uuid\Builder\FallbackBuilder::build() on a separate line has no effect. can be safely ignored here. The lack of effect is intentional as we are testing exceptions. --- tests/phpstan-tests.neon | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpstan-tests.neon b/tests/phpstan-tests.neon index 1973ce3..d7d0cc7 100644 --- a/tests/phpstan-tests.neon +++ b/tests/phpstan-tests.neon @@ -27,3 +27,12 @@ parameters: message: "#^Function uuid_parse\\(\\) has parameter \\$uuid with no typehint specified\\.$#" count: 1 path: phpstan-bootstrap.php + - + message: "#^Call to method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" + paths: + - Builder/*Test.php + - Converter/*Test.php + - Generator/*Test.php + - Guid/*Test.php + - Nonstandard/*Test.php + - Rfc4122/*Test.php From 19291c6491495b3d0cf2a9e85e7b3552ac6f9df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:27:44 +0200 Subject: [PATCH 4/7] Ignore some PHPStan "no effect" errors for static methods in tests PHPStan errors like these: Call to static method Ramsey\Uuid\Uuid::fromString() on a separate line has no effect. can be safely ignored here. The lack of effect is intentional as we are testing exceptions. --- tests/phpstan-tests.neon | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpstan-tests.neon b/tests/phpstan-tests.neon index d7d0cc7..76b6c78 100644 --- a/tests/phpstan-tests.neon +++ b/tests/phpstan-tests.neon @@ -27,6 +27,10 @@ parameters: message: "#^Function uuid_parse\\(\\) has parameter \\$uuid with no typehint specified\\.$#" count: 1 path: phpstan-bootstrap.php + - + message: "#^Call to static method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" + paths: + - *Test.php - message: "#^Call to method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" paths: From c02c911ea625990ef15e4919ab75f42e82b1be4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:36:18 +0200 Subject: [PATCH 5/7] Ignore some PHPStan "no effect" errors in benchmarks PHPStan errors like these: Call to static method Ramsey\Uuid\Uuid::uuid3() on a separate line has no effect. can be safely ignored here. The lack of effect is intentional in benchmarks. --- tests/phpstan-tests.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpstan-tests.neon b/tests/phpstan-tests.neon index 76b6c78..06d411d 100644 --- a/tests/phpstan-tests.neon +++ b/tests/phpstan-tests.neon @@ -31,6 +31,7 @@ parameters: message: "#^Call to static method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" paths: - *Test.php + - benchmark/*Bench.php - message: "#^Call to method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" paths: From 7e4909e764b089d4e597a6d2087eb73aa77493e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:44:43 +0200 Subject: [PATCH 6/7] Assure unserialized BuilderCollection contains only valid elements This stops Psalm from complaining about MixedPropertyTypeCoercion --- src/Builder/BuilderCollection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Builder/BuilderCollection.php b/src/Builder/BuilderCollection.php index 81072af..560b060 100644 --- a/src/Builder/BuilderCollection.php +++ b/src/Builder/BuilderCollection.php @@ -69,6 +69,11 @@ class BuilderCollection extends AbstractCollection ], ]); - $this->data = $data; + $this->data = array_filter( + $data, + function ($unserialized): bool { + return $unserialized instanceof UuidBuilderInterface; + } + ); } } From fe475968dbd8a120e2c558161b686431ca49567d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20S=C5=82owik?= Date: Mon, 24 May 2021 22:48:58 +0200 Subject: [PATCH 7/7] Assure unserialized NodeProviderCollection contains only valid elements This stops Psalm from complaining about MixedPropertyTypeCoercion --- src/Provider/Node/NodeProviderCollection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Provider/Node/NodeProviderCollection.php b/src/Provider/Node/NodeProviderCollection.php index 11854b0..33cd608 100644 --- a/src/Provider/Node/NodeProviderCollection.php +++ b/src/Provider/Node/NodeProviderCollection.php @@ -50,6 +50,11 @@ class NodeProviderCollection extends AbstractCollection ], ]); - $this->data = $data; + $this->data = array_filter( + $data, + function ($unserialized): bool { + return $unserialized instanceof NodeProviderInterface; + } + ); } }