Menu

Error Identifier: doctrine.findByArgument

← Back to doctrine.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class User
{
	#[ORM\Id]
	#[ORM\Column]
	public int $id;

	#[ORM\Column]
	public string $name;
}

function doFoo(EntityManager $em): void
{
	$repository = $em->getRepository(User::class);
	$repository->findBy(['nonexistent' => 'test']);
}

Why is it reported? #

The findBy() method on a Doctrine entity repository accepts an array of field names as criteria. The field nonexistent does not exist on the User entity, so the call will fail at runtime with a Doctrine exception.

When bleeding edge is enabled, the field names in the second argument (the order-by array) are checked the same way:

$repository->findBy(['name' => 'test'], ['nonexistent' => 'ASC']);

This rule is provided by the phpstan-doctrine extension.

How to fix it #

Use a field name that actually exists on the entity:

- $repository->findBy(['nonexistent' => 'test']);
+ $repository->findBy(['name' => 'test']);

The same applies to the order-by argument:

- $repository->findBy(['name' => 'test'], ['nonexistent' => 'ASC']);
+ $repository->findBy(['name' => 'test'], ['id' => 'ASC']);

How to ignore this error #

You can use the identifier doctrine.findByArgument to ignore this error using a comment:

// @phpstan-ignore doctrine.findByArgument
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: doctrine.findByArgument

Rules that report this error #

  • PHPStan\Rules\Doctrine\ORM\RepositoryMethodCallRule [1] [2] phpstan/phpstan-doctrine
Theme
A
© 2026 PHPStan s.r.o.