Menu
Error Identifier: doctrine.findOneByArgument
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\Mapping as ORM;
#[ORM\Entity]
class User
{
#[ORM\Id]
#[ORM\Column]
private int $id;
#[ORM\Column]
private string $email;
}
<?php declare(strict_types = 1);
/** @var \Doctrine\ORM\EntityRepository<User> $repository */
$user = $repository->findOneBy(['username' => 'john']);
Why is it reported? #
This error is reported by the phpstan-doctrine extension.
The criteria array passed to findOneBy() contains a key (username) that does not correspond to any field or association on the entity (User). This likely indicates a typo or a reference to a field that does not exist.
How to fix it #
Use a field name that exists on the entity:
<?php declare(strict_types = 1);
/** @var \Doctrine\ORM\EntityRepository<User> $repository */
-$user = $repository->findOneBy(['username' => 'john']);
+$user = $repository->findOneBy(['email' => 'john@example.com']);
How to ignore this error #
You can use the identifier doctrine.findOneByArgument to ignore this error using a comment:
// @phpstan-ignore doctrine.findOneByArgument
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.findOneByArgument
Rules that report this error #
- PHPStan\Rules\Doctrine\ORM\RepositoryMethodCallRule [1] phpstan/phpstan-doctrine