From b58f1b41566ca71c2a2d9736ffdf09af77fc0b83 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 31 Jan 2024 21:17:51 +0100 Subject: [PATCH] improve code style --- composer.json | 5 ++++- d3DicHandler.php | 33 ++++++++++++++++++++------------- d3DicHandlerInterface.php | 2 +- d3DicUtilities.php | 2 +- definitionFileContainer.php | 6 +++--- tests/unit/d3DicHandlerTest.php | 12 ++++++------ 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 8fc5224..1ed2449 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ }, "require-dev": { "d3/testingtools": "^1.0", - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6", + "friendsofphp/php-cs-fixer": "~3.13.0" }, "autoload": { "psr-4": { @@ -38,6 +39,8 @@ ] }, "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/" } } diff --git a/d3DicHandler.php b/d3DicHandler.php index 2107029..da29fa8 100644 --- a/d3DicHandler.php +++ b/d3DicHandler.php @@ -31,7 +31,7 @@ class d3DicHandler implements d3DicHandlerInterface protected static Container|null $_instance = null; public static array $circularReferenceMethodNames = [ - 'getViewConfig' + 'getViewConfig', ]; /** @@ -46,8 +46,7 @@ class d3DicHandler implements d3DicHandlerInterface $caller = $trace[1]; $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"); } @@ -71,8 +70,7 @@ class d3DicHandler implements d3DicHandlerInterface $caller = $trace[1]; $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"); } @@ -117,7 +115,8 @@ class d3DicHandler implements d3DicHandlerInterface public function d3GetFileLoader(ContainerBuilder $container): YamlFileLoader { /** @var YamlFileLoader $fileLoader */ - $fileLoader = oxNew(YamlFileLoader::class, + $fileLoader = oxNew( + YamlFileLoader::class, $container, oxNew(FileLocator::class, d3DicUtilities::getVendorDir()) ); @@ -167,12 +166,14 @@ class d3DicHandler implements d3DicHandlerInterface */ 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(); - if ( $config->isProductiveMode() - && ! $config->getConfigParam( 'iDebug' ) + if ($config->isProductiveMode() + && ! $config->getConfigParam('iDebug') && $this->isNotInTest() && $this->cacheFileExists() ) { @@ -186,12 +187,14 @@ class d3DicHandler implements d3DicHandlerInterface if ($this->isNotInTest()) { $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; } @@ -204,10 +207,14 @@ class d3DicHandler implements d3DicHandlerInterface /** * clone */ - public function __clone() {} + public function __clone() + { + } /** * constructor */ - public function __construct() {} + public function __construct() + { + } } diff --git a/d3DicHandlerInterface.php b/d3DicHandlerInterface.php index 25b5931..9338b5e 100644 --- a/d3DicHandlerInterface.php +++ b/d3DicHandlerInterface.php @@ -20,4 +20,4 @@ use Symfony\Component\DependencyInjection\Container; interface d3DicHandlerInterface { public static function getInstance(): Container; -} \ No newline at end of file +} diff --git a/d3DicUtilities.php b/d3DicUtilities.php index 96330dd..d3e3884 100644 --- a/d3DicUtilities.php +++ b/d3DicUtilities.php @@ -51,6 +51,6 @@ class d3DicUtilities */ public static function getVendorDir(): string { - return rtrim( dirname( __FILE__, 3 ), '/') . '/'; + return rtrim(dirname(__FILE__, 3), '/') . '/'; } } diff --git a/definitionFileContainer.php b/definitionFileContainer.php index 201f5f6..12fd37a 100644 --- a/definitionFileContainer.php +++ b/definitionFileContainer.php @@ -23,11 +23,11 @@ class definitionFileContainer public const TYPE_YAML = 'yml'; protected array $definitionFiles = [ - self::TYPE_YAML => [] + self::TYPE_YAML => [], ]; protected array $allowedTypes = [ - self::TYPE_YAML + self::TYPE_YAML, ]; public function __construct() @@ -87,4 +87,4 @@ class definitionFileContainer { $this->definitionFiles = []; } -} \ No newline at end of file +} diff --git a/tests/unit/d3DicHandlerTest.php b/tests/unit/d3DicHandlerTest.php index 9a5989e..b44795a 100644 --- a/tests/unit/d3DicHandlerTest.php +++ b/tests/unit/d3DicHandlerTest.php @@ -267,7 +267,7 @@ class d3DicHandlerTest extends TestCase $sut = $this->getMockBuilder(d3DicHandler::class) ->onlyMethods(['d3GetCacheFilePath']) ->getMock(); - $sut->method( 'd3GetCacheFilePath' )->willReturn( 'foo' ); + $sut->method('d3GetCacheFilePath')->willReturn('foo'); } else { $sut = new d3DicHandler(); } @@ -304,14 +304,14 @@ class d3DicHandlerTest extends TestCase * @dataProvider buildContainerTestDataProvider * @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) ->getMock(); /** @var ContainerBuilder|MockObject $containerBuilderMock */ - $containerBuilderMock = $this->getMockBuilder( ContainerBuilder::class )->onlyMethods( [ 'compile' ] )->getMock(); - $containerBuilderMock->expects( $this->exactly( (int) ! $cachedContainer ) )->method( 'compile' ); + $containerBuilderMock = $this->getMockBuilder(ContainerBuilder::class)->onlyMethods([ 'compile' ])->getMock(); + $containerBuilderMock->expects($this->exactly((int) ! $cachedContainer))->method('compile'); /** @var Config|MockObject $configMock */ $configMock = $this->getMockBuilder(Config::class) @@ -327,8 +327,8 @@ class d3DicHandlerTest extends TestCase $sut->method('d3GetConfig')->willReturn($configMock); $sut->expects($this->exactly((int) $cachedContainer))->method('d3GetCacheContainer')->willReturn($cachedContainerMock); $sut->expects($this->exactly((int) !$cachedContainer))->method('getContainerBuilder')->willReturn($containerBuilderMock); - $sut->method('isNotInTest')->willReturn( $notInTest); - $sut->method('cacheFileExists')->willReturn( $cacheFileExist); + $sut->method('isNotInTest')->willReturn($notInTest); + $sut->method('cacheFileExists')->willReturn($cacheFileExist); $this->assertSame( $cachedContainer ? $cachedContainerMock : $containerBuilderMock,