sabbelasichon / typo3-rector

Rector for TYPO3
MIT License
229 stars 63 forks source link

Rector crashes due to a DI failure with any `Typo3(Level)SetList` #3114

Closed oliverklee closed 2 years ago

oliverklee commented 2 years ago

Bug Report

Used package versions

PHP 8.1.8 with these packages installed as global Composer packages:

helmich/typo3-typoscript-parser  v2.4.1   Parser for the TYPO3 configuration language TypoScript.
phpstan/phpstan                  1.8.2    PHPStan - PHP Static Analysis Tool
psr/container                    2.0.2    Common Container Interface (PHP FIG PSR-11)
rector/rector                    0.13.10  Instant Upgrade and Automated Refactoring of any PHP code
ssch/typo3-rector                v0.11.46 Instant fixes for your TYPO3 code by using Rector.
symfony/config                   v6.1.3   Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/dependency-injection     v6.1.3   Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts    v3.1.1   A generic function and convention to trigger deprecation notices
symfony/filesystem               v6.1.3   Provides basic utilities for the filesystem
symfony/polyfill-ctype           v1.26.0  Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme   v1.26.0  Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer v1.26.0  Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring        v1.26.0  Symfony polyfill for the Mbstring extension
symfony/service-contracts        v3.1.1   Generic abstractions related to writing services
symfony/string                   v6.1.3   Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/yaml                     v6.1.3   Loads and dumps YAML files

Used configuration file

The problem also occurs with the configuration file copied from ./vendor/ssch/typo3-rector/templates/rector.php.dist.

A minimal configuration file in my project to reproduce the problem looks like this:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\PostRector\Rector\NameImportingPostRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\FileProcessor\Composer\Rector\ExtensionComposerRector;
use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Set\Typo3SetList;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([__DIR__ . '/packages']);

    // Define your target version which you want to support.
    $rectorConfig->phpVersion(PhpVersion::PHP_72);

    // In order to have a better analysis from PHPStan, we teach it here some more things.
    $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH);

    // define sets of rules
    $rectorConfig->sets([
        Typo3SetList::TYPO3_95,
    ])
};

Steps to reproduce

rector --version

or

rector --dry-run

Expected results

Either Rector 0.13.10, or the possible changes to the code.

Actual results

 [ERROR] Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator::__construct(): Argument #1    
         ($container) must be of type Symfony\Component\DependencyInjection\ContainerBuilder,                           
         RectorPrefix202208\Symfony\Component\DependencyInjection\ContainerBuilder given, called in                     
         /home/klee/.composer/vendor/rector/rector/vendor/symfony/dependency-injection/Loader/PhpFileLoader.php on line 
         67                                                            

Additional information

The problem occurs with any Typo3SetList or Typo3LevelSetList set I've tried.

Using set constants from Rector itself like LevelSetList::UP_TO_PHP_73 does not lead to this crash, though.

Adding a single TYPO3 Rector rule also does not lead to this crash, e.g.:

    $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v9\v3\BackendUserAuthenticationSimplelogRector::class);
sabbelasichon commented 2 years ago

@oliverklee You should not install rector/rector 0.13.10 and ssch/typo3-rector v0.11.46 at the same time. Please install rector/rector 0.13.4 without requiring ssch/typo3-rector. If you already use PHP 7.4 in your CI you can now switch to ssch/typo3-rector version 1.0 and remove the dependency from rector or use rector/rector in version 0.14

oliverklee commented 2 years ago

@sabbelasichon Thanks! Will do.