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/src/Container/Definition/AbstractDefinition.php b/src/Container/Definition/AbstractDefinition.php index 4d47cfa..9dbb4fd 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; @@ -177,6 +179,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..045e641 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 @@ -271,14 +272,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, + 0, $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 +354,6 @@ static function () use ($instantiation, $className, $object, $properties): void private function serializeValue(mixed $value): string { - return var_export($value, true); + return (string) preg_replace("/^( +)/m", "$1$1", var_export($value, true)); } } 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, + ), );