From a1be5e79dbbb5228f180d3856f32e568d56af573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 01:48:59 +0000 Subject: [PATCH 1/7] Obey EC rules --- .editorconfig | 5 ++++- README.md | 6 +++--- SUPPORT.md | 2 +- phpstan.neon | 12 ++++++------ ...DefinitionWithOptionalConstructorDependencies.php | 4 ++-- ...finitionWithOverriddenConstructorDependencies.php | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.editorconfig b/.editorconfig index 01bb1b3..4116cbf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,12 @@ indent_size = 4 indent_style = space insert_final_newline = true trim_trailing_whitespace = true +eclint_block_comment_start = /* +eclint_block_comment = * +eclint_block_comment_end = */ [Makefile] indent_style = tab -[*.yml] +[{*.yml,*.xml,*.xml.dist}] indent_size = 2 diff --git a/README.md b/README.md index b8bd4bd..4050ca9 100644 --- a/README.md +++ b/README.md @@ -141,9 +141,9 @@ $container = new Container(); In case of very big projects, you might run out of memory when building the container. You can circumvent this issue by manually setting the memory limit: - ```bash - ./vendor/bin/zen --memory-limit="128M" build /var/www/app/Container/Container.php "App\\Container\\CompilerConfig" - ``` +```bash +./vendor/bin/zen --memory-limit="128M" build /var/www/app/Container/Container.php "App\\Container\\CompilerConfig" +``` Besides via the CLI, you can also build the Container via PHP itself: diff --git a/SUPPORT.md b/SUPPORT.md index 3bdbad2..5a0eb61 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -1,3 +1,3 @@ # Support -If you need support, please ask your questions on [Gitter](https://gitter.im/woohoolabs/yang). +If you need support, please ask your questions on [Gitter](https://gitter.im/woohoolabs/yang). diff --git a/phpstan.neon b/phpstan.neon index dd2eda7..7333d43 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,14 +8,14 @@ parameters: message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#' path: src/Config/AbstractContainerConfig.php - - message: '#^Unreachable statement - code above always terminates\.$#' - path: src/Config/AbstractContainerConfig.php + message: '#^Unreachable statement - code above always terminates\.$#' + path: src/Config/AbstractContainerConfig.php - - message: '#^Property WoohooLabs\\Zen\\Container\\ContainerDependencyResolver::\$excludedFileBasedDefinitions \(array\\) does not accept array\\.$#' - path: src/Container/ContainerDependencyResolver.php + message: '#^Property WoohooLabs\\Zen\\Container\\ContainerDependencyResolver::\$excludedFileBasedDefinitions \(array\\) does not accept array\\.$#' + path: src/Container/ContainerDependencyResolver.php - - message: '#^Parameter \#2 \$array of function implode expects array\, array\\|bool\|float\|int\|string\|null\> given\.$#' - path: src/Container/ContainerDependencyResolver.php + message: '#^Parameter \#2 \$array of function implode expects array\, array\\|bool\|float\|int\|string\|null\> given\.$#' + path: src/Container/ContainerDependencyResolver.php checkGenericClassInNonGenericObjectType: false includes: diff --git a/tests/Fixture/Definition/ClassDefinitionWithOptionalConstructorDependencies.php b/tests/Fixture/Definition/ClassDefinitionWithOptionalConstructorDependencies.php index e5bfcd4..078da94 100644 --- a/tests/Fixture/Definition/ClassDefinitionWithOptionalConstructorDependencies.php +++ b/tests/Fixture/Definition/ClassDefinitionWithOptionalConstructorDependencies.php @@ -7,6 +7,6 @@ 1345.999, NULL, array ( - 'a' => false, -), + 'a' => false, + ), ); diff --git a/tests/Fixture/Definition/ClassDefinitionWithOverriddenConstructorDependencies.php b/tests/Fixture/Definition/ClassDefinitionWithOverriddenConstructorDependencies.php index a20c647..aeaa794 100644 --- a/tests/Fixture/Definition/ClassDefinitionWithOverriddenConstructorDependencies.php +++ b/tests/Fixture/Definition/ClassDefinitionWithOverriddenConstructorDependencies.php @@ -4,6 +4,6 @@ NULL, 0, array ( - 'a' => false, -), + 'a' => false, + ), ); From 1ee33c8b92a3c15366fe740be0e371740f7ed295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 02:31:32 +0000 Subject: [PATCH 2/7] Indent var_export's output with 4 spaces --- src/Container/Definition/AbstractDefinition.php | 11 +++++++++++ src/Container/Definition/ClassDefinition.php | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Container/Definition/AbstractDefinition.php b/src/Container/Definition/AbstractDefinition.php index 4d47cfa..ab2ee73 100644 --- a/src/Container/Definition/AbstractDefinition.php +++ b/src/Container/Definition/AbstractDefinition.php @@ -177,6 +177,17 @@ protected function indent(int $indentationLevel): string return str_repeat(" ", $indentationLevel * 4); } + protected function indentLines(string $indentation, string $lines): string + { + return array_reduce( + explode("\n", $lines), + static function($output, $line) use ($indentation) { + return $output . "\n" . $indentation.$line; + }, + "" + ); + } + /** * @param array $relatedClasses */ diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index a08e3d9..a500ac7 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -271,14 +271,17 @@ public function compile( if (array_key_exists("class", $constructorArgument)) { $definition = $compilation->getDefinition($constructorArgument["class"]); - $code .= "\n{$constructorIndent}{$tab}" . $this->compileEntryReference( + $code .= $this->indentLines("{$constructorIndent}{$tab}", $this->compileEntryReference( $definition, $compilation, $constructorIndentationLevel + 1, $preloadedClasses - ) . ","; + )) . ","; } elseif (array_key_exists("value", $constructorArgument)) { - $code .= "\n{$constructorIndent}{$tab}" . $this->serializeValue($constructorArgument["value"]) . ","; + $code .= $this->indentLines( + "{$constructorIndent}{$tab}", + $this->serializeValue($constructorArgument["value"]) + ) . ","; } } @@ -350,6 +353,6 @@ static function () use ($instantiation, $className, $object, $properties): void private function serializeValue(mixed $value): string { - return var_export($value, true); + return preg_replace("/^( +)/m", "$1$1", var_export($value, true)); } } From bebd1aa6883fe923fb270fcb4b2d4ff5cfdfc0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 02:32:39 +0000 Subject: [PATCH 3/7] Fix CS --- src/Container/Definition/AbstractDefinition.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Container/Definition/AbstractDefinition.php b/src/Container/Definition/AbstractDefinition.php index ab2ee73..d8be2fc 100644 --- a/src/Container/Definition/AbstractDefinition.php +++ b/src/Container/Definition/AbstractDefinition.php @@ -182,7 +182,7 @@ protected function indentLines(string $indentation, string $lines): string return array_reduce( explode("\n", $lines), static function($output, $line) use ($indentation) { - return $output . "\n" . $indentation.$line; + return $output . "\n" . $indentation . $line; }, "" ); From 5e425a20636d123a227f11e4d7776493f726b3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 02:34:59 +0000 Subject: [PATCH 4/7] Fix CS --- src/Container/Definition/AbstractDefinition.php | 2 ++ src/Container/Definition/ClassDefinition.php | 1 + 2 files changed, 3 insertions(+) diff --git a/src/Container/Definition/AbstractDefinition.php b/src/Container/Definition/AbstractDefinition.php index d8be2fc..d79ea8a 100644 --- a/src/Container/Definition/AbstractDefinition.php +++ b/src/Container/Definition/AbstractDefinition.php @@ -10,6 +10,8 @@ use WoohooLabs\Zen\Container\DefinitionCompilation; use function array_key_exists; +use function array_reduce; +use function explode; use function str_repeat; use function str_replace; diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index a500ac7..14d7306 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -10,6 +10,7 @@ use function array_key_exists; use function array_keys; +use function preg_replace; use function var_export; class ClassDefinition extends AbstractDefinition From a4b6f2925a805f42f322febcacfa2acf2a8aa66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 02:37:52 +0000 Subject: [PATCH 5/7] Fix CS --- src/Container/Definition/AbstractDefinition.php | 2 +- src/Container/Definition/ClassDefinition.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Container/Definition/AbstractDefinition.php b/src/Container/Definition/AbstractDefinition.php index d79ea8a..9dbb4fd 100644 --- a/src/Container/Definition/AbstractDefinition.php +++ b/src/Container/Definition/AbstractDefinition.php @@ -183,7 +183,7 @@ protected function indentLines(string $indentation, string $lines): string { return array_reduce( explode("\n", $lines), - static function($output, $line) use ($indentation) { + static function ($output, $line) use ($indentation) { return $output . "\n" . $indentation . $line; }, "" diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index 14d7306..450e073 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -280,9 +280,9 @@ public function compile( )) . ","; } elseif (array_key_exists("value", $constructorArgument)) { $code .= $this->indentLines( - "{$constructorIndent}{$tab}", - $this->serializeValue($constructorArgument["value"]) - ) . ","; + "{$constructorIndent}{$tab}", + $this->serializeValue($constructorArgument["value"]) + ) . ","; } } @@ -354,6 +354,6 @@ static function () use ($instantiation, $className, $object, $properties): void private function serializeValue(mixed $value): string { - return preg_replace("/^( +)/m", "$1$1", var_export($value, true)); + return (string)preg_replace("/^( +)/m", "$1$1", var_export($value, true)); } } From d21ef5f41550239b459e8fcf8d253efbf4c6eabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sun, 20 Aug 2023 02:39:17 +0000 Subject: [PATCH 6/7] Fix CS --- src/Container/Definition/ClassDefinition.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index 450e073..eec9924 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -354,6 +354,6 @@ static function () use ($instantiation, $className, $object, $properties): void private function serializeValue(mixed $value): string { - return (string)preg_replace("/^( +)/m", "$1$1", var_export($value, true)); + return (string) preg_replace("/^( +)/m", "$1$1", var_export($value, true)); } } From 47c1a2cf439ebc7c79e214b23178337180b222a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 9 Oct 2023 08:56:39 +0000 Subject: [PATCH 7/7] Fix PlantService indentation --- src/Container/Definition/ClassDefinition.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Container/Definition/ClassDefinition.php b/src/Container/Definition/ClassDefinition.php index eec9924..045e641 100644 --- a/src/Container/Definition/ClassDefinition.php +++ b/src/Container/Definition/ClassDefinition.php @@ -275,7 +275,7 @@ public function compile( $code .= $this->indentLines("{$constructorIndent}{$tab}", $this->compileEntryReference( $definition, $compilation, - $constructorIndentationLevel + 1, + 0, $preloadedClasses )) . ","; } elseif (array_key_exists("value", $constructorArgument)) {