From 943adfaa5e016e9c35835edf57427a35ec000331 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 31 Jan 2024 22:09:36 +0100 Subject: [PATCH] improve code --- autoload/functions_oxDIC.php | 1 - composer.json | 7 ++- d3DicHandler.php | 24 --------- d3DicUtilities.php | 11 ----- definitionFileContainer.php | 19 ------- rector.php | 55 +++++++++++++++++++++ tests/unit/autoload/functions_oxDICTest.php | 1 - tests/unit/d3DicHandlerTest.php | 26 +--------- tests/unit/d3DicUtilitiesTest.php | 8 --- tests/unit/definitionFileContainerTest.php | 20 +------- 10 files changed, 62 insertions(+), 110 deletions(-) create mode 100644 rector.php diff --git a/autoload/functions_oxDIC.php b/autoload/functions_oxDIC.php index 3d3025b..71ffaaf 100644 --- a/autoload/functions_oxDIC.php +++ b/autoload/functions_oxDIC.php @@ -17,7 +17,6 @@ use D3\DIContainerHandler\d3DicHandler; use Symfony\Component\DependencyInjection\Container; /** - * @return Container * @throws Exception */ function d3GetOxidDIC(): Container diff --git a/composer.json b/composer.json index faf57c8..7e54fb1 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "d3/testingtools": "^1.0", "phpunit/phpunit": "^9.6", "friendsofphp/php-cs-fixer": "~3.13.0", - "phpstan/phpstan": "^1.10" + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.18.13" }, "autoload": { "psr-4": { @@ -45,6 +46,8 @@ "phpstan": "./vendor/bin/phpstan --configuration=vendor/d3/oxid-dic-handler/phpstan.neon analyse", "phpstan-report": "./vendor/bin/phpstan --configuration=vendor/d3/ordermanager/phpstan.neon analyse --error-format=json > vendor/d3/ordermanager/tests/phpstan.report.json", - "phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/" + "phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/", + + "rector": "./vendor/bin/rector process --dry-run --config ./vendor/d3/oxid-dic-handler/rector.php" } } diff --git a/d3DicHandler.php b/d3DicHandler.php index da29fa8..9d33a6f 100644 --- a/d3DicHandler.php +++ b/d3DicHandler.php @@ -37,7 +37,6 @@ class d3DicHandler implements d3DicHandlerInterface /** * get instance * - * @return Container * @throws Exception */ public static function getInstance(): Container @@ -61,7 +60,6 @@ class d3DicHandler implements d3DicHandlerInterface /** * get instance * - * @return Container * @throws Exception */ public static function getUncompiledInstance(): Container @@ -85,9 +83,6 @@ class d3DicHandler implements d3DicHandlerInterface self::$_instance = null; } - /** - * @return Config - */ public function d3GetConfig(): Config { return Registry::getConfig(); @@ -98,20 +93,12 @@ class d3DicHandler implements d3DicHandlerInterface return $this->d3GetConfig()->getConfigParam('sCompileDir').'/d3DicContainer_'.Registry::getConfig()->getShopId().'.php'; } - /** - * @return Container - */ public function d3GetCacheContainer(): Container { require_once $this->d3GetCacheFilePath(); return oxNew(d3DIContainerCache::class); } - /** - * @param ContainerBuilder $container - * - * @return YamlFileLoader - */ public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader { /** @var YamlFileLoader $fileLoader */ @@ -125,8 +112,6 @@ class d3DicHandler implements d3DicHandlerInterface } /** - * @param ContainerBuilder $container - * * @throws Exception */ public function loadFiles(ContainerBuilder $container): void @@ -142,26 +127,17 @@ class d3DicHandler implements d3DicHandlerInterface } } - /** - * @return bool - */ protected function isNotInTest(): bool { return false == defined('OXID_PHP_UNIT') || true == defined('D3_MODCFG_TEST'); } - /** - * @return bool - */ protected function cacheFileExists(): bool { return file_exists($this->d3GetCacheFilePath()); } /** - * @param bool $compileAndDump - * - * @return Container * @throws Exception */ public function buildContainer(bool $compileAndDump = true): Container diff --git a/d3DicUtilities.php b/d3DicUtilities.php index d3e3884..f085871 100644 --- a/d3DicUtilities.php +++ b/d3DicUtilities.php @@ -18,10 +18,8 @@ namespace D3\DIContainerHandler; class d3DicUtilities { /** - * @param string $classNameSpace * @param string|null $additional * - * @return string */ public static function getServiceId(string $classNameSpace, string $additional = null): string { @@ -31,12 +29,6 @@ class d3DicUtilities ); } - /** - * @param string $classNamespace - * @param string $argumentName - * - * @return string - */ public static function getArgumentId(string $classNamespace, string $argumentName): string { return strtolower( @@ -46,9 +38,6 @@ class d3DicUtilities ); } - /** - * @return string - */ public static function getVendorDir(): string { return rtrim(dirname(__FILE__, 3), '/') . '/'; diff --git a/definitionFileContainer.php b/definitionFileContainer.php index a0d3931..b8cee35 100644 --- a/definitionFileContainer.php +++ b/definitionFileContainer.php @@ -34,12 +34,6 @@ class definitionFileContainer { } - /** - * @param string $definitionFile - * @param string $type - * - * @return void - */ public function addDefinitions(string $definitionFile, string $type): void { Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type'); @@ -48,21 +42,11 @@ class definitionFileContainer $this->definitionFiles[$type][md5($definitionFile)] = $definitionFile; } - /** - * @param string $definitionFile - * - * @return void - */ public function addYamlDefinitions(string $definitionFile): void { $this->addDefinitions($definitionFile, self::TYPE_YAML); } - /** - * @param string $type - * - * @return array - */ public function getDefinitions(string $type): array { Assert::that($type)->inArray($this->allowedTypes, 'invalid definition file type'); @@ -70,9 +54,6 @@ class definitionFileContainer return $this->definitionFiles[$type]; } - /** - * @return array - */ public function getYamlDefinitions(): array { return $this->getDefinitions(self::TYPE_YAML); diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..70f8449 --- /dev/null +++ b/rector.php @@ -0,0 +1,55 @@ +paths([ + __DIR__ . '/.', + ]); + + $rectorConfig->bootstrapFiles([ + __DIR__.'/../../oxid-esales/oxideshop-ce/source/oxfunctions.php', + __DIR__.'/../../oxid-esales/oxideshop-ce/source/overridablefunctions.php', + ]); + + $rectorConfig->skip( + [ + MixedTypeRector::class, // shouldn't remove argument annotations + ] + ); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, // lowest possible PHP version for this plugin is 8.0 + SetList::TYPE_DECLARATION, + SetList::INSTANCEOF, + SetList::EARLY_RETURN, + SetList::DEAD_CODE, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + ]); + + $rectorConfig->importNames(); +}; diff --git a/tests/unit/autoload/functions_oxDICTest.php b/tests/unit/autoload/functions_oxDICTest.php index 674eefe..432ecae 100644 --- a/tests/unit/autoload/functions_oxDICTest.php +++ b/tests/unit/autoload/functions_oxDICTest.php @@ -26,7 +26,6 @@ class functions_oxDICTest extends TestCase /** * @test - * @return void * @throws Exception */ public function d3GetOxidDICTest(): void diff --git a/tests/unit/d3DicHandlerTest.php b/tests/unit/d3DicHandlerTest.php index d206d6b..4c39d1c 100644 --- a/tests/unit/d3DicHandlerTest.php +++ b/tests/unit/d3DicHandlerTest.php @@ -34,7 +34,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::getInstance */ @@ -71,7 +70,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::getUncompiledInstance */ @@ -94,7 +92,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::removeInstance */ @@ -123,7 +120,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::d3GetConfig */ @@ -142,7 +138,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::d3GetCacheFilePath */ @@ -161,7 +156,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::d3GetCacheContainer */ @@ -182,7 +176,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::d3GetFileLoader */ @@ -205,7 +198,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::loadFiles */ @@ -235,7 +227,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::isNotInTest */ @@ -252,14 +243,12 @@ class d3DicHandlerTest extends TestCase } /** - * @param bool $cacheExist * @test - * @return void * @throws ReflectionException * @dataProvider cacheFileExistsTestDataProvider * @covers \D3\DIContainerHandler\d3DicHandler::cacheFileExists */ - public function cacheFileExistsTest(bool $cacheExist) + public function cacheFileExistsTest(bool $cacheExist): void { if (!$cacheExist) { $sut = $this->getMockBuilder(d3DicHandler::class) @@ -279,9 +268,6 @@ class d3DicHandlerTest extends TestCase ); } - /** - * @return Generator - */ public function cacheFileExistsTestDataProvider(): Generator { yield 'cacheExist' => [true]; @@ -291,13 +277,7 @@ class d3DicHandlerTest extends TestCase /** * @test * - * @param bool $productive - * @param int $debug - * @param bool $notInTest - * @param bool $cacheFileExist - * @param bool $cachedContainer * - * @return void * @throws ReflectionException * @dataProvider buildContainerTestDataProvider * @covers \D3\DIContainerHandler\d3DicHandler::buildContainer @@ -335,9 +315,6 @@ class d3DicHandlerTest extends TestCase ); } - /** - * @return Generator - */ public function buildContainerTestDataProvider(): Generator { yield 'notProductive' => [false, 0, false, true, false]; @@ -349,7 +326,6 @@ class d3DicHandlerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicHandler::getContainerBuilder */ diff --git a/tests/unit/d3DicUtilitiesTest.php b/tests/unit/d3DicUtilitiesTest.php index 30f8f68..7742a24 100644 --- a/tests/unit/d3DicUtilitiesTest.php +++ b/tests/unit/d3DicUtilitiesTest.php @@ -29,11 +29,8 @@ class d3DicUtilitiesTest extends TestCase /** * @test * - * @param string $className * @param string|null $additional - * @param string $expected * - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId * @dataProvider getServiceIdTestDataProvider @@ -61,11 +58,7 @@ class d3DicUtilitiesTest extends TestCase /** * @test * - * @param string $className - * @param string $argumentName - * @param string $expected * - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicUtilities::getArgumentId * @dataProvider getArgumentIdTestDataProvider @@ -91,7 +84,6 @@ class d3DicUtilitiesTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\d3DicUtilities::getVendorDir() */ diff --git a/tests/unit/definitionFileContainerTest.php b/tests/unit/definitionFileContainerTest.php index db24f60..2d26b89 100644 --- a/tests/unit/definitionFileContainerTest.php +++ b/tests/unit/definitionFileContainerTest.php @@ -29,12 +29,7 @@ class definitionFileContainerTest extends TestCase /** * @test * - * @param string $file - * @param string $type - * @param int $sumand - * @param bool $expectException * - * @return void * @throws ReflectionException * @dataProvider addDefinitionsTestDataProvider * @covers \D3\DIContainerHandler\definitionFileContainer::addDefinitions @@ -62,9 +57,6 @@ class definitionFileContainerTest extends TestCase ); } - /** - * @return Generator - */ public function addDefinitionsTestDataProvider(): Generator { yield 'invalid file' => ['foo.txt', definitionFileContainer::TYPE_YAML, 0, true]; @@ -74,7 +66,6 @@ class definitionFileContainerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\definitionFileContainer::addYamlDefinitions */ @@ -95,10 +86,7 @@ class definitionFileContainerTest extends TestCase /** * @test * - * @param string $type - * @param bool $expectException * - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\definitionFileContainer::getDefinitions * @dataProvider getDefinitionsTestDataProvider @@ -120,9 +108,6 @@ class definitionFileContainerTest extends TestCase $this->assertIsArray($definitions); } - /** - * @return Generator - */ public function getDefinitionsTestDataProvider(): Generator { yield 'type ok' => [definitionFileContainer::TYPE_YAML, false]; @@ -131,7 +116,6 @@ class definitionFileContainerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\definitionFileContainer::getYamlDefinitions */ @@ -150,7 +134,6 @@ class definitionFileContainerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\definitionFileContainer::getAll */ @@ -176,11 +159,10 @@ class definitionFileContainerTest extends TestCase /** * @test - * @return void * @throws ReflectionException * @covers \D3\DIContainerHandler\definitionFileContainer::clear */ - public function clearTest() + public function clearTest(): void { $sut = oxNew(definitionFileContainer::class); $sut->addYamlDefinitions('d3/modcfg/Config/services.yaml');