Psalm says that: Class, interface or enum named Yii does not exist

Hi.
I am trying to run Psalm on my old yii2 basic project.
When scanning all project I see too many issues.
So I try to run it for one file, just to try.

    <projectFiles>
        <file name="components/FileJob.php" />

        <file name="vendor/autoload.php" />
        <file name="vendor/composer/autoload_classmap.php" />
        <file name="vendor/composer/autoload_files.php" />
        <file name="vendor/composer/autoload_namespaces.php" />
        <file name="vendor/composer/autoload_psr4.php" />
        <file name="vendor/composer/autoload_real.php" />
        <file name="vendor/composer/autoload_static.php" />
        <file name="vendor/composer/ClassLoader.php" />
        <file name="vendor/composer/installed.php" />
        <file name="vendor/composer/InstalledVersions.php" />
        <file name="vendor/composer/platform_check.php" />
        <file name="vendor/yiisoft/extensions.php" />

        <ignoreFiles>
            <directory name="vendor" />
        </ignoreFiles>
    </projectFiles>

That is FileJob:

namespace app\components;

use yii\base\BaseObject;
use Yii;

class FileJob extends BaseObject implements \yii\queue\JobInterface
{
    public $file;
    
    public function execute($queue)
    {
        $file = Yii::getAlias('@runtime/queuedata1/' . $this->file);
        $content = file_get_contents($file);
        unlink($file);
        $file = str_replace('.txt', '__done.txt', $file);
        file_put_contents($file, $content . "\n\n Done", FILE_APPEND);
    }
}

Psalm gives me the next error conserning the use of Yii

ERROR: UndefinedClass - components/FileJob.php:13:17 - Class, interface or enum named Yii does not exist (see https://psalm.dev/019)
        $file = Yii::getAlias('@runtime/queuedata1/' . $this->file);

Why is that?

The documentation says it extends from yii\BaseYii

https://www.yiiframework.com/doc/api/2.0/yii

I once had hard time,
see if you can get anything: false positive: MissingDependency on Yii2 Active record · Issue #10780 · vimeo/psalm · GitHub

Added
<file name="vendor/yiisoft/yii2/Yii.php" />
to psalm config. Issue disappeared.

1 Like

Psalm, for default, works very badly with yii2.
Errors and errors.
It looks it cannot figure out classes that is autoloaded by Yii.

UndefinedClass, always