Skip to content
Permalink
Browse files

ServiceDefinition: removed unnecessary $service variable [Closes #206]

  • Loading branch information...
dg committed Jul 24, 2019
1 parent a49bf89 commit 01dce95a860d62c0b22a04ab7870170a29898029
Showing with 9 additions and 6 deletions.
  1. +8 −4 src/DI/Definitions/ServiceDefinition.php
  2. +1 −2 tests/DI/Definitions.FactoryDefinition.render.phpt
@@ -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))
) {
@@ -49,8 +49,7 @@ test(function () {
public function create(): stdClass
{
$service = new stdClass;
return $service;
return new stdClass;
}
};
}', $method->__toString());

0 comments on commit 01dce95

Please sign in to comment.
You can’t perform that action at this time.