Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obey EC rules #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion SUPPORT.md
Original file line number Diff line number Diff line change
@@ -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).
12 changes: 6 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\<string\>\) does not accept array\<string, int\>\.$#'
path: src/Container/ContainerDependencyResolver.php
message: '#^Property WoohooLabs\\Zen\\Container\\ContainerDependencyResolver::\$excludedFileBasedDefinitions \(array\<string\>\) does not accept array\<string, int\>\.$#'
path: src/Container/ContainerDependencyResolver.php
-
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<int\|string, mixed\>\|bool\|float\|int\|string\|null\> given\.$#'
path: src/Container/ContainerDependencyResolver.php
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<int\|string, mixed\>\|bool\|float\|int\|string\|null\> given\.$#'
path: src/Container/ContainerDependencyResolver.php
checkGenericClassInNonGenericObjectType: false

includes:
Expand Down
13 changes: 13 additions & 0 deletions src/Container/Definition/AbstractDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<string, string> $relatedClasses
*/
Expand Down
14 changes: 9 additions & 5 deletions src/Container/Definition/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you generate the example container with the make build command, you'll see that this makes the indentation of the dependencies of PlantService wrong. The rest of the changes look good though.

Copy link
Contributor Author

@szepeviktor szepeviktor Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 🍏

Is it all right now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this change is needed at all when the original indentation looked good for me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var_export has a fixed indentation of 2 spaces.
a1be5e7#diff-735c9178f83fdb6831e51d7073bcee55372c3a5c83b4bed1edf08deffb7fe774
To correct that I've added this method.

$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"])
) . ",";
}
}

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
1345.999,
NULL,
array (
'a' => false,
),
'a' => false,
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
NULL,
0,
array (
'a' => false,
),
'a' => false,
),
);