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

MixedAssignment false positive #226

Open
enumag opened this issue Nov 4, 2021 · 1 comment
Open

MixedAssignment false positive #226

enumag opened this issue Nov 4, 2021 · 1 comment

Comments

@enumag
Copy link
Contributor

enumag commented Nov 4, 2021

Code:

<?php declare(strict_types = 1);

namespace App\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

final class MyCommand extends Command
{
    protected static $defaultName = 'app:my-command';

    public function configure(): void
    {
        $this->addOption('test', null, InputOption::VALUE_NONE);
    }

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $option = $input->getOption('test');

        if ($option) {
            return self::FAILURE;
        }

        return self::SUCCESS;
    }
}

Psalm throws:

ERROR: MixedAssignment
at /app/project/Infrastructure/Console/GenerateMutationControllerCommand.php:23:9
Unable to determine the type that $option is being assigned to (see https://psalm.dev/032)
        $option = $input->getOption('test');

However it does know that the variable is boolean because if I add assert(is_bool($option)) then I get this:

ERROR: RedundantCondition
at /app/project/Infrastructure/Console/GenerateMutationControllerCommand.php:22:9
Type bool for $option is always bool (see https://psalm.dev/122)
        assert(is_bool($option));
@Jean85
Copy link

Jean85 commented Aug 24, 2023

I'm getting this issue too, with the lastest version of Psalm (5.15.0) and the plugin (5.0.3)

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