Skip to content

Commit

Permalink
Update Container.php
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Feb 6, 2024
1 parent d699d8e commit 10aceb7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,33 +247,33 @@ public function bind(
*/
public function build(string $service, array $arguments = []): object
{
$class = $this->resolve($service);

if (is_a($service, ContainerInterface::class, true)) {
return $this;
}

$service = $this->resolve($service);

if (array_key_exists($service, $this->dependencies)) {
if (array_key_exists($class, $this->dependencies)) {
throw new CircularDependencyException(sprintf(
'Class: %s -> %s',
implode(' -> ', array_keys($this->dependencies)),
$service
$class
));
}

$this->dependencies[$service] = true;
$this->dependencies[$class] = true;

Check warning on line 264 in src/Container.php

View workflow job for this annotation

GitHub Actions / automation / Infection on ubuntu with PHP 8.3 and Composer locked

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ if (array_key_exists($class, $this->dependencies)) { throw new CircularDependencyException(sprintf('Class: %s -> %s', implode(' -> ', array_keys($this->dependencies)), $class)); } - $this->dependencies[$class] = true; + $this->dependencies[$class] = false; /** @var TService $instance */ $instance = $this->instantiator->instantiate($class, $arguments); $this->instances[$class] = $instance;

/** @var TService $instance */
$instance = $this->instantiator->instantiate($service, $arguments);
$instance = $this->instantiator->instantiate($class, $arguments);

$this->instances[$service] = $instance;
$this->instances[$class] = $instance;

if (array_key_exists($service, $this->dependencies)) {
unset($this->dependencies[$service]);
if (array_key_exists($class, $this->dependencies)) {
unset($this->dependencies[$class]);
}

foreach (array_keys($this->extensions) as $serviceName) {
if ($serviceName !== $service || ! is_a($instance, $serviceName, true)) {
if ($serviceName !== $class || ! is_a($instance, $serviceName, true)) {

Check warning on line 276 in src/Container.php

View workflow job for this annotation

GitHub Actions / automation / Infection on ubuntu with PHP 8.3 and Composer locked

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ unset($this->dependencies[$class]); } foreach (array_keys($this->extensions) as $serviceName) { - if ($serviceName !== $class || !is_a($instance, $serviceName, true)) { + if ($serviceName !== $class && !is_a($instance, $serviceName, true)) { continue; } foreach ($this->extensions[$serviceName] ?? [] as $extension) {
continue;

Check warning on line 277 in src/Container.php

View workflow job for this annotation

GitHub Actions / automation / Infection on ubuntu with PHP 8.3 and Composer locked

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ } foreach (array_keys($this->extensions) as $serviceName) { if ($serviceName !== $class || !is_a($instance, $serviceName, true)) { - continue; + break; } foreach ($this->extensions[$serviceName] ?? [] as $extension) { $instance = $this->invoke($extension, [$this, $instance]);
}

Expand All @@ -282,7 +282,7 @@ public function build(string $service, array $arguments = []): object
}
}

return $this->instances[$service] = $instance;
return $this->instances[$class] = $instance;
}

/**
Expand Down

0 comments on commit 10aceb7

Please sign in to comment.