From b6034d7a7c72ea8ea54c9bf1b029e6e27d6ab933 Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 16:59:56 +0300 Subject: [PATCH 1/8] Add a stub for `Criteria` --- stubs/Criteria.stubs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 stubs/Criteria.stubs diff --git a/stubs/Criteria.stubs b/stubs/Criteria.stubs new file mode 100644 index 0000000..abe09ae --- /dev/null +++ b/stubs/Criteria.stubs @@ -0,0 +1,24 @@ + + */ + public function orderBy(array $orderings) + { + } +} From ba31af965ec477a7e3cae9f2d64351bd6a9a4d2a Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:10:52 +0300 Subject: [PATCH 2/8] Add tests for Criteria --- tests/acceptance/Criteria.feature | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/acceptance/Criteria.feature diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature new file mode 100644 index 0000000..1bc3b31 --- /dev/null +++ b/tests/acceptance/Criteria.feature @@ -0,0 +1,62 @@ +Feature: Criteria + In order to use Doctrine Criteria + As a Psalm user + I need Psalm to typecheck Criteria + + Background: + Given I have Doctrine plugin enabled + And I have the following code preamble + """ + matching(Criteria::create()); + } + """ + When I run Psalm + Then I see no errors + + @Criteria::orderBy + Scenario: Order a Criteria in a pure context + Given I have the following code + """ + /** @psalm-pure */ + function foo(): void + { + $collection = new ArrayCollection(); + $collection->matching(Criteria::create()->orderBy('foo' => Criteria::ASC)); + } + """ + When I run Psalm + Then I see no errors + + @Criteria::orderBy + Scenario: Invalid sorting provided to matching + Given I have the following code + """ + /** @psalm-pure */ + function foo(): void + { + $collection = new ArrayCollection(); + $collection->matching(Criteria::create()->orderBy('foo' => 'bar')); + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | todo | todo | + And I see no other errors From 19e4aa2e1eacd014071d92eb39e6602357374996 Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:15:38 +0300 Subject: [PATCH 3/8] Remove redundant `use` --- tests/acceptance/Criteria.feature | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature index 1bc3b31..6404a76 100644 --- a/tests/acceptance/Criteria.feature +++ b/tests/acceptance/Criteria.feature @@ -9,9 +9,7 @@ Feature: Criteria """ Date: Thu, 11 Aug 2022 17:24:17 +0300 Subject: [PATCH 4/8] Fix test --- tests/acceptance/Criteria.feature | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature index 6404a76..92c1de6 100644 --- a/tests/acceptance/Criteria.feature +++ b/tests/acceptance/Criteria.feature @@ -8,7 +8,7 @@ Feature: Criteria And I have the following code preamble """ matching(Criteria::create()); + return $collection->matching(Criteria::create()); } """ When I run Psalm @@ -33,10 +32,9 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(): void + function foo(Collection $collection): Collection { - $collection = new ArrayCollection(); - $collection->matching(Criteria::create()->orderBy('foo' => Criteria::ASC)); + return $collection->matching(Criteria::create()->orderBy(['foo' => Criteria::ASC])); } """ When I run Psalm @@ -47,10 +45,9 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(): void + function foo(Collection $collection): Collection { - $collection = new ArrayCollection(); - $collection->matching(Criteria::create()->orderBy('foo' => 'bar')); + return $collection->matching(Criteria::create()->orderBy(['foo' => 'bar'])); } """ When I run Psalm From a3774c2161176edeb195873debd704e903cc9e6e Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:29:48 +0300 Subject: [PATCH 5/8] Fix test --- tests/acceptance/Criteria.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature index 92c1de6..202b561 100644 --- a/tests/acceptance/Criteria.feature +++ b/tests/acceptance/Criteria.feature @@ -8,7 +8,7 @@ Feature: Criteria And I have the following code preamble """ matching(Criteria::create()); } @@ -32,7 +32,7 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(Collection $collection): Collection + function foo(Selectable $collection): Selectable { return $collection->matching(Criteria::create()->orderBy(['foo' => Criteria::ASC])); } @@ -45,7 +45,7 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(Collection $collection): Collection + function foo(Selectable $collection): Selectable { return $collection->matching(Criteria::create()->orderBy(['foo' => 'bar'])); } From 8f3a1e26227e7bb1cf0f7b98bbcd61301ef4e313 Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:31:07 +0300 Subject: [PATCH 6/8] Mark `Selectable::matching` as a mutation free --- stubs/Collections.phpstub | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/Collections.phpstub b/stubs/Collections.phpstub index 165465d..6b7ea0f 100644 --- a/stubs/Collections.phpstub +++ b/stubs/Collections.phpstub @@ -170,6 +170,7 @@ interface Collection extends Countable, IteratorAggregate, ArrayAccess interface Selectable { /** + * @psalm-mutation-free * @return Collection */ public function matching(Criteria $criteria); From 507b79145944be077ff16862add3b77413e4b484 Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:37:54 +0300 Subject: [PATCH 7/8] Update Criteria.feature --- tests/acceptance/Criteria.feature | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/Criteria.feature b/tests/acceptance/Criteria.feature index 202b561..91e8285 100644 --- a/tests/acceptance/Criteria.feature +++ b/tests/acceptance/Criteria.feature @@ -8,8 +8,9 @@ Feature: Criteria And I have the following code preamble """ matching(Criteria::create()); } @@ -32,7 +33,7 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(Selectable $collection): Selectable + function foo(Selectable $collection): Collection { return $collection->matching(Criteria::create()->orderBy(['foo' => Criteria::ASC])); } @@ -45,7 +46,7 @@ Feature: Criteria Given I have the following code """ /** @psalm-pure */ - function foo(Selectable $collection): Selectable + function foo(Selectable $collection): Collection { return $collection->matching(Criteria::create()->orderBy(['foo' => 'bar'])); } From 5e1ae012f0a38b2d16ba6cb41f93e099909ce606 Mon Sep 17 00:00:00 2001 From: fluffycondor <62219548+fluffycondor@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:46:38 +0300 Subject: [PATCH 8/8] Rename Criteria.stubs to Criteria.phpstub --- stubs/{Criteria.stubs => Criteria.phpstub} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stubs/{Criteria.stubs => Criteria.phpstub} (100%) diff --git a/stubs/Criteria.stubs b/stubs/Criteria.phpstub similarity index 100% rename from stubs/Criteria.stubs rename to stubs/Criteria.phpstub