Skip to content

Commit

Permalink
ServiceDefinition: removed unnecessary $service variable [Closes #206]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 24, 2019
1 parent 9097a08 commit 0112da4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/DI/Definitions/ServiceDefinition.php
Expand Up @@ -237,12 +237,16 @@ public function complete(Nette\DI\Resolver $resolver): void
public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGenerator $generator): void
{
$entity = $this->factory->getEntity();
$code = '$service = ' . $generator->formatStatement($this->factory) . ";\n";
$type = $this->getType();
$code = $generator->formatStatement($this->factory) . ";\n";
if (!$this->setup) {
$method->setBody('return ' . $code);
return;
}

$code = '$service = ' . $code;
$type = $this->getType();
if (
$this->setup
&& $type !== $entity
$type !== $entity
&& !(is_array($entity) && $entity[0] instanceof Reference && $entity[0]->getValue() === Nette\DI\ContainerBuilder::THIS_CONTAINER)
&& !(is_string($entity) && preg_match('#^[\w\\\\]+$#D', $entity) && is_subclass_of($entity, $type))
) {
Expand Down
3 changes: 1 addition & 2 deletions tests/DI/Definitions.FactoryDefinition.render.phpt
Expand Up @@ -49,8 +49,7 @@ test(function () {
public function create(): stdClass
{
$service = new stdClass;
return $service;
return new stdClass;
}
};
}', $method->__toString());
Expand Down

0 comments on commit 0112da4

Please sign in to comment.