Phpspreadsheet: Migration with Rector example outdated?

Created on 2 Nov 2020  Â·  2Comments  Â·  Source: PHPOffice/PhpSpreadsheet

This is:

- [X] a bug report
- [ ] a feature request
- [ X] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

It seems the migration example is outdated because the CLI option mentioned has been removed. Unfortunately the Rector docs are not helpful either to someone new to Rector.

What is the expected behavior?

According to the migration example, running the _rector_ binary should do things.

What is the current behavior?

Rector CLI claims _The "--set" option does not exist._

What are the steps to reproduce?

composer-require --dev Rector as described, then run

vendor/bin/rector process src --set phpexcel-to-phpspreadsheet

Which versions of PhpSpreadsheet and PHP are affected?

phpoffice/phpspreadsheet 1.15 with PHP 7.4.12 on Ubuntu 18 LTS

Most helpful comment

Found a workaround – It seems to me Rector requires configuration by an PHP file. So passing s.th. like--set phpexcel-to-phpspreadsheet will not work any longer, and it takes two more steps:

$ composer require rector/rector --dev
$ vendor/bin/rector init

The init command will add a rector.php configuration file. Open that file in an editor and add the PHPEXCEL_TO_PHPSPREADSHEET ruleset to the _$parameters._ — Note: When you are about to migrate only the PhpOffice packages, you may want to disable the DEAD_CODE ruleset:

<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    // get parameters
    $parameters = $containerConfigurator->parameters();

    // Define what rule sets will be applied
    $parameters->set(Option::SETS, [
        // SetList::DEAD_CODE,
        SetList::PHPEXCEL_TO_PHPSPREADSHEET,
    ]);

    // get services (needed for register a single rule)
    // $services = $containerConfigurator->services();

    // register a single rule
    // $services->set(TypedPropertyRector::class);
};

Now assuming your project code is located in src/ directory, run Rector on it like this:

$ vendor/bin/rector process src/

After successful migration Rector can be removed:

$ composer remove rector/rector && rm rector.php

If this way is considered helpful and this receipt meets the intended usage, I'd happily supply a PR.

All 2 comments

Found a workaround – It seems to me Rector requires configuration by an PHP file. So passing s.th. like--set phpexcel-to-phpspreadsheet will not work any longer, and it takes two more steps:

$ composer require rector/rector --dev
$ vendor/bin/rector init

The init command will add a rector.php configuration file. Open that file in an editor and add the PHPEXCEL_TO_PHPSPREADSHEET ruleset to the _$parameters._ — Note: When you are about to migrate only the PhpOffice packages, you may want to disable the DEAD_CODE ruleset:

<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    // get parameters
    $parameters = $containerConfigurator->parameters();

    // Define what rule sets will be applied
    $parameters->set(Option::SETS, [
        // SetList::DEAD_CODE,
        SetList::PHPEXCEL_TO_PHPSPREADSHEET,
    ]);

    // get services (needed for register a single rule)
    // $services = $containerConfigurator->services();

    // register a single rule
    // $services->set(TypedPropertyRector::class);
};

Now assuming your project code is located in src/ directory, run Rector on it like this:

$ vendor/bin/rector process src/

After successful migration Rector can be removed:

$ composer remove rector/rector && rm rector.php

If this way is considered helpful and this receipt meets the intended usage, I'd happily supply a PR.

I think that this should be a high priority for a pull request.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PowerKiKi picture PowerKiKi  Â·  4Comments

ionesculiviucristian picture ionesculiviucristian  Â·  4Comments

sadlyblue picture sadlyblue  Â·  3Comments

isopen picture isopen  Â·  3Comments

PowerKiKi picture PowerKiKi  Â·  5Comments