Skip to content

Commit

Permalink
[DI] removed unneeded is_object() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Nov 18, 2012
1 parent 00d132a commit 966e7d6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit 966e7d6

Please sign in to comment.