improve code
This commit is contained in:
parent
3a1c270932
commit
943adfaa5e
@ -17,7 +17,6 @@ use D3\DIContainerHandler\d3DicHandler;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
/**
|
||||
* @return Container
|
||||
* @throws Exception
|
||||
*/
|
||||
function d3GetOxidDIC(): Container
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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), '/') . '/';
|
||||
|
@ -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);
|
||||
|
55
rector.php
Normal file
55
rector.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
|
||||
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
|
||||
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
|
||||
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
|
||||
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
|
||||
use Rector\Set\ValueObject\LevelSetList;
|
||||
use Rector\Set\ValueObject\SetList;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->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();
|
||||
};
|
@ -26,7 +26,6 @@ class functions_oxDICTest extends TestCase
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function d3GetOxidDICTest(): void
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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()
|
||||
*/
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user