Permalink
Browse files

Merge pull request #630 from omarkdev/early-return

Simplify conditions
  • Loading branch information...
mnapoli committed Oct 8, 2018
2 parents c109437 + fa4322b commit 66ecb4f0a3a1edd198a15a64445e5d6f8a7768e4
Showing with 10 additions and 23 deletions.
  1. +8 −13 src/Compiler/ObjectCreationCompiler.php
  2. +2 −10 src/Definition/Dumper/ObjectDefinitionDumper.php
@@ -186,19 +186,14 @@ private function assertClassIsNotAnonymous(ObjectDefinition $definition)
private function assertClassIsInstantiable(ObjectDefinition $definition)
{
if (! $definition->isInstantiable()) {
// Check that the class exists
if (! $definition->classExists()) {
throw InvalidDefinition::create($definition, sprintf(
'Entry "%s" cannot be compiled: the class doesn\'t exist',
$definition->getName()
));
}
throw InvalidDefinition::create($definition, sprintf(
'Entry "%s" cannot be compiled: the class is not instantiable',
$definition->getName()
));
if ($definition->isInstantiable()) {
return;
}
$message = ! $definition->classExists()
? 'Entry "%s" cannot be compiled: the class doesn\'t exist'
: 'Entry "%s" cannot be compiled: the class is not instantiable';
throw InvalidDefinition::create($definition, sprintf($message, $definition->getName()));
}
}
@@ -72,11 +72,7 @@ private function dumpProperties(ObjectDefinition $definition) : string
foreach ($definition->getPropertyInjections() as $propertyInjection) {
$value = $propertyInjection->getValue();
if ($value instanceof Definition) {
$valueStr = (string) $value;
} else {
$valueStr = var_export($value, true);
}
$valueStr = $value instanceof Definition ? (string) $value : var_export($value, true);
$str .= sprintf(PHP_EOL . ' $%s = %s', $propertyInjection->getPropertyName(), $valueStr);
}
@@ -108,12 +104,8 @@ private function dumpMethodParameters(string $className, MethodInjection $method
foreach ($methodReflection->getParameters() as $index => $parameter) {
if (array_key_exists($index, $definitionParameters)) {
$value = $definitionParameters[$index];
$valueStr = $value instanceof Definition ? (string) $value : var_export($value, true);
if ($value instanceof Definition) {
$valueStr = (string) $value;
} else {
$valueStr = var_export($value, true);
}
$args[] = sprintf('$%s = %s', $parameter->getName(), $valueStr);
continue;

0 comments on commit 66ecb4f

Please sign in to comment.