diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1b16b1c..6200187 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,7 @@ jobs: - 8.2 - 8.3 - 8.4 + - 8.5 steps: - name: Checkout uses: actions/checkout@v3 @@ -112,6 +113,8 @@ jobs: typo3-version: '^13.4' - php-version: '8.4' typo3-version: '^13.4' + - php-version: '8.5' + typo3-version: '^13.4' steps: - uses: actions/checkout@v3 @@ -143,6 +146,8 @@ jobs: typo3-version: '^13.4' - php-version: '8.4' typo3-version: '^13.4' + - php-version: '8.5' + typo3-version: '^13.4' steps: - uses: actions/checkout@v3 diff --git a/Classes/Domain/Model/MarkerCollection.php b/Classes/Domain/Model/MarkerCollection.php index 43b3695..912d686 100644 --- a/Classes/Domain/Model/MarkerCollection.php +++ b/Classes/Domain/Model/MarkerCollection.php @@ -45,10 +45,13 @@ public function get(string $markerKey): Marker } /** - * @return mixed[] + * @return list */ public function getMarkerKeys(): array { - return array_keys($this->data); + return array_map( + static fn (Marker $marker): string => $marker->getMarkerWithBrackets(), + array_values($this->data), + ); } } diff --git a/Classes/EventListener/ContentProcessor.php b/Classes/EventListener/ContentProcessor.php index c9b4adc..4aee085 100644 --- a/Classes/EventListener/ContentProcessor.php +++ b/Classes/EventListener/ContentProcessor.php @@ -17,7 +17,6 @@ use Sinso\Variables\Service\VariablesService; use TYPO3\CMS\Core\Attribute\AsEventListener; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent; class ContentProcessor diff --git a/Classes/EventListener/ModifyCacheLifetime.php b/Classes/EventListener/ModifyCacheLifetime.php index a9585ab..a77361e 100644 --- a/Classes/EventListener/ModifyCacheLifetime.php +++ b/Classes/EventListener/ModifyCacheLifetime.php @@ -8,10 +8,10 @@ use TYPO3\CMS\Core\Attribute\AsEventListener; use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent; -final class ModifyCacheLifetime +final readonly class ModifyCacheLifetime { public function __construct( - private readonly VariablesService $variablesService, + private VariablesService $variablesService, ) { } diff --git a/Classes/Service/VariablesService.php b/Classes/Service/VariablesService.php index a2f721b..a9aa907 100644 --- a/Classes/Service/VariablesService.php +++ b/Classes/Service/VariablesService.php @@ -87,7 +87,7 @@ private function replaceMarkersInText( MarkerCollection $markerCollection, string &$text ): void { - $markerRegexp = '/(' . implode('|', array_map('preg_quote', $markerCollection->getMarkerKeys())) . ')/'; + $markerRegexp = '/(' . implode('|', array_map(preg_quote(...), $markerCollection->getMarkerKeys())) . ')/'; $loops = 0; @@ -128,9 +128,7 @@ private function replaceMarkersInText( private function getMarkers( ServerRequestInterface $request, ): MarkerCollection { - $pids = array_map(static function ($page) { - return $page['uid']; - }, $request->getAttribute('frontend.page.information')?->getRootLine() ?? []); + $pids = array_map(static fn ($page) => $page['uid'], $request->getAttribute('frontend.page.information')?->getRootLine() ?? []); $storagePid = $this->getStoragePidFromTypoScript($request); if (is_int($storagePid)) { @@ -183,10 +181,7 @@ private function setCacheTags( return; } - $cacheTags = array_map(function (string $tag): CacheTag { - return new CacheTag($tag); - }, $this->cacheTags->toArray()); - + $cacheTags = array_map(fn (string $tag): CacheTag => new CacheTag($tag), $this->cacheTags->toArray()); $cacheCollector->addCacheTags(...$cacheTags); } diff --git a/Configuration/TCA/tx_variables_marker.php b/Configuration/TCA/tx_variables_marker.php index 341a9dc..c754085 100644 --- a/Configuration/TCA/tx_variables_marker.php +++ b/Configuration/TCA/tx_variables_marker.php @@ -24,7 +24,6 @@ 'starttime' => 'starttime', 'endtime' => 'endtime', ], - 'searchFields' => 'marker,replacement', 'iconfile' => 'EXT:variables/Resources/Public/Icons/tx_variables_marker.png' ], 'types' => [ diff --git a/Tests/Functional/Caching/AdjustsPageCacheLifetimeTest.php b/Tests/Functional/Caching/AdjustsPageCacheLifetimeTest.php index 270b351..5a01373 100644 --- a/Tests/Functional/Caching/AdjustsPageCacheLifetimeTest.php +++ b/Tests/Functional/Caching/AdjustsPageCacheLifetimeTest.php @@ -27,19 +27,9 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Sinso\Variables\EventListener\ModifyCacheLifetime; -use Sinso\Variables\Hooks\DataHandler; use Sinso\Variables\Service\VariablesService; use Sinso\Variables\Tests\Functional\Frontend\AbstractProcessesMarkersTestCase; -use TYPO3\CMS\Core\Cache\CacheManager; -use TYPO3\CMS\Core\Context\Context; -use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; #[CoversClass(ModifyCacheLifetime::class)] #[CoversClass(VariablesService::class)] diff --git a/Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php b/Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php index 45ed87e..e7b3740 100644 --- a/Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php +++ b/Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php @@ -26,13 +26,10 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Sinso\Variables\Hooks\DataHandler; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; #[CoversClass(DataHandler::class)] diff --git a/Tests/Unit/Domain/Model/MarkerCollectionTest.php b/Tests/Unit/Domain/Model/MarkerCollectionTest.php index 16da293..3701d1c 100644 --- a/Tests/Unit/Domain/Model/MarkerCollectionTest.php +++ b/Tests/Unit/Domain/Model/MarkerCollectionTest.php @@ -38,7 +38,7 @@ public function returnsType(): void { $subject = new MarkerCollection(); - self::assertSame('Sinso\Variables\Domain\Model\Marker', $subject->getType()); + self::assertSame(\Sinso\Variables\Domain\Model\Marker::class, $subject->getType()); } #[Test] diff --git a/composer.json b/composer.json index ee12552..4719a48 100644 --- a/composer.json +++ b/composer.json @@ -14,16 +14,17 @@ } }, "require": { - "php": ">= 8.1 < 8.5", + "php": ">= 8.2 < 8.6", "ramsey/collection": "^2.0", "typo3/cms-core": "^13.4" }, "require-dev": { - "rector/rector": "^0.12.23", + "rector/rector": "^2.6", "typo3/testing-framework": "^8.0", "symplify/easy-coding-standard": "^12.3", "phpstan/extension-installer": "^1.4", - "saschaegerer/phpstan-typo3": "^1.10" + "saschaegerer/phpstan-typo3": "^2.1", + "ssch/typo3-rector": "^3.16" }, "extra": { "typo3/cms": { diff --git a/ext_localconf.php b/ext_localconf.php index 100fbd1..8eadc45 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,5 @@ , mixed given\.$#' + identifier: argument.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \#1 \$fieldName of method TYPO3\\CMS\\Core\\Database\\Query\\Expression\\ExpressionBuilder\:\:gt\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \#1 \$fieldName of method TYPO3\\CMS\\Core\\Database\\Query\\Expression\\ExpressionBuilder\:\:lte\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \#1 \$identifier of method TYPO3\\CMS\\Core\\Database\\Query\\QueryBuilder\:\:quoteIdentifier\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 2 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \#2 \$array of function implode expects array\, array given\.$#' + identifier: argument.type count: 1 path: Classes/Service/VariablesService.php - - message: "#^Unable to resolve the template type T in call to method static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:makeInstance\\(\\)$#" + message: '#^Parameter \$key of class Sinso\\Variables\\Domain\\Model\\Marker constructor expects string, mixed given\.$#' + identifier: argument.type count: 1 path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \$replacement of class Sinso\\Variables\\Domain\\Model\\Marker constructor expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \$uid of class Sinso\\Variables\\Domain\\Model\\Marker constructor expects int, mixed given\.$#' + identifier: argument.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter &\$text by\-ref type of method Sinso\\Variables\\Service\\VariablesService\:\:replaceMarkersInText\(\) expects string, string\|null given\.$#' + identifier: parameterByRef.type + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Unable to resolve the template type T in call to static method TYPO3\\CMS\\Core\\Utility\\GeneralUtility\:\:makeInstance\(\)$#' + identifier: argument.templateType + count: 1 + path: Classes/Service/VariablesService.php + + - + message: '#^Parameter \#1 \$params of method Sinso\\Variables\\Hooks\\DataHandler\:\:clearCachePostProc\(\) expects array\, array\ given\.$#' + identifier: argument.type + count: 1 + path: Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php + + - + message: '#^Property TYPO3\\TestingFramework\\Core\\Functional\\FunctionalTestCase\:\:\$configurationToUseInTestInstance \(array\\) does not accept array\.$#' + identifier: assign.propertyType + count: 1 + path: Tests/Functional/Frontend/AbstractProcessesMarkersTestCase.php diff --git a/rector.php b/rector.php index f7e3f08..11f8007 100644 --- a/rector.php +++ b/rector.php @@ -3,105 +3,28 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Core\Configuration\Option; -use Rector\Core\ValueObject\PhpVersion; -use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; -use Ssch\TYPO3Rector\Configuration\Typo3Option; -use Ssch\TYPO3Rector\FileProcessor\Composer\Rector\ExtensionComposerRector; -use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\ExtbasePersistenceTypoScriptRector; -use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\FileIncludeToImportStatementTypoScriptRector; -use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector; -use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector; -use Ssch\TYPO3Rector\Rector\v9\v0\InjectAnnotationRector; +use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Set\ValueObject\LevelSetList; +use Rector\ValueObject\PhpVersion; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([ - Typo3LevelSetList::UP_TO_TYPO3_11, +/** + * If FQDNs are imported globally at a later date, it must be ensured that + * extended domain models of the EXT:news extension are excluded. To check + * which files this affects, you can look in the configuration of the PhpCsFixer. + * @see https://docs.typo3.org/p/georgringer/news/main/en-us/Tutorials/ExtendNews/ProxyClassGenerator/Index.html + */ +return RectorConfig::configure() + ->withPaths([ + getcwd() . '/Classes', + getcwd() . '/Configuration', + getcwd() . '/Tests', + getcwd() . '/ext_localconf.php', + ]) + ->withImportNames(false, true, false) + ->withPhpVersion(PhpVersion::PHP_82) + ->withSets([ + LevelSetList::UP_TO_PHP_82, + Typo3LevelSetList::UP_TO_TYPO3_13, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, ]); - - // In order to have a better analysis from phpstan we teach it here some more things - $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH); - - // FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by: - $rectorConfig->importNames(); - - // this will not import root namespace classes, like \DateTime or \Exception - $parameters = $rectorConfig->parameters(); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - - // this prevents infinite loop issues due to symlinks in e.g. ".Build/" folders within single extensions - $parameters->set(Option::FOLLOW_SYMLINKS, false); - - // Define your target version which you want to support - $rectorConfig->phpVersion(PhpVersion::PHP_73); - - // If you have an editorconfig and changed files should keep their format enable it here - // $parameters->set(Option::ENABLE_EDITORCONFIG, true); - - // If you only want to process one/some TYPO3 extension(s), you can specify its path(s) here. - // If you use the option --config change __DIR__ to getcwd() - $rectorConfig->paths([ - __DIR__, - ]); - - // If you use the option --config change __DIR__ to getcwd() - $rectorConfig->skip([ - __DIR__ . '/vendor/*', - __DIR__ . '/.Build/*', - ]); - - // This is used by the class \Ssch\TYPO3Rector\Rector\PostRector\FullQualifiedNamePostRector to force FQN in this paths and files - $parameters->set(Typo3Option::PATHS_FULL_QUALIFIED_NAMESPACES, [ - # If you are targeting TYPO3 Version 11 use can now use Short namespace - # @see namespace https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ConfigurationFiles/Index.html - 'ext_localconf.php', - 'ext_tables.php', - __DIR__ . '/**/Configuration/*.php', - __DIR__ . '/**/Configuration/**/*.php', - ]); - - // If you have trouble that rector cannot run because some TYPO3 constants are not defined add an additional constants file - // @see https://github.com/sabbelasichon/typo3-rector/blob/master/typo3.constants.php - // @see https://github.com/rectorphp/rector/blob/main/docs/static_reflection_and_autoload.md#include-files - // $parameters->set(Option::BOOTSTRAP_FILES, [ - // __DIR__ . '/typo3.constants.php' - // ]); - - // register a single rule - // $rectorConfig->rule(InjectAnnotationRector::class); - - /** - * Useful rule from RectorPHP itself to transform i.e. GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager') - * to GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class) calls. - * But be warned, sometimes it produces false positives (edge cases), so watch out - */ - // $rectorConfig->rule(StringClassNameToClassConstantRector::class); - - // Optional non-php file functionalities: - // @see https://github.com/sabbelasichon/typo3-rector/blob/main/docs/beyond_php_file_processors.md - - // Adapt your composer.json dependencies to the latest available version for the defined SetList - // $rectorConfig->sets([ - // Typo3SetList::COMPOSER_PACKAGES_104_CORE - // Typo3SetList::COMPOSER_PACKAGES_104_EXTENSIONS, - // ); - - // Rewrite your extbase persistence class mapping from typoscript into php according to official docs. - // This processor will create a summarized file with all of the typoscript rewrites combined into a single file. - // The filename can be passed as argument, "Configuration_Extbase_Persistence_Classes.php" is default. - $rectorConfig->ruleWithConfiguration(ExtbasePersistenceTypoScriptRector::class, [ - ExtbasePersistenceTypoScriptRector::FILENAME => 'Configuration_Extbase_Persistence_Classes.php', - ]); - // Add some general TYPO3 rules - $rectorConfig->rule(ConvertImplicitVariablesToExplicitGlobalsRector::class); - $rectorConfig->ruleWithConfiguration(ExtEmConfRector::class, [ - ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [], - ]); - $rectorConfig->ruleWithConfiguration(ExtensionComposerRector::class, [ - ExtensionComposerRector::TYPO3_VERSION_CONSTRAINT => '^10.4 || ^11.5', - ]); - - // Do you want to modernize your TypoScript include statements for files and move from to @import use the FileIncludeToImportStatementVisitor - // $rectorConfig->rule(FileIncludeToImportStatementTypoScriptRector::class); -};