Skip to content

ForeachToInArrayRector changing code that cannot be changed to in_array approach #8686

@nikolicaleksa

Description

@nikolicaleksa

Bug Report

Subject Details
Rector version last dev-main

Minimal PHP Code Causing Issue

See https://getrector.com/demo/eb744759-eea9-40c4-b502-93615d95761e

<?php

namespace Rector\Tests\CodeQuality\Rector\Foreach_\ForeachToInArrayRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Foreach_\ForeachToInArrayRector\Source\Collection;

final class SkipMethodCalls
{
    public function foreachToInArray($items): bool
    {
        foreach ($items as $item) {
            if ($item == $this->strtoupper($item)) {
                return true;
            }
        }

        return false;
    }

    public function strtoupper($item): bool
    {
        return strtoupper((string) $item);
    }
}

Expected Behaviour

Rector should not change the code as it cannot be changed to the in_array approach

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