Skip to content

Commit

Permalink
Merge pull request #630 from omarkdev/early-return
Browse files Browse the repository at this point in the history
Simplify conditions
  • Loading branch information
mnapoli committed Oct 8, 2018
2 parents c109437 + fa4322b commit 66ecb4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
21 changes: 8 additions & 13 deletions src/Compiler/ObjectCreationCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
12 changes: 2 additions & 10 deletions src/Definition/Dumper/ObjectDefinitionDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 66ecb4f

Please sign in to comment.