Skip to content

Commit

Permalink
[TASK] Add TYPO3 rector
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Nov 25, 2024
1 parent 1e4c524 commit 14f9123
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/core12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ jobs:
name: Validate code against CGL
run: PHP_CS_FIXER_IGNORE_ENV=1 Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s cgl -n

# temporary composer require here until rector supports nikic/php-parser ^5.1.0 for TYPO3 13 compatibility
- if: matrix.php == '8.1' && matrix.composerInstall == 'composerInstallHighest'
name: Install Rector
run: composer require ssch/typo3-rector --dev

- if: matrix.php == '8.1' && matrix.composerInstall == 'composerInstallHighest'
name: Run Rector
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s rector -n

- name: Unit Tests
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s unit

Expand Down
23 changes: 16 additions & 7 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Options:
- composerInstallHighest: "composer update", handy if host has no PHP
- coveralls: Generate coverage
- docsGenerate: Renders the extension ReST documentation.
- rector: Run rector
- functional: functional tests
- lint: PHP linting
- unit: PHP unit tests
Expand Down Expand Up @@ -228,10 +229,9 @@ Options:
- 12: use TYPO3 v12 (default)
- 13: use TYPO3 v13
-p <8.0|8.1|8.2|8.3|8.4>
-p <8.1|8.2|8.3|8.4>
Specifies the PHP minor version to be used
- 8.0: use PHP 8.0 (default)
- 8.1: use PHP 8.1
- 8.1: use PHP 8.1 (default)
- 8.2: use PHP 8.2
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4
Expand Down Expand Up @@ -271,7 +271,7 @@ Options:
Show this help.
Examples:
# Run all core unit tests using PHP 7.4
# Run all core unit tests
./Build/Scripts/runTests.sh -s unit
# Run all core units tests and enable xdebug (have a PhpStorm listening on port 9003!)
Expand Down Expand Up @@ -314,7 +314,7 @@ PHP_VERSION="8.1"
PHP_XDEBUG_ON=0
PHP_XDEBUG_PORT=9003
EXTRA_TEST_OPTIONS=""
CGLCHECK_DRY_RUN=0
DRY_RUN=0
DATABASE_DRIVER=""
CONTAINER_BIN=""
COMPOSER_ROOT_VERSION="12.0.0-dev"
Expand Down Expand Up @@ -377,7 +377,7 @@ while getopts "a:b:s:d:i:p:e:t:xy:nhu" OPT; do
PHP_XDEBUG_PORT=${OPTARG}
;;
n)
CGLCHECK_DRY_RUN=1
DRY_RUN=1
;;
h)
loadHelp
Expand Down Expand Up @@ -470,7 +470,7 @@ fi
case ${TEST_SUITE} in
cgl)
DRY_RUN_OPTIONS=''
if [ "${CGLCHECK_DRY_RUN}" -eq 1 ]; then
if [ "${DRY_RUN}" -eq 1 ]; then
DRY_RUN_OPTIONS='--dry-run --diff'
fi
COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v ${DRY_RUN_OPTIONS} --config=Build/php-cs-fixer/php-cs-fixer.php --using-cache=no"
Expand Down Expand Up @@ -588,6 +588,15 @@ case ${TEST_SUITE} in
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/bash -c "${COMMAND}"
SUITE_EXIT_CODE=$?
;;
rector)
DRY_RUN_OPTIONS=''
if [ "${DRY_RUN}" -eq 1 ]; then
DRY_RUN_OPTIONS='--dry-run'
fi
COMMAND="php -dxdebug.mode=off .Build/bin/rector process ${DRY_RUN_OPTIONS} --config=Build/rector/rector.php --no-progress-bar"
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}"
SUITE_EXIT_CODE=$?
;;
unit)
COMMAND=(.Build/bin/phpunit -c Build/phpunit/UnitTests.xml --exclude-group not-${DBMS} ${EXTRA_TEST_OPTIONS} "$@")
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} "${COMMAND[@]}"
Expand Down
51 changes: 51 additions & 0 deletions Build/rector/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\ValueObject\PhpVersion;
use Ssch\TYPO3Rector\CodeQuality\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\CodeQuality\General\ExtEmConfRector;
use Ssch\TYPO3Rector\CodeQuality\General\InjectMethodToConstructorInjectionRector;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
use Ssch\TYPO3Rector\Set\Typo3SetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/../../Build',
__DIR__ . '/../../Classes',
__DIR__ . '/../../Configuration',
__DIR__ . '/../../Tests',
__DIR__ . '/../../ext_emconf.php',
__DIR__ . '/../../ext_localconf.php',
__DIR__ . '/../../ext_tables.php',
])
->withPhpSets(php81: true)
->withPhpVersion(PhpVersion::PHP_81)
->withSets([
Typo3SetList::CODE_QUALITY,
Typo3SetList::GENERAL,
Typo3LevelSetList::UP_TO_TYPO3_12,
])
// To have a better analysis from PHPStan, we teach it here some more things
->withPHPStanConfigs([Typo3Option::PHPSTAN_FOR_RECTOR_PATH])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
ConvertImplicitVariablesToExplicitGlobalsRector::class,
])
->withImportNames(true, true, false, true)
->withConfiguredRule(ExtEmConfRector::class, [
ExtEmConfRector::PHP_VERSION_CONSTRAINT => '8.1.0-8.4.99',
ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '12.4.2-13.9.99',
ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [],
])
->withSkip([
InjectMethodToConstructorInjectionRector::class => [
__DIR__ . '/../../Classes/ViewHelpers/',
],
NullToStrictStringFuncCallArgRector::class,
])
;
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"typo3/cms-seo": "Sitemaps"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.47.1",
"phpstan/phpdoc-parser": "^1.12.10",
"phpunit/phpunit": "^10.5",
"typo3/cms-install": "^12.4.2 || ^13.1",
"typo3/cms-seo": "^12.4.2 || ^13.1",
"typo3/testing-framework": "^8.0.9",
"phpunit/phpunit": "^10.5",
"typo3/coding-standards": "^0.5.5",
"friendsofphp/php-cs-fixer": "^3.47.1",
"phpstan/phpdoc-parser": "^1.12.10",
"typo3/testing-framework": "^8.0.9",
"webmozart/assert": "^1.11.0"
},
"autoload": {
Expand Down

0 comments on commit 14f9123

Please sign in to comment.