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

Commit 32e8b82

Browse files
committed
Optimize more PHP function calls and issets
1 parent 152cb1e commit 32e8b82

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ final class ConfigAbstractFactory implements AbstractFactoryInterface
2121
*/
2222
public function canCreate(\Interop\Container\ContainerInterface $container, $requestedName)
2323
{
24-
if (! $container->has('config') || ! array_key_exists(self::class, $container->get('config'))) {
24+
if (! $container->has('config') || ! \array_key_exists(self::class, $container->get('config'))) {
2525
return false;
2626
}
2727
$config = $container->get('config');
2828
$dependencies = $config[self::class];
2929

30-
return is_array($dependencies) && array_key_exists($requestedName, $dependencies);
30+
return \is_array($dependencies) && \array_key_exists($requestedName, $dependencies);
3131
}
3232

3333
/**
@@ -41,31 +41,31 @@ public function __invoke(\Interop\Container\ContainerInterface $container, $requ
4141

4242
$config = $container->get('config');
4343

44-
if (! (is_array($config) || $config instanceof ArrayObject)) {
44+
if (! (\is_array($config) || $config instanceof ArrayObject)) {
4545
throw new ServiceNotCreatedException('Config must be an array or an instance of ArrayObject');
4646
}
4747

48-
if (! array_key_exists(self::class, $config)) {
48+
if (! \array_key_exists(self::class, $config)) {
4949
throw new ServiceNotCreatedException('Cannot find a `' . self::class . '` key in the config array');
5050
}
5151

5252
$dependencies = $config[self::class];
5353

54-
if (! is_array($dependencies)
55-
|| ! array_key_exists($requestedName, $dependencies)
56-
|| ! is_array($dependencies[$requestedName])
54+
if (! \is_array($dependencies)
55+
|| ! \array_key_exists($requestedName, $dependencies)
56+
|| ! \is_array($dependencies[$requestedName])
5757
) {
5858
throw new ServiceNotCreatedException('Dependencies config must exist and be an array');
5959
}
6060

6161
$serviceDependencies = $dependencies[$requestedName];
6262

63-
if ($serviceDependencies !== array_values(array_map('strval', $serviceDependencies))) {
64-
$problem = json_encode(array_map('gettype', $serviceDependencies));
63+
if ($serviceDependencies !== \array_values(\array_map('strval', $serviceDependencies))) {
64+
$problem = \json_encode(\array_map('gettype', $serviceDependencies));
6565
throw new ServiceNotCreatedException('Service message must be an array of strings, ' . $problem . ' given');
6666
}
6767

68-
$arguments = array_map([$container, 'get'], $serviceDependencies);
68+
$arguments = \array_map([$container, 'get'], $serviceDependencies);
6969

7070
return new $requestedName(...$arguments);
7171
}

src/AbstractFactory/ReflectionBasedAbstractFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private function resolveParameter(ReflectionParameter $parameter, ContainerInter
216216
}
217217

218218
$type = $parameter->getClass()->getName();
219-
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;
219+
$type = $this->aliases[$type] ?? $type;
220220

221221
if (! $container->has($type)) {
222222
throw new ServiceNotFoundException(sprintf(

src/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Config implements ConfigInterface
6363
public function __construct(array $config = [])
6464
{
6565
// Only merge keys we're interested in
66-
foreach (array_keys($config) as $key) {
66+
foreach (\array_keys($config) as $key) {
6767
if (! isset($this->allowedKeys[$key])) {
6868
unset($config[$key]);
6969
}
@@ -98,12 +98,12 @@ private function merge(array $a, array $b)
9898
foreach ($b as $key => $value) {
9999
if ($value instanceof MergeReplaceKeyInterface) {
100100
$a[$key] = $value->getData();
101-
} elseif (isset($a[$key]) || array_key_exists($key, $a)) {
101+
} elseif (isset($a[$key]) || \array_key_exists($key, $a)) {
102102
if ($value instanceof MergeRemoveKey) {
103103
unset($a[$key]);
104-
} elseif (is_int($key)) {
104+
} elseif (\is_int($key)) {
105105
$a[] = $value;
106-
} elseif (is_array($value) && is_array($a[$key])) {
106+
} elseif (\is_array($value) && \is_array($a[$key])) {
107107
$a[$key] = $this->merge($a[$key], $value);
108108
} else {
109109
$a[$key] = $value;

src/ServiceManager.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function get($name)
183183
return $this->services[$requestedName];
184184
}
185185

186-
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
186+
$name = $this->resolvedAliases[$name] ?? $name;
187187

188188
// Next, if the alias should be shared, and we have cached the resolved
189189
// service, use it.
@@ -223,7 +223,7 @@ public function get($name)
223223
public function build($name, array $options = null)
224224
{
225225
// We never cache when using "build"
226-
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
226+
$name = $this->resolvedAliases[$name] ?? $name;
227227
return $this->doCreate($name, $options);
228228
}
229229

@@ -232,7 +232,7 @@ public function build($name, array $options = null)
232232
*/
233233
public function has($name)
234234
{
235-
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
235+
$name = $this->resolvedAliases[$name] ?? $name;
236236
$found = isset($this->services[$name]) || isset($this->factories[$name]);
237237

238238
if ($found) {
@@ -656,7 +656,7 @@ private function resolveNewAliasesWithPreviouslyResolvedAliases(array $aliases)
656656
*/
657657
private function getFactory($name)
658658
{
659-
$factory = isset($this->factories[$name]) ? $this->factories[$name] : null;
659+
$factory = $this->factories[$name] ?? null;
660660

661661
$lazyLoaded = false;
662662
if (\is_string($factory) && \class_exists($factory)) {
@@ -710,7 +710,7 @@ private function createDelegatorFromName($name, array $options = null)
710710

711711
if (! \is_callable($delegatorFactory)) {
712712
if (\is_string($delegatorFactory)) {
713-
throw new ServiceNotCreatedException(sprintf(
713+
throw new ServiceNotCreatedException(\sprintf(
714714
'An invalid delegator factory was registered; resolved to class or function "%s" '
715715
. 'which does not exist; please provide a valid function name or class name resolving '
716716
. 'to an implementation of %s',
@@ -719,9 +719,9 @@ private function createDelegatorFromName($name, array $options = null)
719719
));
720720
}
721721

722-
throw new ServiceNotCreatedException(sprintf(
722+
throw new ServiceNotCreatedException(\sprintf(
723723
'A non-callable delegator, "%s", was provided; expected a callable or instance of "%s"',
724-
is_object($delegatorFactory) ? get_class($delegatorFactory) : gettype($delegatorFactory),
724+
\is_object($delegatorFactory) ? \get_class($delegatorFactory) : \gettype($delegatorFactory),
725725
DelegatorFactoryInterface::class
726726
));
727727
}

0 commit comments

Comments
 (0)