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 #145

Open
bohdanmoshchenko opened this issue Jun 26, 2023 · 6 comments
Open

PossiblyUnusedParam #145

bohdanmoshchenko opened this issue Jun 26, 2023 · 6 comments

Comments

@bohdanmoshchenko
Copy link

bohdanmoshchenko commented Jun 26, 2023

With Symfony 6.3.1, vimeo/psalm 5.13.0 and doctrine/doctrine-bundle 2.10.0

ERROR: PossiblyUnusedParam - src/User/Repository/UserTokenRepository.php:16:49 - Param psalm/psalm-plugin-symfony#1 is never referenced in this method (see https://psalm.dev/134)
public function __construct(ManagerRegistry $registry)
ERROR: PossiblyUnusedParam - src/User/Repository/UserTokenRepository.php:24:49 - Param psalm/psalm-plugin-symfony#1 is never referenced in this method (see https://psalm.dev/134)
public function findOneByTypeAndHash(string $type, string $hash): ?UserToken
ERROR: PossiblyUnusedParam - src/User/Repository/UserTokenRepository.php:24:63 - Param psalm/psalm-plugin-symfony#2 is never referenced in this method (see https://psalm.dev/134)
public function findOneByTypeAndHash(string $type, string $hash): ?UserToken

CODE:

<?php

declare(strict_types=1);

namespace App\User\Repository;

use App\User\Entity\UserToken;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    /**
     * @psalm-param value-of<UserToken::AVAILABLE_TYPES> $type
     */
    public function findOneByTypeAndHash(string $type, string $hash): ?UserToken
    {
        return $this->findOneBy(['type' => $type, 'hash' => $hash]);
    }
}
@weirdan
Copy link
Member

weirdan commented Jun 26, 2023

What version of the doctrine bundle (where ServiceEntityRepository comes from) do you have?

@bohdanmoshchenko
Copy link
Author

@weirdan doctrine/doctrine-bundle 2.10.0

@weirdan
Copy link
Member

weirdan commented Jun 26, 2023

Thanks. My guess is that Psalm is confused with a conditional class definition here: https://github.com/doctrine/DoctrineBundle/blob/2.10.x/Repository/ServiceEntityRepository.php

Do you also use https://github.com/psalm/psalm-plugin-doctrine (you most likely should)?

@bohdanmoshchenko
Copy link
Author

@weirdan Yes. I use it too.

@weirdan weirdan transferred this issue from psalm/psalm-plugin-symfony Jun 26, 2023
@weirdan
Copy link
Member

weirdan commented Jun 26, 2023

@bohdanmoshchenko I believe this issue belongs here, as it's doctrine-specific.

@MihailSerov
Copy link

you can temporally fix it by this:

<?php

use Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @template T of object
 * @template-extends LazyServiceEntityRepository<T>
 *
 * @psalm-suppress InternalClass
 */
class ServiceEntityRepository extends LazyServiceEntityRepository
{
    /**
     * @psalm-param class-string $entityClass
     *
     * @psalm-suppress InternalMethod
     */
    public function __construct(ManagerRegistry $registry, string $entityClass)
    {
        parent::__construct($registry, $entityClass);
    }
}

class MyRepository extends ServiceEntityRepository
{
}

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

3 participants