Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 2318ea3

Browse files
committed
Similified canCreate so it stops failing silently, the failure now happens in the __invoke method to ensure we dont get confused users wondering why this abstract factory isnt firing
1 parent e652ed3 commit 2318ea3

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,7 @@ public function canCreate(\Interop\Container\ContainerInterface $container, $req
2828
$config = $container->get('config');
2929
$dependencies = $config[self::class];
3030

31-
// config must be array, and have a key for the requested name that's value is also an array
32-
if (!is_array($dependencies)
33-
|| !array_key_exists($requestedName, $dependencies)
34-
|| !is_array($dependencies[$requestedName])
35-
) {
36-
return false;
37-
}
38-
39-
// we can only create this service if the config is an array of strings
40-
return $dependencies[$requestedName] === array_values(array_map('strval', $dependencies[$requestedName]));
41-
31+
return is_array($dependencies) && array_key_exists($requestedName, $dependencies);
4232
}
4333

4434
/**

test/AbstractFactory/ConfigAbstractFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class ConfigAbstractFactoryTest extends \PHPUnit_Framework_TestCase
2121
{
2222

23-
public function testCanCreateReturnsFalseIfDependencyNotArrays()
23+
public function testCanCreateReturnsTrueIfDependencyNotArrays()
2424
{
2525
$abstractFactory = new ConfigAbstractFactory();
2626
$serviceManager = new ServiceManager();
@@ -42,7 +42,7 @@ public function testCanCreateReturnsFalseIfDependencyNotArrays()
4242
]
4343
]
4444
);
45-
self::assertFalse($abstractFactory->canCreate($serviceManager, InvokableObject::class));
45+
self::assertTrue($abstractFactory->canCreate($serviceManager, InvokableObject::class));
4646

4747
$serviceManager->setAllowOverride(true);
4848
$serviceManager->setService(
@@ -58,7 +58,7 @@ public function testCanCreateReturnsFalseIfDependencyNotArrays()
5858
]
5959
]
6060
);
61-
self::assertFalse($abstractFactory->canCreate($serviceManager, InvokableObject::class));
61+
self::assertTrue($abstractFactory->canCreate($serviceManager, InvokableObject::class));
6262

6363
}
6464

0 commit comments

Comments
 (0)