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

Commit f3c7c65

Browse files
committed
Fixed wrong use of array_key_exists with ArrayObject
1 parent e42f0f3 commit f3c7c65

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ parameters:
1515
- "#Casting to [a-z]+ something that's already [a-z]+#"
1616
- '#PHPDoc tag @throws with type Interop\\Container\\Exception\\ContainerException is not subtype of Throwable#'
1717
- '#PHPDoc tag @throws with type ([\w\\\|]+\|)?Psr\\Container\\ContainerExceptionInterface(\|[\w\\\|]+)? is not subtype of Throwable#'
18-
- '#Parameter \#2 \$search of function array_key_exists expects array, (array\|)?ArrayObject given#'
1918
# AbstractPluginManager::__construct() accepts more types:
2019
- '#Result of && is always false#'

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ final class ConfigAbstractFactory implements AbstractFactoryInterface
2626
*/
2727
public function canCreate(\Psr\Container\ContainerInterface $container, $requestedName)
2828
{
29-
if (! $container->has('config') || ! array_key_exists(self::class, $container->get('config'))) {
29+
if (! $container->has('config')) {
3030
return false;
3131
}
32+
3233
$config = $container->get('config');
34+
35+
if (! isset($config[self::class])) {
36+
return false;
37+
}
38+
3339
$dependencies = $config[self::class];
3440

3541
return is_array($dependencies) && array_key_exists($requestedName, $dependencies);
@@ -50,7 +56,7 @@ public function __invoke(\Psr\Container\ContainerInterface $container, $requeste
5056
throw new ServiceNotCreatedException('Config must be an array or an instance of ArrayObject');
5157
}
5258

53-
if (! array_key_exists(self::class, $config)) {
59+
if (! isset($config[self::class])) {
5460
throw new ServiceNotCreatedException('Cannot find a `' . self::class . '` key in the config array');
5561
}
5662

0 commit comments

Comments
 (0)