Skip to content

Commit decaf23

Browse files
Amrouche Hamzasroze
authored andcommitted
[DependencyInjection] Add more information to the message when passing miss matching class.
1 parent 7a33b01 commit decaf23

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,14 @@ private function createTypeAlternatives(TypedReference $reference)
336336
if ($message = $this->getAliasesSuggestionForType($type = $reference->getType())) {
337337
return ' '.$message;
338338
}
339-
340339
if (isset($this->ambiguousServiceTypes[$type])) {
341340
$message = sprintf('one of these existing services: "%s"', implode('", "', $this->ambiguousServiceTypes[$type]));
342341
} elseif (isset($this->types[$type])) {
343342
$message = sprintf('the existing "%s" service', $this->types[$type]);
344343
} elseif ($reference->getRequiringClass() && !$reference->canBeAutoregistered()) {
345344
return ' It cannot be auto-registered because it is from a different root namespace.';
345+
} elseif (is_array($this->types) && (null !== $key = array_search(strtolower($type), array_map('strtolower', $this->types)))) {
346+
return sprintf(' Maybe you mean %s instead of %s ?', $key, $type);
346347
} else {
347348
return;
348349
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ class Foo
66
{
77
}
88

9+
class FooFoo
10+
{
11+
public function __construct(Foo $foo)
12+
{
13+
}
14+
}
15+
916
class Bar
1017
{
1118
public function __construct(Foo $foo)
@@ -293,6 +300,17 @@ public function setChildMethodWithoutDocBlock(A $a)
293300
}
294301
}
295302

303+
class ARealClass {
304+
305+
}
306+
307+
class ClassMisMatch {
308+
309+
public function __construct(arealclass $n = null)
310+
{
311+
}
312+
}
313+
296314
class NotWireable
297315
{
298316
public function setNotAutowireable(NotARealClass $n)

0 commit comments

Comments
 (0)