Skip to content

Commit

Permalink
improve assert
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 21, 2025
1 parent ed0f961 commit 275a5a3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 33 deletions.
91 changes: 62 additions & 29 deletions src/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class Dependencies implements DependenciesInterface
/**
* @var array<string, string>
*/
private array $definedAt = [];
private array $requirer = [];

/**
* [<string>className => ParametersInterface,]
Expand Down Expand Up @@ -95,55 +95,84 @@ public function extract(string $className, array $container): array
return (new Arguments($parameters, $extracted))->toArray();
}

public function assert(array $container): void
public function assert(mixed ...$argument): void
{
$errors = [];
foreach ($container as $key => $value) {
foreach ($this->parameters as $key => $parameter) {
$key = (string) $key;
if (! $this->parameters->has($key)) {
$hasArgument = array_key_exists($key, $argument);
if (! $hasArgument
&& $this->parameters->optionalKeys()->contains($key)
) {
continue;
}
$requirer = $this->requirer($key);
$reflector = new ReflectionMethod($requirer, '__construct');
$fileLine = $reflector->getFileName() . ':' . $reflector->getStartLine();
if (! $hasArgument) {
$errors[] = (string) message(
<<<PLAIN
Missing argument `%key%` as previously defined by `%requirer%` in %fileLine%
PLAIN,
key: $key,
requirer: $requirer,
fileLine: $fileLine,
);

continue;
}
$parameter = $this->parameters->get($key);

try {
/** @var mixed $value */
$value = $argument[$key];
// @phpstan-ignore-next-line
$parameter($value);
} catch (Throwable) {
$type = getType($value);
if (is_object($value)) {
$type = get_class($value);
}
$definedAt = $this->definedAt($key);
$reflector = new ReflectionMethod($definedAt, '__construct');
$errors[] = (string) message(
<<<PLAIN
Argument `{$key}` provided as `%provided%` is not compatible with `%expected%` as previously defined at `%definedAt%` in %fileLine%
Argument `{$key}` provided as `%provided%` is not compatible with `%expected%` as previously defined by `%requirer%` in %fileLine%
PLAIN,
provided: $type,
expected: $parameter->type()->typeHinting(),
definedAt: $definedAt,
fileLine: $reflector->getFileName() . ':' . $reflector->getStartLine(),
requirer: $requirer,
fileLine: $fileLine,
);
}
}
if ($errors !== []) {
throw new LogicException(
implode("\n\n", array_map(
fn ($i, $error) => '[' . ($i + 1) . '] ' . $error,
array_keys($errors),
$errors
))
);
$message = $this->errorMessage($errors);

throw new LogicException($message);
}
}

public function requirer(string $name): string
{
if (array_key_exists($name, $this->requirer)) {
return $this->requirer[$name];
}

throw new OutOfBoundsException(
"Dependency `\${$name}` not defined"
);
}

public function definedAt(string $name): string
/**
* @param array<string> $errors
*/
private function errorMessage(array $errors): string
{
return array_key_exists($name, $this->definedAt)
? $this->definedAt[$name]
: throw new OutOfBoundsException(
"Dependency `\${$name}` not defined"
);
return count($errors) === 1

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 2 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "Identical": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) !== 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "Ternary": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)) : $errors[0]; } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 2 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "Identical": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) !== 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "Ternary": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)) : $errors[0]; } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 2 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "Identical": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) !== 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "Ternary": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)) : $errors[0]; } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "Identical": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) !== 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 2 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 169 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "Ternary": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)) : $errors[0]; } private function addRoute(RouteInterface $route): void {
? $errors[0]
: implode("\n\n", array_map(

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_keys($errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", $errors); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_keys($errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", $errors); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", $errors); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_keys($errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_keys($errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 171 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", $errors); } private function addRoute(RouteInterface $route): void {
fn ($i, $error) => '- [' . ($i + 1) . '] ' . $error,

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "DecrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 0) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 2) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-24.04

Escaped Mutant for Mutator "Plus": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i - 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "DecrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 0) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 2) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-24.04

Escaped Mutant for Mutator "Plus": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i - 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "DecrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 0) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 2) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-24.04

Escaped Mutant for Mutator "Plus": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i - 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "DecrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 0) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "IncrementInteger": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 2) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {

Check warning on line 172 in src/Dependencies.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-24.04

Escaped Mutant for Mutator "Plus": @@ @@ */ private function errorMessage(array $errors): string { - return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i + 1) . '] ' . $error, array_keys($errors), $errors)); + return count($errors) === 1 ? $errors[0] : implode("\n\n", array_map(fn($i, $error) => '- [' . ($i - 1) . '] ' . $error, array_keys($errors), $errors)); } private function addRoute(RouteInterface $route): void {
array_keys($errors),
$errors
));
}

private function addRoute(RouteInterface $route): void
Expand All @@ -166,6 +195,7 @@ private function setMiddleware(EndpointInterface $endpoint): void

private function handleParameters(string $className): void
{
$errors = [];
if (! method_exists($className, '__construct')) {
return;
}
Expand All @@ -183,17 +213,20 @@ private function handleParameters(string $className): void
try {
$existing->assertCompatible($parameter);
} catch (Throwable $e) {
throw new TypeError(
<<<PLAIN
Incompatible dependency type for variable `\${$name}` at `{$className}::__construct` previously defined as type `{$existing->type()->typeHinting()}`
PLAIN
);
$errors[] = <<<PLAIN
Incompatible dependency type for variable `\${$name}` at `{$className}::__construct` previously defined as type `{$existing->type()->typeHinting()}`
PLAIN;
}
$parameters = $parameters->without($name);
}
if ($errors !== []) {
$message = $this->errorMessage($errors);

throw new TypeError($message);
}
$this->parameters = $this->parameters->withMerge($parameters);
foreach ($parameters->keys() as $key) {
$this->definedAt[$key] = $className;
$this->requirer[$key] = $className;
}
}
}
9 changes: 5 additions & 4 deletions src/Interfaces/DependenciesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public function get(string $className): ParametersInterface;
*/
public function extract(string $className, array $container): array;

public function definedAt(string $name): string;
/**
* Indicates the class name which declared the given dependency.
*/
public function requirer(string $name): string;

/**
* Asserts that the given container has all dependencies.
*
* @param array<string, mixed> $container Service container
*/
public function assert(array $container): void;
public function assert(mixed ...$container): void;
}

0 comments on commit 275a5a3

Please sign in to comment.