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

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

Open
andrew-demb opened this issue Jun 26, 2024 · 1 comment
Open

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

andrew-demb opened this issue Jun 26, 2024 · 1 comment

Comments

@andrew-demb
Copy link
Contributor

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

Copy link

I found these snippets:

https://psalm.dev/r/ac4b9d77f6
<?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 output (using commit 16b24bd):

ERROR: UndefinedClass - 7:24 - Class, interface or enum named Ds\Hashable does not exist

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

1 participant