improve code style

This commit is contained in:
Daniel Seifert 2024-01-31 21:17:51 +01:00
parent 8345a843c3
commit b58f1b4156
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
6 changed files with 35 additions and 25 deletions

View File

@ -27,7 +27,8 @@
}, },
"require-dev": { "require-dev": {
"d3/testingtools": "^1.0", "d3/testingtools": "^1.0",
"phpunit/phpunit": "^9.6" "phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "~3.13.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -38,6 +39,8 @@
] ]
}, },
"scripts": { "scripts": {
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/oxid-dic-handler/.php-cs-fixer.php",
"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/"
} }
} }

View File

@ -31,7 +31,7 @@ class d3DicHandler implements d3DicHandlerInterface
protected static Container|null $_instance = null; protected static Container|null $_instance = null;
public static array $circularReferenceMethodNames = [ public static array $circularReferenceMethodNames = [
'getViewConfig' 'getViewConfig',
]; ];
/** /**
@ -46,8 +46,7 @@ class d3DicHandler implements d3DicHandlerInterface
$caller = $trace[1]; $caller = $trace[1];
$functionName = $caller['function']; $functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
{
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference"); throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
} }
@ -71,8 +70,7 @@ class d3DicHandler implements d3DicHandlerInterface
$caller = $trace[1]; $caller = $trace[1];
$functionName = $caller['function']; $functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
{
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference"); throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
} }
@ -117,7 +115,8 @@ class d3DicHandler implements d3DicHandlerInterface
public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader
{ {
/** @var YamlFileLoader $fileLoader */ /** @var YamlFileLoader $fileLoader */
$fileLoader = oxNew(YamlFileLoader::class, $fileLoader = oxNew(
YamlFileLoader::class,
$container, $container,
oxNew(FileLocator::class, d3DicUtilities::getVendorDir()) oxNew(FileLocator::class, d3DicUtilities::getVendorDir())
); );
@ -167,12 +166,14 @@ class d3DicHandler implements d3DicHandlerInterface
*/ */
public function buildContainer(bool $compileAndDump = true): Container public function buildContainer(bool $compileAndDump = true): Container
{ {
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) startProfile(__METHOD__); if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
startProfile(__METHOD__);
}
$config = $this->d3GetConfig(); $config = $this->d3GetConfig();
if ( $config->isProductiveMode() if ($config->isProductiveMode()
&& ! $config->getConfigParam( 'iDebug' ) && ! $config->getConfigParam('iDebug')
&& $this->isNotInTest() && $this->isNotInTest()
&& $this->cacheFileExists() && $this->cacheFileExists()
) { ) {
@ -186,12 +187,14 @@ class d3DicHandler implements d3DicHandlerInterface
if ($this->isNotInTest()) { if ($this->isNotInTest()) {
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);
file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(array('class' => 'd3DIContainerCache'))); file_put_contents($this->d3GetCacheFilePath(), $dumper->dump(['class' => 'd3DIContainerCache']));
} }
} }
} }
if ((bool) Registry::get( ConfigFile::class)->getVar( 'iDebug')) stopProfile(__METHOD__); if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
stopProfile(__METHOD__);
}
return $container; return $container;
} }
@ -204,10 +207,14 @@ class d3DicHandler implements d3DicHandlerInterface
/** /**
* clone * clone
*/ */
public function __clone() {} public function __clone()
{
}
/** /**
* constructor * constructor
*/ */
public function __construct() {} public function __construct()
{
}
} }

View File

@ -20,4 +20,4 @@ use Symfony\Component\DependencyInjection\Container;
interface d3DicHandlerInterface interface d3DicHandlerInterface
{ {
public static function getInstance(): Container; public static function getInstance(): Container;
} }

View File

@ -51,6 +51,6 @@ class d3DicUtilities
*/ */
public static function getVendorDir(): string public static function getVendorDir(): string
{ {
return rtrim( dirname( __FILE__, 3 ), '/') . '/'; return rtrim(dirname(__FILE__, 3), '/') . '/';
} }
} }

View File

@ -23,11 +23,11 @@ class definitionFileContainer
public const TYPE_YAML = 'yml'; public const TYPE_YAML = 'yml';
protected array $definitionFiles = [ protected array $definitionFiles = [
self::TYPE_YAML => [] self::TYPE_YAML => [],
]; ];
protected array $allowedTypes = [ protected array $allowedTypes = [
self::TYPE_YAML self::TYPE_YAML,
]; ];
public function __construct() public function __construct()
@ -87,4 +87,4 @@ class definitionFileContainer
{ {
$this->definitionFiles = []; $this->definitionFiles = [];
} }
} }

View File

@ -267,7 +267,7 @@ class d3DicHandlerTest extends TestCase
$sut = $this->getMockBuilder(d3DicHandler::class) $sut = $this->getMockBuilder(d3DicHandler::class)
->onlyMethods(['d3GetCacheFilePath']) ->onlyMethods(['d3GetCacheFilePath'])
->getMock(); ->getMock();
$sut->method( 'd3GetCacheFilePath' )->willReturn( 'foo' ); $sut->method('d3GetCacheFilePath')->willReturn('foo');
} else { } else {
$sut = new d3DicHandler(); $sut = new d3DicHandler();
} }
@ -304,14 +304,14 @@ class d3DicHandlerTest extends TestCase
* @dataProvider buildContainerTestDataProvider * @dataProvider buildContainerTestDataProvider
* @covers \D3\DIContainerHandler\d3DicHandler::buildContainer * @covers \D3\DIContainerHandler\d3DicHandler::buildContainer
*/ */
public function buildContainerTest(bool $productive, int $debug, bool $notInTest, bool $cacheFileExist, bool $cachedContainer ): void public function buildContainerTest(bool $productive, int $debug, bool $notInTest, bool $cacheFileExist, bool $cachedContainer): void
{ {
$cachedContainerMock = $this->getMockBuilder(d3DIContainerCache::class) $cachedContainerMock = $this->getMockBuilder(d3DIContainerCache::class)
->getMock(); ->getMock();
/** @var ContainerBuilder|MockObject $containerBuilderMock */ /** @var ContainerBuilder|MockObject $containerBuilderMock */
$containerBuilderMock = $this->getMockBuilder( ContainerBuilder::class )->onlyMethods( [ 'compile' ] )->getMock(); $containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)->onlyMethods([ 'compile' ])->getMock();
$containerBuilderMock->expects( $this->exactly( (int) ! $cachedContainer ) )->method( 'compile' ); $containerBuilderMock->expects($this->exactly((int) ! $cachedContainer))->method('compile');
/** @var Config|MockObject $configMock */ /** @var Config|MockObject $configMock */
$configMock = $this->getMockBuilder(Config::class) $configMock = $this->getMockBuilder(Config::class)
@ -327,8 +327,8 @@ class d3DicHandlerTest extends TestCase
$sut->method('d3GetConfig')->willReturn($configMock); $sut->method('d3GetConfig')->willReturn($configMock);
$sut->expects($this->exactly((int) $cachedContainer))->method('d3GetCacheContainer')->willReturn($cachedContainerMock); $sut->expects($this->exactly((int) $cachedContainer))->method('d3GetCacheContainer')->willReturn($cachedContainerMock);
$sut->expects($this->exactly((int) !$cachedContainer))->method('getContainerBuilder')->willReturn($containerBuilderMock); $sut->expects($this->exactly((int) !$cachedContainer))->method('getContainerBuilder')->willReturn($containerBuilderMock);
$sut->method('isNotInTest')->willReturn( $notInTest); $sut->method('isNotInTest')->willReturn($notInTest);
$sut->method('cacheFileExists')->willReturn( $cacheFileExist); $sut->method('cacheFileExists')->willReturn($cacheFileExist);
$this->assertSame( $this->assertSame(
$cachedContainer ? $cachedContainerMock : $containerBuilderMock, $cachedContainer ? $cachedContainerMock : $containerBuilderMock,