Skip to content

Incorrect behavior of FunctionLikeToFirstClassCallableRector #9453

@samsonasik

Description

@samsonasik

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/371133f2-0c1c-4d0f-8e5c-958d89098e39

<?php

class SkipCallableParamAssignFluentMultiParams
{
    private $transform;

    /**
     * @param callable(mixed $datum, int|string|null $key): mixed $callable
     */
    public function withTransform(callable $callable)
    {
        $this->transform = $callable;
        return $this;
    }

    public function run($value, $optionalData = [])
    {
        var_dump(($this->transform)($value, $optionalData));
    }
}

(new SkipCallableParamAssignFluentMultiParams())
    ->withTransform(fn (string $datum): string => trim($datum))
    ->run('  some data  ');

Responsible rules

  • FunctionLikeToFirstClassCallableRector

Expected Behavior

should be skipped to avoid error:

Fatal error: Uncaught TypeError: trim(): Argument #2 ($characters) must be of type string, array given in /in/aWNCA:15
Stack trace:
#0 /in/aWNCA(15): trim('  some data  ', Array)
#1 /in/aWNCA(21): SkipCallableParamAssignFluent->run('  some data  ')
#2 {main}
  thrown in /in/aWNCA on line 15

see

original: works: https://3v4l.org/SqOPO
changed: error https://3v4l.org/8kku6

I think based on signature docblock, the @param callable(mixed $datum, int|string|null $key): mixed $callable should make it skipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions