vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 661 forks source link

Sync "\Ds\Hashable" arguments naming with extension and stubs #11028

Open andrew-demb opened 3 months ago

andrew-demb commented 3 months ago

https://psalm.dev/r/ac4b9d77f6 (cannot be reproduced in playground - no installed ds extension)

STR: 1) installed and enabled ds extension 2) any psalm config with error level 4 (see example below) 3) class which implements Ds\Hashable and declares hashable method like this: public function equals($obj): bool (just like in polyfill stubs [1] and in extension [2])

Expected: no error - parameter named just like in polyfill and extension

Actual:

ERROR: ParamNameMismatch
at .../test.php:9:28
Argument 1 of Issue::equals has wrong name $obj, expecting $object as defined by Ds\Hashable::equals (see https://psalm.dev/230)
    public function equals($obj): bool

class

<?php

declare(strict_types=1);

use Ds\Hashable;

class Issue implements Hashable
{
    public function equals($obj): bool
    {
        if (false === $obj instanceof static) {
            return false;
        }

        return true;
    }

    public function hash(): string
    {
        return 'foobar';
    }
}

psalm config

<?xml version="1.0"?>
<psalm
        errorLevel="4"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="https://getpsalm.org/schema/config"
        xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
        findUnusedBaselineEntry="true"
        findUnusedCode="false"
>
    <projectFiles>
        <directory name="cmd"/>
    </projectFiles>
</psalm>

Possible reason - parameter name declared in psalm's CallMap:

[1] https://github.com/php-ds/polyfill/blob/7b2c5f1843466d50769a0682ce6fa9ddaaa99cb4/src/Hashable.php#L25-L31 [2] https://github.com/php-ds/ext-ds/blob/5f8915dae22596ce468543b78591170a7da8736d/src/php/classes/php_hashable_ce.c#L8-L15

psalm-github-bot[bot] commented 3 months ago

I found these snippets:

https://psalm.dev/r/ac4b9d77f6 ```php