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.
According to the migration example, running the _rector_ binary should do things.
Rector CLI claims _The "--set" option does not exist._
composer-require --dev Rector as described, then run
vendor/bin/rector process src --set phpexcel-to-phpspreadsheet
phpoffice/phpspreadsheet 1.15 with PHP 7.4.12 on Ubuntu 18 LTS
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.
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-phpspreadsheetwill not work any longer, and it takes two more steps: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:
Now assuming your project code is located in src/ directory, run Rector on it like this:
After successful migration Rector can be removed:
If this way is considered helpful and this receipt meets the intended usage, I'd happily supply a PR.