Skip to content

StringableForToStringRector adding cast to incorrect place #8685

@nikolicaleksa

Description

@nikolicaleksa

Bug Report

Subject Details
Rector version last dev-main

Minimal PHP Code Causing Issue

See https://getrector.com/demo/c32efdb4-a075-4a39-9686-259bed08325d

<?php

declare(strict_types=1);

namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture;

class View
{
    public function __construct(private string $template, private array $data)
    {
    }

    public static function make(string $template, array $data)
    {
        return new self($template, $data);
    }

    public function render(): string
    {
        return $this->template;
    }
}

class SkipOnAnonymousFunctions implements \Stringable
{
    public function __construct(private array $items)
    {
    }

    public function __toString(): string
    {
        return View::make('index', [
            'only_uppercase' => array_filter(
                $this->items,
                static function (string $item) {
                    return mb_strtoupper($item) === $item;
                }
            ),
        ])->render();
    }
}

Expected Behaviour

Rector should not add string casting to array_filter

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