Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.3.x' into 1.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 21, 2023
2 parents ffb83c1 + 68fc764 commit eb6e8eb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use function get_class;
use function in_array;
use function is_object;
use function method_exists;

Expand All @@ -34,7 +35,7 @@ public function getClass(): string

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return true;
return in_array($methodReflection->getName(), ['add', 'addMultiple'], true);
}

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type\Doctrine\QueryBuilder\Expr;

use PHPStan\Testing\TypeInferenceTestCase;

class BaseExpressionDynamicReturnTypeExtensionTest extends TypeInferenceTestCase
{

/** @return iterable<mixed> */
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/../../data/QueryResult/baseExpressionAndOr.php');
}

/**
* @dataProvider dataFileAsserts
* @param mixed ...$args
*/
public function testFileAsserts(
string $assertType,
string $file,
...$args
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

/** @return string[] */
public static function getAdditionalConfigFiles(): array
{
return [__DIR__ . '/../../data/QueryResult/config.neon'];
}

}
16 changes: 16 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/baseExpressionAndOr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace QueryResult\CreateQuery;

use Doctrine\ORM\Query\Expr\Andx;
use function PHPStan\Testing\assertType;

$and = new Andx();
$count1 = $and->count();
assertType("int<0, max>", $count1);

$modifiedAnd = $and->add('a = b');
assertType("Doctrine\ORM\Query\Expr\Andx", $modifiedAnd);

$string = $and->__toString();
assertType("string", $string);

0 comments on commit eb6e8eb

Please sign in to comment.