Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged branch Tobion/is_object_instance_of (PR #6051)

This PR was merged into the master branch.

Commits
-------

966e7d6 [DI] removed unneeded is_object() calls

Discussion
----------

[DI] removed unneeded is_object() calls

I searched through all of symfony for occurences of the coding style `(is_object($value) && $value instanceof Object)` with a regex like `is_object\(\$[a-zA-z0-9]+\) && \$[a-zA-z0-9]+ instanceof `.
The `is_object` calls are not needed in this case. Only the DI component made such duplicate checks.
  • Loading branch information...
commit 7e88eccfb6f48ae864e3b711eeb56ac5e500d066 2 parents 5127492 + 966e7d6
@fabpot fabpot authored
View
12 src/Symfony/Component/DependencyInjection/ContainerBuilder.php
@@ -806,10 +806,8 @@ private function createService(Definition $definition, $id)
}
if ($callable = $definition->getConfigurator()) {
- if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof Reference) {
- $callable[0] = $this->get((string) $callable[0]);
- } elseif (is_array($callable)) {
- $callable[0] = $parameterBag->resolveValue($callable[0]);
+ if (is_array($callable)) {
+ $callable[0] = $callable[0] instanceof Reference ? $this->get((string) $callable[0]) : $parameterBag->resolveValue($callable[0]);
}
if (!is_callable($callable)) {
@@ -835,9 +833,9 @@ public function resolveServices($value)
foreach ($value as &$v) {
$v = $this->resolveServices($v);
}
- } elseif (is_object($value) && $value instanceof Reference) {
+ } elseif ($value instanceof Reference) {
$value = $this->get((string) $value, $value->getInvalidBehavior());
- } elseif (is_object($value) && $value instanceof Definition) {
+ } elseif ($value instanceof Definition) {
$value = $this->createService($value, null);
}
@@ -895,7 +893,7 @@ public static function getServiceConditionals($value)
foreach ($value as $v) {
$services = array_unique(array_merge($services, self::getServiceConditionals($v)));
}
- } elseif (is_object($value) && $value instanceof Reference && $value->getInvalidBehavior() === ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
+ } elseif ($value instanceof Reference && $value->getInvalidBehavior() === ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
$services[] = (string) $value;
}
View
2  src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php
@@ -130,7 +130,7 @@ private function findEdges($id, $arguments, $required, $name)
{
$edges = array();
foreach ($arguments as $argument) {
- if (is_object($argument) && $argument instanceof Parameter) {
+ if ($argument instanceof Parameter) {
$argument = $this->container->hasParameter($argument) ? $this->container->getParameter($argument) : null;
} elseif (is_string($argument) && preg_match('/^%([^%]+)%$/', $argument, $match)) {
$argument = $this->container->hasParameter($match[1]) ? $this->container->getParameter($match[1]) : null;
View
10 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
@@ -452,7 +452,7 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta
}
if (is_array($callable)) {
- if (is_object($callable[0]) && $callable[0] instanceof Reference) {
+ if ($callable[0] instanceof Reference) {
return sprintf(" %s->%s(\$%s);\n", $this->getServiceCall((string) $callable[0]), $callable[1], $variableName);
}
@@ -997,7 +997,7 @@ private function dumpValue($value, $interpolate = true)
}
return sprintf('array(%s)', implode(', ', $code));
- } elseif (is_object($value) && $value instanceof Definition) {
+ } elseif ($value instanceof Definition) {
if (null !== $this->definitionVariables && $this->definitionVariables->contains($value)) {
return $this->dumpValue($this->definitionVariables->offsetGet($value), $interpolate);
}
@@ -1029,15 +1029,15 @@ private function dumpValue($value, $interpolate = true)
}
return sprintf("new \\%s(%s)", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
- } elseif (is_object($value) && $value instanceof Variable) {
+ } elseif ($value instanceof Variable) {
return '$'.$value;
- } elseif (is_object($value) && $value instanceof Reference) {
+ } elseif ($value instanceof Reference) {
if (null !== $this->referenceVariables && isset($this->referenceVariables[$id = (string) $value])) {
return $this->dumpValue($this->referenceVariables[$id], $interpolate);
}
return $this->getServiceCall((string) $value, $value);
- } elseif (is_object($value) && $value instanceof Parameter) {
+ } elseif ($value instanceof Parameter) {
return $this->dumpParameter($value);
} elseif (true === $interpolate && is_string($value)) {
if (preg_match('/^%([^%]+)%$/', $value, $match)) {
View
8 src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
@@ -158,7 +158,7 @@ private function addService($definition, $id, \DOMElement $parent)
if ($callable = $definition->getConfigurator()) {
$configurator = $this->document->createElement('configurator');
if (is_array($callable)) {
- $configurator->setAttribute((is_object($callable[0]) && $callable[0] instanceof Reference ? 'service' : 'class'), $callable[0]);
+ $configurator->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
$configurator->setAttribute('method', $callable[1]);
} else {
$configurator->setAttribute('function', $callable);
@@ -230,7 +230,7 @@ private function convertParameters($parameters, $type, \DOMElement $parent, $key
if (is_array($value)) {
$element->setAttribute('type', 'collection');
$this->convertParameters($value, $type, $element, 'key');
- } elseif (is_object($value) && $value instanceof Reference) {
+ } elseif ($value instanceof Reference) {
$element->setAttribute('type', 'service');
$element->setAttribute('id', (string) $value);
$behaviour = $value->getInvalidBehavior();
@@ -239,7 +239,7 @@ private function convertParameters($parameters, $type, \DOMElement $parent, $key
} elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
$element->setAttribute('on-invalid', 'ignore');
}
- } elseif (is_object($value) && $value instanceof Definition) {
+ } elseif ($value instanceof Definition) {
$element->setAttribute('type', 'service');
$this->addService($value, null, $element);
} else {
@@ -294,7 +294,7 @@ public static function phpToXml($value)
return 'true';
case false === $value:
return 'false';
- case is_object($value) && $value instanceof Parameter:
+ case $value instanceof Parameter:
return '%'.$value.'%';
case is_object($value) || is_resource($value):
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
View
6 src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
@@ -120,7 +120,7 @@ private function addService($id, $definition)
if ($callable = $definition->getConfigurator()) {
if (is_array($callable)) {
- if (is_object($callable[0]) && $callable[0] instanceof Reference) {
+ if ($callable[0] instanceof Reference) {
$callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
} else {
$callable = array($callable[0], $callable[1]);
@@ -211,9 +211,9 @@ private function dumpValue($value)
}
return $code;
- } elseif (is_object($value) && $value instanceof Reference) {
+ } elseif ($value instanceof Reference) {
return $this->getServiceCall((string) $value, $value);
- } elseif (is_object($value) && $value instanceof Parameter) {
+ } elseif ($value instanceof Parameter) {
return $this->getParameterCall((string) $value);
} elseif (is_object($value) || is_resource($value)) {
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
Please sign in to comment.
Something went wrong with that request. Please try again.