Skip to content

PHPStan cannot match the correct select() definition with 4 params #1143

@marki555

Description

@marki555

Information

  • Version of Medoo: 2.2.0
  • Version of PHP: 8.4.10
  • Type of Database: MySQL
  • System: Linux

Describe the Problem
PHPStan complains about wrong number of parameters to the select() method when using it as per docu: select($table, $join, $columns, $where)

Code Snippet
The detail code you are using that causes the problem:

        $result = $this->db->select("doors(d)", // Main doors table with alias
            [
                "[>]users(u)"                => [ "tenant_id" => "tenant_id" ],                           // pull in tenant_id from user
                "[>]permissions_tenants(pt)" => [ "door_id" => "door_id", "u.tenant_id" => "tenant_id" ], // tenant defaults per door
                "[>]permissions_users(pu)"   => [ "door_id" => "door_id", "u.id"        => "user_id" ],   // user‐specific overrides
            ], [ // columns
                "d.door_id",
                "d.visible_name",
                Medoo::raw("COALESCE(pu.permission, pt.permission) AS perm")
            ], [ // where
                "u.id" => $userId,
                Medoo::raw("COALESCE(pu.permission, pt.permission) IN ('read','write')")
            ]
        );
        /** @disregard intelephense(P1006): it thinks $result is null and not array */
        return $result;

Expected Behavior
PHPStan (and Intelephense) is happy.

Actual Behavior
Code works, but PHPStan (and also vscode intelliphense) complains:
Method Medoo\Medoo::select() invoked with 4 parameters, 5 required.
Parameter #3 $column of method Medoo\Medoo::select() expects string, array<int, Medoo\Raw|string> given.
Method xx\DoorService::listUserDoors() should return array but returns null.
And also Intelephense for the return statement:
Expected type 'array'. Found 'null'.

When I removed all PHPDoc declarations of select() in vendor/catfan/src/Medoo.php (I had to clear PHPStan cache every time), PHPStan was not complaining and also Intelliphsense was happy. I tried to add the definition I think is correct to the list of other definitions, but it didn't help. It works with none select() in phpdoc or with just the one:
* @method array|null select(string $table, array $join, array|string $columns, array $where)

It seems like both tools cannot match the declaration with 4 params and try to use 5 params declaration (which returns null as per phpdoc, so they complain also about the return type from my function).
Not sure what is the correct fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions