diff --git a/Plugin.php b/Plugin.php index 35ab809..afd5588 100644 --- a/Plugin.php +++ b/Plugin.php @@ -12,6 +12,8 @@ use function class_exists; use function glob; +use const GLOB_BRACE; + class Plugin implements PluginEntryPointInterface { /** @return void */ @@ -27,7 +29,7 @@ public function __invoke(RegistrationInterface $psalm, ?SimpleXMLElement $config /** @return string[] */ private function getStubFiles(): array { - return glob(__DIR__ . '/' . 'stubs/*.php'); + return glob(__DIR__ . '/' . 'stubs/{,*/}*.php', GLOB_BRACE); } /** @return string[] */ diff --git a/stubs/DBAL/QueryBuilder.php b/stubs/DBAL/QueryBuilder.php new file mode 100644 index 0000000..7fa7d7d --- /dev/null +++ b/stubs/DBAL/QueryBuilder.php @@ -0,0 +1,91 @@ +having([$expr])->distinct(); + builder()->andHaving([$expr])->distinct(); """ When I run Psalm Then I see no errors diff --git a/tests/acceptance/QueryBuilderDbal.feature b/tests/acceptance/QueryBuilderDbal.feature new file mode 100644 index 0000000..9390220 --- /dev/null +++ b/tests/acceptance/QueryBuilderDbal.feature @@ -0,0 +1,131 @@ +Feature: QueryBuilderDbal + In order to use Doctrine DBAL QueryBuilder safely + As a Psalm user + I need Psalm to typecheck QueryBuilder + + Background: + Given I have the following config + """ + + + + + + + + + + """ + And I have the following code preamble + """ + select('field1', 'field2'); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::select accepts array argument + Given I have the following code + """ + builder()->select(['field1', 'field1']); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::addSelect accepts variadic arguments + Given I have the following code + """ + builder()->addSelect('field1', 'field2'); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::addSelect accepts array argument + Given I have the following code + """ + builder()->addSelect(['field1', 'field2']); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::where, ::orWhere and ::andWhere accept variadic arguments + Given I have the following code + """ + builder()->where('field1', 'field2') + ->andWhere('field1', 'field2') + ->orWhere('field1', 'field2'); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::where, ::orWhere and ::andWhere accept CompositeExpression + Given I have the following code + """ + $expr = builder()->expr(); + $orx = $expr->orX(); + $orx->add($expr->eq('field1', 1)); + $orx->add($expr->eq('field1', 2)); + builder()->where($orx)->andWhere($orx)->orWhere($orx); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::groupBy ::addGroupBy accept variadic arguments + Given I have the following code + """ + builder()->groupBy('field1', 'field2') + ->addGroupBy('field1', 'field2'); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::groupBy ::addGroupBy accept array argument + Given I have the following code + """ + builder()->groupBy(['field1', 'field2']) + ->addGroupBy(['field1', 'field2']); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::having, ::orHaving and ::andHaving accept variadic arguments + Given I have the following code + """ + builder()->having('field1', 'field2') + ->orHaving('field1', 'field2') + ->andHaving('field1', 'field2'); + """ + When I run Psalm + Then I see no errors + + @QueryBuilderDbal + Scenario: Dbal QueryBuilder ::having, ::orHaving and ::andHaving accept CompositeExpression + Given I have the following code + """ + $andx = builder()->expr()->andX('a = b'); + builder()->having($andx)->orHaving($andx)->andHaving($andx); + """ + When I run Psalm + Then I see no errors