Skip to content

Incorrect behavior of StrictStringParamConcatRector #9691

@ghostwriter

Description

@ghostwriter

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/d26470d6-7392-4e21-ad13-c3b5106408ac

Code:

<?php

final class DemoFile
{
    public function resolve($item)
    {
        return $item . ' world';
    }
}

Config:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
    ->withRules([
        // 'string' type declaration is not available in PHP version 5.6 or earlier
        StrictStringParamConcatRector::class
    ])
    // specific PHP version
    ->withPhpVersion(PhpVersion::PHP_54);

Result:

final class DemoFile
 {
-    public function resolve($item)
+    public function resolve(string $item)
     {
         return $item . ' world';
     }
 }

Responsible rules

  • StrictStringParamConcatRector

Expected Behavior

string type declaration is not available in PHP version 5.6 or earlier

https://3v4l.org/TfdT4#v5.6.40

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