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": {
"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/"
}
}

View File

@ -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()
{
}
}

View File

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

View File

@ -51,6 +51,6 @@ class d3DicUtilities
*/
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';
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 = [];
}
}
}

View File

@ -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,