[DI] removed unneeded is_object() calls

This commit is contained in:
Tobias Schultze 2012-11-18 21:27:35 +01:00
parent 00d132a6d3
commit 966e7d6d12
5 changed files with 18 additions and 20 deletions

View File

@ -806,10 +806,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
}
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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 File

@ -130,7 +130,7 @@ class GraphvizDumper extends Dumper
{
$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 File

@ -452,7 +452,7 @@ class PhpDumper extends Dumper
}
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 @@ EOF;
}
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 @@ EOF;
}
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 File

@ -158,7 +158,7 @@ class XmlDumper extends Dumper
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 @@ class XmlDumper extends Dumper
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 @@ class XmlDumper extends Dumper
} 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 @@ class XmlDumper extends Dumper
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 File

@ -120,7 +120,7 @@ class YamlDumper extends Dumper
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 @@ class YamlDumper extends Dumper
}
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.');