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

PossiblyUnusedParam error reported despite parameter usage #159

Open
crosart opened this issue Jan 29, 2025 · 2 comments
Open

PossiblyUnusedParam error reported despite parameter usage #159

crosart opened this issue Jan 29, 2025 · 2 comments

Comments

@crosart
Copy link

crosart commented Jan 29, 2025

Hi there !

I'm currently using Psalm v6.0.0 (Problem already happening in Psalm v5.2) configured at errorLevel 3, with the psalm/plugin-symfony and weirdan/doctrine-psalm-plugin plugins installed.

Psalm reports several PossiblyUnusedParam as ERRORS despite these parameters being used (seemingly can't be unused).

The documentation recommends prefixing such parameters with _ to ignore this error, which I tried but to no avail.

It resembles a clear false positive to me given the following example :

ERROR: PossiblyUnusedParam
at /home/project/src/Repository/ApiTokenRepository.php:12:49
Param #1 is never referenced in this method (see https://psalm.dev/134)
public function __construct(ManagerRegistry $registry)

ERROR: PossiblyUnusedParam
at /home/project/src/Repository/ApiTokenRepository.php:17:40
Param #1 is never referenced in this method (see https://psalm.dev/134)
public function getApiToken(string $token): ?ApiToken

namespace App\Repository;

use App\Entity\ApiToken;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\AbstractQuery;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<ApiToken>
 */
class ApiTokenRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ApiToken::class);
    }

    public function getApiToken(string $token): ?ApiToken
    {
        $qb = $this->createQueryBuilder('apiToken')
                   ->andWhere('apiToken.token = :token')
                   ->setParameter('token', $token);

        /** @var ?ApiToken $result */
        $result = $qb->getQuery()
                     ->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

        return $result;
    }
}

Thank you for your insight !

@crosart crosart changed the title Bug : PossiblyUnusedParam error reported despite parameter usage PossiblyUnusedParam error reported despite parameter usage Jan 29, 2025
@ThomasLandauer
Copy link

Same as #157 ?

@crosart
Copy link
Author

crosart commented Feb 3, 2025

Same as #157 ?

Not exactly, this is a PossiblyUnusedParam error despite it being clearly used anytime in the method.

It is indeed close, maybe the same detection method that triggers both errors though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants