Skip to content

Commit

Permalink
[TASK] Add TYPO3 Rector (#2580)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi authored Dec 15, 2024
1 parent 121c105 commit a5efced
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/core12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v3

- name: Install testing system
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s ${{ matrix.composerInstall }}
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s ${{ matrix.composerInstall }}

- name: Lint PHP
run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s lint
Expand All @@ -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:^2.0 --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 --ansi"
${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
54 changes: 54 additions & 0 deletions Build/rector/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
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;
use Ssch\TYPO3Rector\TYPO311\v0\DateTimeAspectInsteadOfGlobalsExecTimeRector;

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([
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/Controller/AdministrationController.php',
__DIR__ . '/../../Classes/Domain/Repository/AbstractDemandedRepository.php',
__DIR__ . '/../../Classes/Service/SettingsService.php',
__DIR__ . '/../../Classes/ViewHelpers/',
],
DateTimeAspectInsteadOfGlobalsExecTimeRector::class => [
__DIR__ . '/../../Tests/Unit/Backend/FormDataProvider/NewsRowInitializeNewTest.php',
],
])
;

0 comments on commit a5efced

Please sign in to comment.