Skip to content

RectorConfig::importNames produces invalid code #7714

@r-simlinger

Description

@r-simlinger

Bug Report

Subject Details
Rector version 0.15.4

For files where the PHP open tag is not in the first line the \Rector\Config\RectorConfig::importNames() config will produce invalid code:

Minimal PHP Code Causing Issue

#!/usr/local/bin/php -q

<?php

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = \Dotenv\Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();
// ... more code ...

Current Behaviour

    ---------- begin diff ----------
@@ @@
+use Dotenv\Dotenv;
 #!/usr/local/bin/php -q

 <?php
@@ @@

 require(__DIR__ . '/../../vendor/autoload.php');

-$dotenv = \Dotenv\Dotenv::createUnsafeMutable(__DIR__ . '/../../');
+$dotenv = Dotenv::createUnsafeMutable(__DIR__ . '/../../');
 $dotenv->load();
 // ... more code ...
    ----------- end diff -----------

Expected Behaviour

#!/usr/local/bin/php -q

<?php

use Dotenv\Dotenv;

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();
// ... more code ...

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