From a3d9e093a05402adc08146f49512c1b0732893f2 Mon Sep 17 00:00:00 2001 From: "thomas.layh" Date: Mon, 4 Mar 2024 11:35:22 +0100 Subject: [PATCH] feat: - update from nimut/testing-framework to typo/testing-framework - updates for php 8.2 - updated code-styles --- Classes/Sequenzer.php | 48 ++----- Classes/Service/Typo3Service.php | 23 +-- Classes/Xclass/Connection.php | 12 +- Classes/Xclass/QueryBuilder.php | 6 +- Tests/Functional/SequenzerTest.php | 51 +++---- Tests/Functional/Xclass/ConnectionTest.php | 15 +- Tests/Functional/Xclass/QueryBuilderTest.php | 12 +- Tests/Unit/Service/Typo3ServiceTest.php | 32 ++--- Tests/Unit/Xclass/ConnectionTest.php | 17 +-- Tests/Unit/Xclass/QueryBuilderTest.php | 43 +++--- code-quality/ecs.php | 74 +++++----- code-quality/phpstan-baseline.neon | 21 +-- code-quality/phpstan.neon | 19 +-- code-quality/rector.php | 143 +++++++------------ composer.json | 22 +-- 15 files changed, 182 insertions(+), 356 deletions(-) diff --git a/Classes/Sequenzer.php b/Classes/Sequenzer.php index e7a09df..63586bf 100644 --- a/Classes/Sequenzer.php +++ b/Classes/Sequenzer.php @@ -32,8 +32,6 @@ /** * Sequenzer is used to generate system wide independent IDs - * - * @package Aoe\AoeDbSequenzer */ class Sequenzer { @@ -42,47 +40,29 @@ class Sequenzer */ public const SEQUENZER_TABLE = 'tx_aoedbsequenzer_sequenz'; - /** - * @var integer - */ - private $defaultStart = 0; + private int $defaultStart = 0; - /** - * @var integer - */ - private $defaultOffset = 1; + private int $defaultOffset = 1; /** - * @var integer in seconds + * @var int in seconds */ - private $checkInterval = 120; + private int $checkInterval = 120; - /** - * @param integer $defaultStart to set - */ - public function setDefaultStart($defaultStart): void + public function setDefaultStart(int $defaultStart): void { $this->defaultStart = $defaultStart; } - /** - * @param integer $defaultOffset to set - */ - public function setDefaultOffset($defaultOffset): void + public function setDefaultOffset(int $defaultOffset): void { $this->defaultOffset = $defaultOffset; } /** * returns next free id in the sequenz of the table - * - * @param string $table - * @param int $depth - * - * @return int - * @throws \Exception */ - public function getNextIdForTable($table, $depth = 0) + public function getNextIdForTable(string $table, int $depth = 0): int { if ($depth > 99) { throw new \Exception( @@ -90,6 +70,7 @@ public function getNextIdForTable($table, $depth = 0) 1512378158 ); } + /** @var Connection $databaseConnection */ $databaseConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::SEQUENZER_TABLE); $row = $databaseConnection->select(['*'], self::SEQUENZER_TABLE, ['tablename' => $table])->fetch(); @@ -126,13 +107,8 @@ public function getNextIdForTable($table, $depth = 0) /** * Gets the default start value for a given table. - * - * @param string $table - * - * @return int - * @throws \Exception */ - private function getDefaultStartValue($table) + private function getDefaultStartValue(string $table): int { /** @var Connection $databaseConnection */ $databaseConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::SEQUENZER_TABLE); @@ -146,12 +122,8 @@ private function getDefaultStartValue($table) /** * if no scheduler entry for the table yet exists, this method initialises the sequenzer to fit offest and start and current max value * in the table - * - * @param string $table - * - * @throws \Exception */ - private function initSequenzerForTable($table): void + private function initSequenzerForTable(string $table): void { $start = $this->getDefaultStartValue($table); diff --git a/Classes/Service/Typo3Service.php b/Classes/Service/Typo3Service.php index a779cc6..2e24ead 100644 --- a/Classes/Service/Typo3Service.php +++ b/Classes/Service/Typo3Service.php @@ -32,15 +32,9 @@ use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -/** - * @package Aoe\AoeDbSequenzer - */ class Typo3Service implements SingletonInterface { - /** - * @var Sequenzer - */ - private $sequenzer; + private Sequenzer $sequenzer; /** * @var array @@ -54,16 +48,14 @@ class Typo3Service implements SingletonInterface /** * array of configured tables that should call the sequenzer - * - * @var array */ - private $supportedTables = []; + private array $supportedTables; public function __construct(Sequenzer $sequenzer) { $this->conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('aoe_dbsequenzer'); - $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); + $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(self::class); $this->sequenzer = $sequenzer; $this->sequenzer->setDefaultOffset((int) $this->conf['offset']); @@ -75,10 +67,8 @@ public function __construct(Sequenzer $sequenzer) /** * Modify a TYPO3 insert array (key -> value) , and adds the uid that should be forced during INSERT - * - * @param string $tableName */ - public function modifyInsertFields($tableName, array $fields_values): array + public function modifyInsertFields(string $tableName, array $fields_values): array { if (!$this->needsSequenzer($tableName)) { return $fields_values; @@ -104,11 +94,8 @@ public function modifyInsertFields($tableName, array $fields_values): array /** * If a table is configured to use the sequenzer - * - * @param string $tableName - * @return boolean */ - public function needsSequenzer($tableName) + public function needsSequenzer(string $tableName): bool { return in_array($tableName, $this->supportedTables); } diff --git a/Classes/Xclass/Connection.php b/Classes/Xclass/Connection.php index 4333c16..b11187f 100644 --- a/Classes/Xclass/Connection.php +++ b/Classes/Xclass/Connection.php @@ -14,15 +14,9 @@ use TYPO3\CMS\Core\Database\Query\BulkInsertQuery; use TYPO3\CMS\Core\Utility\GeneralUtility; -/** - * @package Aoe\AoeDbSequenzer\Xclass - */ class Connection extends CoreConnection { - /** - * @var Typo3Service - */ - private $typo3Service; + private ?Typo3Service $typo3Service = null; /** * Inserts a table row with specified data. @@ -102,10 +96,8 @@ public function update($tableName, array $data, array $identifier, array $types * Why we do this? * Because some unittests backup the variable $GLOBALS (and so, also the variable $GLOBALS['TYPO3_DB']), which means, that this * object/class will be serialized/unserialized, so the instance of Typo3Service will be null after unserialization! - * - * @return Typo3Service */ - protected function getTypo3Service() + protected function getTypo3Service(): Typo3Service { if (!isset($this->typo3Service)) { $this->typo3Service = GeneralUtility::makeInstance(Typo3Service::class, new Sequenzer()); diff --git a/Classes/Xclass/QueryBuilder.php b/Classes/Xclass/QueryBuilder.php index 41cc512..5858a7a 100644 --- a/Classes/Xclass/QueryBuilder.php +++ b/Classes/Xclass/QueryBuilder.php @@ -10,13 +10,11 @@ use Aoe\AoeDbSequenzer\Sequenzer; use Aoe\AoeDbSequenzer\Service\Typo3Service; +use mysql_xdevapi\Table; use PDO; use TYPO3\CMS\Core\Database\Query\QueryBuilder as CoreQueryBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; -/** - * @package Aoe\AoeDbSequenzer\Xclass - */ class QueryBuilder extends CoreQueryBuilder { /** @@ -88,7 +86,7 @@ protected function getTypo3Service() protected function sanitizeTableName(string $tableName): string { $mark = '`'; - if (!empty($tableName) && $tableName[0] === $mark && $tableName[strlen($tableName) - 1] === $mark) { + if ($tableName !== '' && $tableName !== '0' && $tableName[0] === $mark && $tableName[strlen($tableName) - 1] === $mark) { return str_replace($mark, '', $tableName); } diff --git a/Tests/Functional/SequenzerTest.php b/Tests/Functional/SequenzerTest.php index 1b5c177..4252288 100644 --- a/Tests/Functional/SequenzerTest.php +++ b/Tests/Functional/SequenzerTest.php @@ -29,7 +29,7 @@ use Aoe\AoeDbSequenzer\Sequenzer; use Exception; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use ReflectionException; use ReflectionMethod; use TYPO3\CMS\Core\Database\ConnectionPool; @@ -42,19 +42,18 @@ class SequenzerTest extends FunctionalTestCase */ protected $subject; - protected $testExtensionsToLoad = ['typo3conf/ext/aoe_dbsequenzer']; + protected array $testExtensionsToLoad = ['typo3conf/ext/aoe_dbsequenzer']; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->subject = new Sequenzer(); } /** - * @test * @throws Exception */ - public function getNextIdForTable_throwsExceptionDepthToHigh() + public function testGetNextIdForTable_throwsExceptionDepthToHigh(): void { $this->expectException(Exception::class); $this->expectExceptionCode(1512378158); @@ -62,10 +61,7 @@ public function getNextIdForTable_throwsExceptionDepthToHigh() $this->subject->getNextIdForTable('tableName', 1000); } - /** - * @test - */ - public function getNextIdForTable_NoPagesAdded() + public function testGetNextIdForTable_NoPagesAdded(): void { $this->subject->setDefaultOffset(10); $this->subject->setDefaultStart(4); @@ -76,15 +72,12 @@ public function getNextIdForTable_NoPagesAdded() ); } - /** - * @test - */ - public function getNextIdForTable_OutDatedSequencerInformation() + public function testGetNextIdForTable_OutDatedSequencerInformation(): void { // Offset is set in Fixture (20) // Current is set in Fixture (5) $this->importDataSet(__DIR__ . '/Fixtures/tx_aoedbsequenzer_seqeunz.xml'); - $this->importDataSet('ntf://Database/pages.xml'); + $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml'); $this->assertSame( 28, @@ -92,26 +85,20 @@ public function getNextIdForTable_OutDatedSequencerInformation() ); } - /** - * @test - */ - public function getDefaultStartValue_withoutOffsetConfigured() + public function testGetDefaultStartValue_withoutOffsetConfigured(): void { // Imports 7 pages, therefor the expected StartValue should be 8 - $this->importDataSet('ntf://Database/pages.xml'); + $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml'); $method = $this->getPrivateMethod($this->subject, 'getDefaultStartValue'); $result = $method->invokeArgs($this->subject, ['pages']); $this->assertSame(8, $result); } - /** - * @test - */ - public function getDefaultStartValue_withOffsetConfigured() + public function testGetDefaultStartValue_withOffsetConfigured(): void { $this->subject->setDefaultOffset(6); - $this->importDataSet('ntf://Database/pages.xml'); + $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml'); $method = $this->getPrivateMethod($this->subject, 'getDefaultStartValue'); $result = $method->invokeArgs($this->subject, ['pages']); @@ -119,14 +106,11 @@ public function getDefaultStartValue_withOffsetConfigured() $this->assertSame(12, $result); } - /** - * @test - */ - public function getDefaultStartValue_withOffsetAndDefaultStartValueConfigured() + public function testGetDefaultStartValue_withOffsetAndDefaultStartValueConfigured(): void { $this->subject->setDefaultOffset(14); $this->subject->setDefaultStart(20); - $this->importDataSet('ntf://Database/pages.xml'); + $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml'); $method = $this->getPrivateMethod($this->subject, 'getDefaultStartValue'); $result = $method->invokeArgs($this->subject, ['pages']); @@ -134,15 +118,12 @@ public function getDefaultStartValue_withOffsetAndDefaultStartValueConfigured() $this->assertSame(34, $result); } - /** - * @test - */ - public function initSequenzerForTable_isDataInsert() + public function testInitSequenzerForTable_isDataInsert(): void { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(Sequenzer::SEQUENZER_TABLE); // Before Init - $this->assertEquals( + $this->assertSame( 0, $queryBuilder->count('*', Sequenzer::SEQUENZER_TABLE, ['tablename' => 'pages']) ); @@ -151,7 +132,7 @@ public function initSequenzerForTable_isDataInsert() $method->invokeArgs($this->subject, ['pages']); // After Init - $this->assertEquals( + $this->assertSame( 1, $queryBuilder->count('*', Sequenzer::SEQUENZER_TABLE, ['tablename' => 'pages']) ); diff --git a/Tests/Functional/Xclass/ConnectionTest.php b/Tests/Functional/Xclass/ConnectionTest.php index 8e20a1a..945d4a8 100644 --- a/Tests/Functional/Xclass/ConnectionTest.php +++ b/Tests/Functional/Xclass/ConnectionTest.php @@ -15,7 +15,7 @@ use Aoe\AoeDbSequenzer\Xclass\Connection; use Doctrine\DBAL\Driver\PDOMySql\Driver; use InvalidArgumentException; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\CMS\Core\Utility\GeneralUtility; class ConnectionTest extends FunctionalTestCase @@ -25,7 +25,7 @@ class ConnectionTest extends FunctionalTestCase */ protected $subject; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $params = []; @@ -35,18 +35,15 @@ public function setUp(): void $typo3Service = $this->getMockBuilder(Typo3Service::class) ->disableOriginalConstructor() - ->setMethods(['needsSequenzer']) + ->onlyMethods(['needsSequenzer']) ->getMock(); - $typo3Service->expects($this->any())->method('needsSequenzer')->willReturn($this->returnValue(true)); + $typo3Service->method('needsSequenzer')->willReturn(true); - $this->inject($this->subject, 'typo3Service', $typo3Service); + GeneralUtility::setSingletonInstance(Typo3Service::class, $typo3Service); } - /** - * @test - */ - public function updateThrowsExceptionWhenUidInFieldArray() + public function testUpdateThrowsExceptionWhenUidInFieldArray(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionCode(1564122222); diff --git a/Tests/Functional/Xclass/QueryBuilderTest.php b/Tests/Functional/Xclass/QueryBuilderTest.php index 2b85b5b..f36641a 100644 --- a/Tests/Functional/Xclass/QueryBuilderTest.php +++ b/Tests/Functional/Xclass/QueryBuilderTest.php @@ -13,10 +13,9 @@ use Aoe\AoeDbSequenzer\Xclass\QueryBuilder; - -use Doctrine\DBAL\Driver\PDOSqlite\Driver; +use Doctrine\DBAL\Driver\PDO\SQLite\Driver; use InvalidArgumentException; -use Nimut\TestingFramework\TestCase\FunctionalTestCase; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -27,7 +26,7 @@ class QueryBuilderTest extends FunctionalTestCase */ protected $subject; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $params = []; @@ -38,10 +37,7 @@ public function setUp(): void $this->subject->expects($this->once())->method('shouldTableBeSequenced')->willReturn(true); } - /** - * @test - */ - public function QueryBuilderSetThrowsExceptionWhenUidIsKey() + public function testQueryBuilderSetThrowsExceptionWhenUidIsKey(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionCode(1564122229); diff --git a/Tests/Unit/Service/Typo3ServiceTest.php b/Tests/Unit/Service/Typo3ServiceTest.php index 3205f5a..43b9b62 100644 --- a/Tests/Unit/Service/Typo3ServiceTest.php +++ b/Tests/Unit/Service/Typo3ServiceTest.php @@ -26,9 +26,10 @@ use Aoe\AoeDbSequenzer\Sequenzer; use Aoe\AoeDbSequenzer\Service\Typo3Service; -use Nimut\TestingFramework\TestCase\UnitTestCase; +use PHPUnit\Framework\MockObject\MockObject; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * @package Aoe\AoeDbSequenzer\Tests\Unit @@ -36,20 +37,17 @@ */ class Typo3ServiceTest extends UnitTestCase { - /** - * @var Typo3Service - */ - private $service; + private Typo3Service $service; /** - * @var Sequenzer|\PHPUnit_Framework_MockObject_MockObject + * @var Sequenzer|MockObject */ - private $sequenzer; + private MockObject $sequenzer; /** * @see PHPUnit_Framework_TestCase::setUp() */ - public function setUp(): void + protected function setUp(): void { $testConfiguration = []; $testConfiguration['aoe_dbsequenzer']['offset'] = '1'; @@ -63,24 +61,20 @@ public function setUp(): void $this->service = new Typo3Service($this->sequenzer); } - /** - * @test - */ - public function modifyInsertFields_NotSupportedTable() + public function testModifyInsertFields_NotSupportedTable(): void { + $this->resetSingletonInstances = true; $this->sequenzer->expects($this->never())->method('getNextIdForTable'); $modifiedFields = $this->service->modifyInsertFields('tableXY', ['field1' => 'a']); - $this->assertFalse(isset($modifiedFields['uid'])); + $this->assertArrayNotHasKey('uid', $modifiedFields); } - /** - * @test - */ - public function modifyInsertFields_GetNextIdForTable() + public function testModifyInsertFields_GetNextIdForTable(): void { + $this->resetSingletonInstances = true; $this->sequenzer->expects($this->once())->method('getNextIdForTable')->willReturn(1); $modifiedFields = $this->service->modifyInsertFields('table1', ['field1' => 'a']); - $this->assertTrue(isset($modifiedFields['uid'])); - $this->assertEquals(1, $modifiedFields['uid']); + $this->assertArrayHasKey('uid', $modifiedFields); + $this->assertSame(1, $modifiedFields['uid']); } } diff --git a/Tests/Unit/Xclass/ConnectionTest.php b/Tests/Unit/Xclass/ConnectionTest.php index cbc6673..e83b699 100644 --- a/Tests/Unit/Xclass/ConnectionTest.php +++ b/Tests/Unit/Xclass/ConnectionTest.php @@ -14,9 +14,9 @@ use Aoe\AoeDbSequenzer\Service\Typo3Service; use Aoe\AoeDbSequenzer\Xclass\Connection; -use Nimut\TestingFramework\TestCase\UnitTestCase; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class ConnectionTest extends UnitTestCase { @@ -25,25 +25,20 @@ class ConnectionTest extends UnitTestCase */ protected $subject; - public function setUp(): void + protected function setUp(): void { $testConfiguration = []; $testConfiguration['aoe_dbsequenzer']['offset'] = '1'; $testConfiguration['aoe_dbsequenzer']['system'] = 'testa'; $testConfiguration['aoe_dbsequenzer']['tables'] = 'table1,table2'; GeneralUtility::makeInstance(ExtensionConfiguration::class)->setAll($testConfiguration); - - $this->subject = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->getMock(); } - /** - * @test - */ - public function expectsTypo3ServiceIsInitiated() + public function testExpectsTypo3ServiceIsInitiated(): void { - $typo3Service = $this->callInaccessibleMethod($this->subject, 'getTypo3Service'); + // $typo3Service = $this->callInaccessibleMethod($this->subject, 'getTypo3Service'); + $this->subject = $this->getAccessibleMock(Connection::class, ['getTypo3Service'], [], '', false); + $typo3Service = $this->subject->_call('getTypo3Service'); $this->assertInstanceOf( Typo3Service::class, diff --git a/Tests/Unit/Xclass/QueryBuilderTest.php b/Tests/Unit/Xclass/QueryBuilderTest.php index 0889bb4..8cafa74 100644 --- a/Tests/Unit/Xclass/QueryBuilderTest.php +++ b/Tests/Unit/Xclass/QueryBuilderTest.php @@ -1,9 +1,10 @@ subject = $this->getAccessibleMock(QueryBuilder::class, ['dummy'], [], '', false); + $this->subject = $this->getAccessibleMock(QueryBuilder::class, null, [], '', false); } /** - * @test * @dataProvider sanitizeTableNameDataProvider */ - public function sanitizeTableName($tableName, $expected) + public function testSanitizeTableName(string $tableName, string $expected): void { - $this->assertEquals( + $this->assertSame( $expected, $this->subject->_call('sanitizeTableName', $tableName) ); } - /** - * @return array - */ - public function sanitizeTableNameDataProvider() + public static function sanitizeTableNameDataProvider(): \Iterator { - return [ - 'tableName with out quotes' => [ - 'tableName' => 'sys_log', - 'expected' => 'sys_log' - ], - 'tableName with back quotes' => [ - 'tableName' => '`sys_log`', - 'expected' => 'sys_log' - ], - 'empty tableName' => [ - 'tableName' => '', - 'expected' => '' - ] + yield 'tableName with out quotes' => [ + 'tableName' => 'sys_log', + 'expected' => 'sys_log' + ]; + yield 'tableName with back quotes' => [ + 'tableName' => '`sys_log`', + 'expected' => 'sys_log' + ]; + yield 'empty tableName' => [ + 'tableName' => '', + 'expected' => '' ]; } - - } diff --git a/code-quality/ecs.php b/code-quality/ecs.php index a80af61..ad38d24 100644 --- a/code-quality/ecs.php +++ b/code-quality/ecs.php @@ -7,55 +7,45 @@ use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; use PhpCsFixer\Fixer\Strict\StrictComparisonFixer; use PhpCsFixer\Fixer\Strict\StrictParamFixer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer; use Symplify\CodingStandard\Fixer\LineLength\DocBlockLineLengthFixer; use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; -use Symplify\EasyCodingStandard\ValueObject\Option; +use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ContainerConfigurator $containerConfigurator): void { - $parameters = $containerConfigurator->parameters(); - $parameters->set( - Option::PATHS, +return ECSConfig::configure() + ->withPaths([ + __DIR__ . '/../Classes', + __DIR__ . '/ecs.php', + ]) + ->withSets([ + SetList::COMMON, + SetList::CLEAN_CODE, + SetList::PSR_12, + SetList::SYMPLIFY, + ]) + ->withConfiguredRule( + LineLengthFixer::class, [ - __DIR__ . '/../Classes', - __DIR__ . '/ecs.php', - ] - ); - - $containerConfigurator->import(SetList::COMMON); - $containerConfigurator->import(SetList::CLEAN_CODE); - $containerConfigurator->import(SetList::PSR_12); - $containerConfigurator->import(SetList::SYMPLIFY); - - $containerConfigurator->services() - ->set(LineLengthFixer::class) - ->call('configure', [[ LineLengthFixer::LINE_LENGTH => 140, LineLengthFixer::INLINE_SHORT_LINES => false, - ]]); - - // Skip Rules and Sniffer - $parameters->set( - Option::SKIP, - [ - // Default Skips - NotOperatorWithSuccessorSpaceFixer::class => null, - DocBlockLineLengthFixer::class => null, - ArrayListItemNewlineFixer::class => null, - ArrayOpenerAndCloserNewlineFixer::class => null, - - // @todo for next upgrade - YodaStyleFixer::class => [ - __DIR__ . '/../Classes/Sequenzer.php', - ], - - // @todo strict php - DeclareStrictTypesFixer::class => null, - StrictComparisonFixer::class => null, - StrictParamFixer::class => null, ] - ); -}; + ) + ->withSkip([ + // Default Skips + NotOperatorWithSuccessorSpaceFixer::class => null, + DocBlockLineLengthFixer::class => null, + ArrayListItemNewlineFixer::class => null, + ArrayOpenerAndCloserNewlineFixer::class => null, + + // @todo for next upgrade + YodaStyleFixer::class => [ + __DIR__ . '/../Classes/Sequenzer.php', + ], + + // @todo strict php + DeclareStrictTypesFixer::class => null, + StrictComparisonFixer::class => null, + StrictParamFixer::class => null, + ]); diff --git a/code-quality/phpstan-baseline.neon b/code-quality/phpstan-baseline.neon index 4770fff..eb2db23 100644 --- a/code-quality/phpstan-baseline.neon +++ b/code-quality/phpstan-baseline.neon @@ -3,22 +3,7 @@ parameters: - message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Result\\:\\:fetch\\(\\)\\.$#" path: ../Classes/Sequenzer.php - - - message: "#^Call to an undefined method object\\:\\:getConnectionForTable\\(\\)\\.$#" - path: ../Classes/Sequenzer.php - - - - message: "#^Call to an undefined method object\\:\\:(get|getLogger)\\(\\)\\.$#" - path: ../Classes/Service/Typo3Service.php - - - - message: "#^Call to an undefined method object\\:\\:(addValues|execute)\\(\\)\\.$#" - path: ../Classes/Xclass/Connection.php - - - - message: "#^Property Aoe\\\\AoeDbSequenzer\\\\Xclass\\\\(QueryBuilder|Connection)\\:\\:\\$typo3Service \\(Aoe\\\\AoeDbSequenzer\\\\Service\\\\Typo3Service\\) does not accept object\\.$#" - paths: - - ../Classes/Xclass/Connection.php - - ../Classes/Xclass/QueryBuilder.php - + message: "#^Property Aoe\\\\AoeDbSequenzer\\\\Xclass\\\\QueryBuilder\\:\\:\\$typo3Service \\(Aoe\\\\AoeDbSequenzer\\\\Service\\\\Typo3Service\\) in isset\\(\\) is not nullable\\.$#" + count: 1 + path: ../Classes/Xclass/QueryBuilder.php diff --git a/code-quality/phpstan.neon b/code-quality/phpstan.neon index 552f30f..a3df5cf 100644 --- a/code-quality/phpstan.neon +++ b/code-quality/phpstan.neon @@ -1,12 +1,10 @@ includes: + - ../.Build/vendor/symplify/phpstan-rules/config/services/services.neon + - ../.Build/vendor/symplify/phpstan-rules/config/code-complexity-rules.neon - phpstan-baseline.neon - - ../.Build/vendor/symplify/phpstan-rules/packages/cognitive-complexity/config/cognitive-complexity-rules.neon - -rules: - - Symplify\PHPStanRules\Rules\NoDefaultExceptionRule parameters: - level: max + level: 6 paths: - "../Classes/" @@ -15,17 +13,6 @@ parameters: checkGenericClassInNonGenericObjectType: false services: - - class: Symplify\Astral\Naming\SimpleNameResolver - - class: Symplify\PHPStanRules\CognitiveComplexity\AstCognitiveComplexityAnalyzer - - class: Symplify\PHPStanRules\CognitiveComplexity\NodeTraverser\ComplexityNodeTraverserFactory - - class: Symplify\PHPStanRules\CognitiveComplexity\DataCollector\CognitiveComplexityDataCollector - - class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\NestingNodeVisitor - - class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\ComplexityNodeVisitor - - class: Symplify\PHPStanRules\CognitiveComplexity\NodeAnalyzer\ComplexityAffectingNodeFinder - - class: Symplify\PackageBuilder\Php\TypeChecker - - class: Symplify\PackageBuilder\Matcher\ArrayStringAndFnMatcher - - class: Symplify\PHPStanRules\TypeAnalyzer\ObjectTypeAnalyzer - - class: Symplify\PHPStanRules\TypeAnalyzer\TypeUnwrapper - class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule tags: [phpstan.rules.rule] diff --git a/code-quality/rector.php b/code-quality/rector.php index 8c91385..5ff8828 100644 --- a/code-quality/rector.php +++ b/code-quality/rector.php @@ -6,111 +6,70 @@ use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector; use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; -use Rector\CodeQualityStrict\Rector\If_\MoveOutMethodCallInsideIfConditionRector; -use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector; -use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector; use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector; -use Rector\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector; -use Rector\Core\Configuration\Option; +use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\Cast\RecastingRemovalRector; -use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector; use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; -use Rector\Defluent\Rector\Return_\ReturnFluentChainMethodCallToNormalMethodCallRector; use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector; -use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector; -use Rector\EarlyReturn\Rector\Return_\ReturnBinaryAndToEarlyReturnRector; use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector; use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector; -use Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; +use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\PHPUnit\Set\PHPUnitSetList; -use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector; use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector; -use Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector; -use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector; -use Rector\Privatization\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector; use Rector\Set\ValueObject\SetList; -use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector; -use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector; -use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -return static function (ContainerConfigurator $containerConfigurator): void { +return RectorConfig::configure() + ->withPaths([ + __DIR__ . '/../Classes', + __DIR__ . '/../Tests', + __DIR__ . '/../code-quality', + ]) + ->withPhpSets( + false, + true + ) + ->withSets([ + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::DEAD_CODE, + SetList::EARLY_RETURN, + SetList::PRIVATIZATION, + SetList::TYPE_DECLARATION, + SetList::PHP_74, + SetList::PHP_80, + SetList::PHP_81, + SetList::PHP_82, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + ]) + ->withRules([ + RemoveUnusedPrivatePropertyRector::class, + ]) + ->withSkip([ + RecastingRemovalRector::class, + PostIncDecToPreIncDecRector::class, + FinalizeClassesWithoutChildrenRector::class, + ChangeAndIfToEarlyReturnRector::class, + IssetOnPropertyObjectToPropertyExistsRector::class, + FlipTypeControlToUseExclusiveTypeRector::class, + RenameVariableToMatchNewTypeRector::class, + AddLiteralSeparatorToNumberRector::class, + RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class, - $containerConfigurator->import(SetList::CODE_QUALITY); - $containerConfigurator->import(SetList::CODE_QUALITY_STRICT); - $containerConfigurator->import(SetList::CODING_STYLE); - $containerConfigurator->import(SetList::DEAD_CODE); - $containerConfigurator->import(SetList::EARLY_RETURN); - $containerConfigurator->import(SetList::PRIVATIZATION); - $containerConfigurator->import(SetList::TYPE_DECLARATION); - $containerConfigurator->import(SetList::PSR_4); - $containerConfigurator->import(SetList::MYSQL_TO_MYSQLI); - $containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT); - $containerConfigurator->import(SetList::UNWRAP_COMPAT); + ClassPropertyAssignToConstructorPromotionRector::class => [ + __DIR__ . '/../Classes/Service/Typo3Service.php', + ], - $containerConfigurator->import(SetList::PHP_72); - $containerConfigurator->import(SetList::PHP_73); - $containerConfigurator->import(SetList::PHP_74); - $containerConfigurator->import(SetList::PHP_80); - - $containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY); - - $parameters = $containerConfigurator->parameters(); - $parameters->set( - Option::PATHS, - [ - __DIR__ . '/../Classes', - __DIR__ . '/rector.php', - ] - ); - - $parameters->set(Option::AUTO_IMPORT_NAMES, false); - $parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/../Classes']); - $parameters->set( - Option::SKIP, - [ - RecastingRemovalRector::class, - ConsistentPregDelimiterRector::class, - PostIncDecToPreIncDecRector::class, - FinalizeClassesWithoutChildrenRector::class, - ChangeOrIfReturnToEarlyReturnRector::class, - ChangeAndIfToEarlyReturnRector::class, - ReturnBinaryAndToEarlyReturnRector::class, - MakeBoolPropertyRespectIsHasWasMethodNamingRector::class, - MoveOutMethodCallInsideIfConditionRector::class, - ReturnArrayClassMethodToYieldRector::class, - AddArrayParamDocTypeRector::class, - AddArrayReturnDocTypeRector::class, - ReturnFluentChainMethodCallToNormalMethodCallRector::class, - IssetOnPropertyObjectToPropertyExistsRector::class, - FlipTypeControlToUseExclusiveTypeRector::class, - RepeatedLiteralToClassConstantRector::class, - RenameVariableToMatchNewTypeRector::class, - AddLiteralSeparatorToNumberRector::class, - RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class, - ChangeReadOnlyVariableWithDefaultValueToConstantRector::class, - PrivatizeLocalPropertyToPrivatePropertyRector::class, - RemoveDelegatingParentCallRector::class, - - ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class, - - // @todo strict php - ArgumentAdderRector::class, - ParamTypeDeclarationRector::class, - ReturnTypeDeclarationRector::class, - RemoveExtraParametersRector::class, - EncapsedStringsToSprintfRector::class, - AddFalseDefaultToBoolPropertyRector::class, - WrapEncapsedVariableInCurlyBracesRector::class, - UseIdenticalOverEqualWithSameTypeRector::class, - ] - ); - - $services = $containerConfigurator->services(); - $services->set(RemoveUnusedPrivatePropertyRector::class); -}; + // @todo strict php + ArgumentAdderRector::class, + RemoveExtraParametersRector::class, + EncapsedStringsToSprintfRector::class, + WrapEncapsedVariableInCurlyBracesRector::class, + UseIdenticalOverEqualWithSameTypeRector::class, + ]) + ->withAutoloadPaths([__DIR__ . '/../Classes']) + ->withCache('.cache/rector/default') + ->withImportNames(false); diff --git a/composer.json b/composer.json index 2a00b1d..ec82510 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^8.0 || ^8.2", "ext-mysqli": "*", "typo3/cms-core": "^9.5 || ^10.4 || ^11.5", "typo3/cms-extbase": "^9.5 || ^10.4 || ^11.5", @@ -26,12 +26,12 @@ "typo3/cms-frontend": "^9.5 || ^10.4 || ^11.5" }, "require-dev": { - "nimut/testing-framework": "6.x-dev", + "typo3/testing-framework": "^7.0", "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "0.12.88", - "rector/rector": "0.11.20", - "symplify/easy-coding-standard": "9.3.26", - "symplify/phpstan-rules": "9.3.26" + "phpstan/phpstan": "^1.10", + "rector/rector": "^1.0", + "symplify/easy-coding-standard": "12.1.14", + "symplify/phpstan-rules": "12.4.8" }, "replace": { "typo3-ter/aoe-dbsequenzer": "self.version" @@ -64,24 +64,24 @@ "[ -e .Build/bin/phpunit ] || composer update", "mkdir -p reports && rm -rf reports/*", "cp Tests/Unit/Fixtures/LocalConfiguration.php .Build/Web/typo3conf/LocalConfiguration.php", - "XDEBUG_MODE=coverage TYPO3_PATH_WEB=$PWD/.Build/Web .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit", - "XDEBUG_MODE=coverage TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml Tests/Functional", + "XDEBUG_MODE=coverage TYPO3_PATH_WEB=$PWD/.Build/Web .Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit", + "XDEBUG_MODE=coverage TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests/Functional", "rm .Build/Web/typo3conf/LocalConfiguration.php" ], "test:unit": [ "[ -e .Build/bin/phpunit ] || composer update", "cp Tests/Unit/Fixtures/LocalConfiguration.php .Build/Web/typo3conf/LocalConfiguration.php", - "TYPO3_PATH_WEB=$PWD/.Build/Web .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit", + "TYPO3_PATH_WEB=$PWD/.Build/Web .Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit", "rm .Build/Web/typo3conf/LocalConfiguration.php" ], "test:functional": [ "[ -e .Build/bin/phpunit ] || composer update", - "TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml Tests/Functional" + "TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests/Functional" ], "test:coverage": [ "[ -e .Build/bin/phpunit ] || composer update", "mkdir -p reports && rm -rf reports/*", - "TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit --whitelist=Classes --coverage-html=reports -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml Tests" + "TYPO3_PATH_WEB=$PWD/.Build/Web typo3DatabaseName=sequenzer typo3DatabaseHost=127.0.0.1 typo3DatabaseUsername=root typo3DatabasePassword=root .Build/bin/phpunit --whitelist=Classes --coverage-html=reports -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests" ], "code-style": [ "[ -e ./.Build/bin/rector ] || composer install",