Skip to content

Commit 9565511

Browse files
authored
Merge pull request #16 from jnamenyi/master
Fix deprecation warnings on PHP 8.2
2 parents 87068b1 + 535428d commit 9565511

6 files changed

+19
-15
lines changed

src/AbstractCompiledContainer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Closure;
88
use Psr\Container\ContainerInterface;
99

10+
use function property_exists;
11+
1012
abstract class AbstractCompiledContainer implements ContainerInterface
1113
{
1214
/** @var array<string, object> */
@@ -18,7 +20,9 @@ protected function setClassProperties(object $object, array $properties): object
1820
Closure::bind(
1921
static function () use ($object, $properties): void {
2022
foreach ($properties as $name => $value) {
21-
$object->$name = $value;
23+
if (property_exists($object, $name)) {
24+
$object->$name = $value;
25+
}
2226
}
2327
},
2428
null,

src/Container/Definition/ClassDefinition.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function compile(
247247
$code = "";
248248

249249
if ($inline === false) {
250-
$code .= "${indent}return ";
250+
$code .= "{$indent}return ";
251251
}
252252

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

257257
if ($hasProperties) {
258258
$code .= "\$this->setClassProperties(\n";
259-
$code .= "${indent}${tab}";
259+
$code .= "{$indent}{$tab}";
260260
}
261261

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

274-
$code .= "\n${constructorIndent}${tab}" . $this->compileEntryReference(
274+
$code .= "\n{$constructorIndent}{$tab}" . $this->compileEntryReference(
275275
$definition,
276276
$compilation,
277277
$constructorIndentationLevel + 1,
278278
$preloadedClasses
279279
) . ",";
280280
} elseif (array_key_exists("value", $constructorArgument)) {
281-
$code .= "\n${constructorIndent}${tab}" . $this->serializeValue($constructorArgument["value"]) . ",";
281+
$code .= "\n{$constructorIndent}{$tab}" . $this->serializeValue($constructorArgument["value"]) . ",";
282282
}
283283
}
284284

285285
if ($hasConstructorArguments) {
286-
$code .= "\n${constructorIndent})";
286+
$code .= "\n{$constructorIndent})";
287287
}
288288

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

296-
$code .= "${indent}${tab}${tab}'$propertyName' => " . $this->compileEntryReference(
296+
$code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->compileEntryReference(
297297
$definition,
298298
$compilation,
299299
$indentationLevel + 2,
300300
$preloadedClasses
301301
) . ",\n";
302302
} elseif (array_key_exists("value", $property)) {
303-
$code .= "${indent}${tab}${tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n";
303+
$code .= "{$indent}{$tab}{$tab}'$propertyName' => " . $this->serializeValue($property["value"]) . ",\n";
304304
}
305305
}
306-
$code .= "${indent}${tab}]\n";
307-
$code .= "${indent})";
306+
$code .= "{$indent}{$tab}]\n";
307+
$code .= "{$indent})";
308308
}
309309

310310
if ($inline === false) {

src/Container/Definition/ReferenceDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function compile(
131131
$code = "";
132132

133133
if ($inline === false) {
134-
$code .= "${indent}return ";
134+
$code .= "{$indent}return ";
135135
}
136136

137137
if ($this->isSingletonCheckEliminable($parentId) === false) {

src/Container/Definition/SelfDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public function compile(
6767
return "\$this";
6868
}
6969

70-
return "${indent}return \$this;\n";
70+
return "{$indent}return \$this;\n";
7171
}
7272
}

tests/Double/StubPrototypeDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function compile(
2525
): string {
2626
$indent = $this->indent($indentationLevel);
2727

28-
return "${indent}// This is a dummy definition.\n";
28+
return "{$indent}// This is a dummy definition.\n";
2929
}
3030
}

tests/Double/StubSingletonDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function compile(
3838
): string {
3939
$indent = $this->indent($indentationLevel);
4040

41-
return "${indent}// This is a dummy definition.\n";
41+
return "{$indent}// This is a dummy definition.\n";
4242
}
4343
}

0 commit comments

Comments
 (0)