Skip to content

Commit

Permalink
Merge pull request #16 from jnamenyi/master
Browse files Browse the repository at this point in the history
Fix deprecation warnings on PHP 8.2
  • Loading branch information
kocsismate authored Aug 19, 2023
2 parents 87068b1 + 535428d commit 9565511
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/AbstractCompiledContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Closure;
use Psr\Container\ContainerInterface;

use function property_exists;

abstract class AbstractCompiledContainer implements ContainerInterface
{
/** @var array<string, object> */
Expand All @@ -18,7 +20,9 @@ protected function setClassProperties(object $object, array $properties): object
Closure::bind(
static function () use ($object, $properties): void {
foreach ($properties as $name => $value) {
$object->$name = $value;
if (property_exists($object, $name)) {
$object->$name = $value;
}
}
},
null,
Expand Down
20 changes: 10 additions & 10 deletions src/Container/Definition/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function compile(
$code = "";

if ($inline === false) {
$code .= "${indent}return ";
$code .= "{$indent}return ";
}

if ($this->isSingletonCheckEliminable($parentId) === false) {
Expand All @@ -256,7 +256,7 @@ public function compile(

if ($hasProperties) {
$code .= "\$this->setClassProperties(\n";
$code .= "${indent}${tab}";
$code .= "{$indent}{$tab}";
}

$code .= "new \\" . $this->getClassName() . "(";
Expand All @@ -271,40 +271,40 @@ public function compile(
if (array_key_exists("class", $constructorArgument)) {
$definition = $compilation->getDefinition($constructorArgument["class"]);

$code .= "\n${constructorIndent}${tab}" . $this->compileEntryReference(
$code .= "\n{$constructorIndent}{$tab}" . $this->compileEntryReference(
$definition,
$compilation,
$constructorIndentationLevel + 1,
$preloadedClasses
) . ",";
} elseif (array_key_exists("value", $constructorArgument)) {
$code .= "\n${constructorIndent}${tab}" . $this->serializeValue($constructorArgument["value"]) . ",";
$code .= "\n{$constructorIndent}{$tab}" . $this->serializeValue($constructorArgument["value"]) . ",";
}
}

if ($hasConstructorArguments) {
$code .= "\n${constructorIndent})";
$code .= "\n{$constructorIndent})";
}

if ($hasProperties) {
$code .= ",\n";
$code .= "${indent}${tab}[\n";
$code .= "{$indent}{$tab}[\n";
foreach ($this->properties as $propertyName => $property) {
if (array_key_exists("class", $property)) {
$definition = $compilation->getDefinition($property["class"]);

$code .= "${indent}${tab}${tab}'$propertyName' => " . $this->compileEntryReference(
$code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->compileEntryReference(
$definition,
$compilation,
$indentationLevel + 2,
$preloadedClasses
) . ",\n";
} elseif (array_key_exists("value", $property)) {
$code .= "${indent}${tab}${tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n";
$code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n";
}
}
$code .= "${indent}${tab}]\n";
$code .= "${indent})";
$code .= "{$indent}{$tab}]\n";
$code .= "{$indent})";
}

if ($inline === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Definition/ReferenceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function compile(
$code = "";

if ($inline === false) {
$code .= "${indent}return ";
$code .= "{$indent}return ";
}

if ($this->isSingletonCheckEliminable($parentId) === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Definition/SelfDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public function compile(
return "\$this";
}

return "${indent}return \$this;\n";
return "{$indent}return \$this;\n";
}
}
2 changes: 1 addition & 1 deletion tests/Double/StubPrototypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function compile(
): string {
$indent = $this->indent($indentationLevel);

return "${indent}// This is a dummy definition.\n";
return "{$indent}// This is a dummy definition.\n";
}
}
2 changes: 1 addition & 1 deletion tests/Double/StubSingletonDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function compile(
): string {
$indent = $this->indent($indentationLevel);

return "${indent}// This is a dummy definition.\n";
return "{$indent}// This is a dummy definition.\n";
}
}

0 comments on commit 9565511

Please sign in to comment.