Rector: BarewordStringRector does not work with code that calls "die()"

Created on 11 Dec 2020  路  4Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | Rector 0.8.56 |
| Installed as | composer dependency |

Minimal PHP Code Causing Issue

A.php

<?php
class A {
    static function b($c) {}
}

test.php

<?php
A::b(C);
die('THIS FILE SHOULD NOT BE EXECUTED');

rector.php

<?php
declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Php72\Rector\ConstFetch\BarewordStringRector;

return static function (ContainerConfigurator $containerConfigurator): void {
        $parameters = $containerConfigurator->parameters();
    $services   = $containerConfigurator->services();
    $services->set(BarewordStringRector::class);
        $parameters->set(Option::AUTOLOAD_PATHS, ['A.php']);
};

https://getrector.org/demo/9beb47c6-ecf1-4fda-bb2f-aa93dfacf9cc#demo_result

Expected Behaviour

rector should not stop working and no php code should be executed by a static analyser.

Hints

bug

All 4 comments

Rector 0.7 is not maintained anymore.

Does the same happen with 0.9?

Rector 0.7 is not maintained anymore.
Does the same happen with 0.9?

I adjusted the example and specified the rector version to latest stable 0.8.56.

Thank you!

The BarewordStringRector must be load the full file, so all the constants are known.
Eval might help, but it would still execute code:

The eval() language construct is very dangerous because it allows execution of arbitrary PHP code.

This could be solve only with static reflection: https://github.com/rectorphp/rector/issues/3490

Closing, as the root of the problem is same.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aerendir picture Aerendir  路  5Comments

darthf1 picture darthf1  路  3Comments

pavarnos picture pavarnos  路  4Comments

peterrehm picture peterrehm  路  4Comments

benr77 picture benr77  路  4Comments