Automate code migrations for TYPO3 Extensions
Find a file
Daniel Siepmann eaa99973b1
TASK: Refactor existing sniffs to work again
* As we migrated trait to class, all sniffs have to extend instead to
  use the new class.
* Also make PhpCsFile import and type hints the same across all sniffs.

Relates: #36
2017-03-23 13:23:26 +01:00
src/Standards/Typo3Update TASK: Refactor existing sniffs to work again 2017-03-23 13:23:26 +01:00
.gitignore FEATURE: Provide first basic implementation of classmapping 2017-03-07 13:36:09 +01:00
composer.json change composer dependency to right path of phpcs 2017-03-21 10:20:46 +01:00
LICENSE Initial commit 2017-03-07 11:41:40 +01:00
Makefile FEATURE: Provide first basic implementation of classmapping 2017-03-07 13:36:09 +01:00
Readme.rst WIP|FEATURE: Provide sniff to convert old legacy class definitions 2017-03-23 08:52:25 +01:00

About

Our goal is to provide an automated migration for TYPO3 updates.

This should include source code modifications like adjusting old legacy class names to new ones.

Requirements

  • composer needs to be installed and inside your $PATH.

Installation

Run:

make install

and copy the vendor/composer/autoload_classaliasmap.php generated by composer in your TYPO3 installation to LegacyClassnames.php in the root of this project.

Usage

Run:

./vendor/bin/phpcbf <path>

This will run the auto fixer recursive for <path> fixing all issues.

Afterwards you should run:

./vendor/bin/phpcs <path>

To get information about possible issues that were not autofixed.

What's included?

Currently we can migrate calls to old legacy class names of the TYPO3 core like Tx_Extbase... to new ones like \TYPO3\Extbase\.... This is done for:

  • PHPDocuments, like Includes and annotations for IDEs.
  • Inheritance like extends and implements.
  • Static calls like t3lib_div:: to \TYPO3\Core\Utility\GeneralUtility.
  • Typehints in methods and function like injects.
  • instanceof checks.
  • Inline comments for IDEs, e.g. /* @var $configurationManager Tx_Extbase_Configuration_ConfigurationManager */
  • Instantiation through new.
  • Instantiation through makeInstance. Only Classnames in Strings are supported, no ::class.
  • Instantiation through ObjectManager, check afterwards as this is static and all function calls using get and create will be adjusted. Might be useful to exclude this sniff and run it separately. Only Classnames in Strings are supported, no ::class.
  • use statements.
  • catch of legacy class names.
  • Convert old legacy class definitions in extensions to namespace ones.

Also we check for the following deprecated calls:

  • Check for create on ObjectManager, which is "stupid" just all create calls are marked with a warning.

What does it look like?

$ ./vendor/bin/phpcs -p --colors -s <path>
E


FILE: <path>
----------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
----------------------------------------------------------------------
 8 | ERROR | [x] Legacy classes are not allowed; found
   |       |   backend_toolbarItem
   |       |   (Typo3Update.LegacyClassnames.Inheritance.legacyClassname)
14 | ERROR | [x] Legacy classes are not allowed; found TYPO3backend
   |       |   (Typo3Update.LegacyClassnames.DocComment.legacyClassname)
16 | ERROR | [x] Legacy classes are not allowed; found TYPO3backend
   |       |   (Typo3Update.LegacyClassnames.TypeHint.legacyClassname)
48 | ERROR | [x] Legacy classes are not allowed; found t3lib_extMgm
   |       |   (Typo3Update.LegacyClassnames.StaticCall.legacyClassname)
61 | ERROR | [x] Legacy classes are not allowed; found t3lib_div
   |       |   (Typo3Update.LegacyClassnames.StaticCall.legacyClassname)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 35ms; Memory: 5Mb

Configuration

Configuration is done through PHPCS Standards, e.g. provide a custom ruleset.xml or customize the provided one.

legacyExtensions

Configures which extension names are legacy. Used to provide further checks and warnings about possible legacy code. E.g. inside of non auto migrated situations.

Example:

<rule ref="Typo3Update.LegacyClassnames.Instanceof">
    <properties>
        <property name="legacyExtensions" type="array" value="Extbase,Fluid,Frontend,Core"/>
    </properties>
</rule>
Typo3Update.LegacyClassnames.DocComment: allowedTags

Configures which tags are checked for legacy class names.

Example:

<rule ref="Typo3Update.LegacyClassnames.DocComment">
    <properties>
        <property name="allowedTags" type="array" value="@param,@return,@var,@see,@throws"/>
    </properties>
</rule>
vendor

Configure your vendor through ruleset.xml or using --runtime-set. Default is YourCompany.

Example:

<config name="vendor" value="YourVendor"/>

Example:

--runtime-set vendor YourVendor