Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic wheres can have a mixed parameter #482

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}