Skip to content

Commit cc74385

Browse files
[DI] Improve error message in LazyClosure when no "id" is provided
1 parent dd1db43 commit cc74385

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Argument/LazyClosure.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ public static function getCode(string $initializer, array $callable, Definition
6060

6161
$r = $container->getReflectionClass($class);
6262

63+
if (null !== $id) {
64+
$id = sprintf(' for service "%s"', $id);
65+
}
66+
6367
if (!$asClosure) {
68+
$id = str_replace('%', '%%', (string) $id);
69+
6470
if (!$r || !$r->isInterface()) {
65-
throw new RuntimeException(sprintf('Cannot create adapter for service "%s" because "%s" is not an interface.', $id, $class));
71+
throw new RuntimeException(sprintf("Cannot create adapter{$id} because \"%s\" is not an interface.", $class));
6672
}
6773
if (1 !== \count($method = $r->getMethods())) {
68-
throw new RuntimeException(sprintf('Cannot create adapter for service "%s" because interface "%s" doesn\'t have exactly one method.', $id, $class));
74+
throw new RuntimeException(sprintf("Cannot create adapter{$id} because interface \"%s\" doesn't have exactly one method.", $class));
6975
}
7076
$method = $method[0]->name;
7177
} elseif (!$r || !$r->hasMethod($method)) {
72-
throw new RuntimeException(sprintf('Cannot create lazy closure for service "%s" because its corresponding callable is invalid.', $id));
78+
throw new RuntimeException("Cannot create lazy closure{$id} because its corresponding callable is invalid.");
7379
}
7480

7581
$code = ProxyHelper::exportSignature($r->getMethod($method), true, $args);

0 commit comments

Comments
 (0)