Skip to content

Incorrect behavior of AssertRegExpRector #8669

@paulbalandan

Description

@paulbalandan

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/7a410258-130e-42f2-b522-7cd7065ee20b

<?php

final class DemoTest extends PHPUnit\Framework\TestCase
{
    public function testFoo(): void
    {
    	$string = 'keys=1000';
        
        $this->assertSame(1, preg_match('/^keys=(?P<count>\d+)/', $string, $matches));
        $this->assertSame(1000, (int) $matches['count']);
    }
}

Responsible rules

  • AssertRegExpRector

Expected Behavior

It should skip the assert if the $matches variable is used subsequently.

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