psalm-plugin-symfony icon indicating copy to clipboard operation
psalm-plugin-symfony copied to clipboard

MixedAssignment false positive

Open enumag opened this issue 4 years ago • 1 comments

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));

enumag avatar Nov 04 '21 10:11 enumag

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

Jean85 avatar Aug 24 '23 07:08 Jean85