Skip to content

Commit

Permalink
fix: dynamic wheres can have a mixed parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-feek committed Mar 2, 2020
1 parent 56b0b2c commit 304edc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Methods/BuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MissingMethodFromReflectionException;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\Php\DummyParameter;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
Expand Down Expand Up @@ -53,11 +55,17 @@ public function dynamicWhere(
/** @var FunctionVariantWithPhpDocs $originalDynamicWhereVariant */
$originalDynamicWhereVariant = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());

/** @var \PHPStan\Reflection\ParameterReflectionWithPhpDocs $originalParameter */
$originalParameter = $originalDynamicWhereVariant->getParameters()[1];

$actualParameter = new DummyParameter($originalParameter->getName(), new MixedType(), $originalParameter->isOptional(), $originalParameter->passedByReference(), $originalParameter->isVariadic(), $originalParameter->getDefaultValue());

return new EloquentBuilderMethodReflection(
$methodName,
$classReflection,
[$originalDynamicWhereVariant->getParameters()[1]],
$returnObject
[$actualParameter],
$returnObject,
true
);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Features/Methods/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ public function testGroupBy(): EloquentBuilder
{
return User::query()->groupBy('foo', 'bar');
}

public function testDynamicWhereAsString(): ?User
{
return (new User())->whereFoo('bar')->first();
}

public function testDynamicWhereMultiple(): ?User
{
return User::whereIdAndEmail(1, 'foo@example.com')->first();
}

public function testDynamicWhereAsInt(): ?User
{
return (new User())->whereFoo(1)->first();
}
}

0 comments on commit 304edc0

Please sign in to comment.