brotkrueml/schema-rector

Instant upgrade and refactoring for the TYPO3 schema extension code by using Rector

v1.0.0 2021-04-12 09:38 UTC

This package is auto-updated.

Last update: 2021-10-12 10:42:50 UTC


README

CI Status

This package provides Rector rules for migrating code from older versions of the TYPO3 extension schema.

Note: If you don't know already, you can also migrate TYPO3 core-specific code with Rector for TYPO3.

Installation

The package can be installed with composer:

composer req --dev brotkrueml/schema-rector

Caution: Never run this tool on production, only on development environment where code is under version control (e.g. git). Always review and test automatic changes before releasing to production.

Configuration

Create a rector.php file in the project's root folder:

<?php

declare(strict_types=1);

use Brotkrueml\SchemaRector\Rules\RenameSchemaManagerSetMainEntityOfWebPageRector;use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->set(RenameSchemaManagerSetMainEntityOfWebPageRector::class);
};

Afterwards you can start a dry-run to see the possible changes (assuming the extensions of your projects are available under the packages folder):

vendor/bin/rector process packages --dry-run

If everything is okay for you than you can omit the dry-run option to write the changes to your code.

Rules

The following rules are available:

RenameSchemaManagerSetMainEntityOfWebPageRector

This Rector migrates the deprecated SchemaManager->setMainEntityOfWebPage() method call to the new SchemaManager->addMainEntityOfWebPage().

🔧 configure it!

use Brotkrueml\SchemaRector\Rules\RenameSchemaManagerSetMainEntityOfWebPageRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->set(RenameSchemaManagerSetMainEntityOfWebPageRector::class);
};

 $schemaManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Brotkrueml\Schema\Manager\SchemaManager::class);
 $type = new \Brotkrueml\Schema\Model\Type\Thing();
-$schemaManager->setMainEntityOfPage($type);
+$schemaManager->addMainEntityOfPage($type);