Skip to content

Commit

Permalink
coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 26, 2018
1 parent db5e2dc commit 8e717ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function getByType($type, $throw = false)
{
$type = Helpers::normalizeClass($type);

if ($this->currentService !== null
if (
$this->currentService !== null
&& is_a($this->definitions[$this->currentService]->getType(), $type, true)
) {
return $this->currentService;
Expand Down Expand Up @@ -337,7 +338,8 @@ public function prepareClassList()
}

// auto-disable autowiring for aliases
if ($def->getAutowired() === true
if (
$def->getAutowired() === true
&& ($alias = $this->getServiceName($def->getFactory()->getEntity()))
&& (!$def->getImplement() || (!Strings::contains($alias, '\\') && $this->definitions[$alias]->getImplement()))
) {
Expand Down Expand Up @@ -438,7 +440,8 @@ private function resolveImplement(ServiceDefinition $def, $name)
if (!$def->getEntity()) {
$def->setFactory($def->getType(), $def->getFactory() ? $def->getFactory()->arguments : []);
}
if (($class = $this->resolveEntityType($def->getFactory(), [$name => 1]))
if (
($class = $this->resolveEntityType($def->getFactory(), [$name => 1]))
&& ($ctor = (new ReflectionClass($class))->getConstructor())
) {
foreach ($ctor->getParameters() as $param) {
Expand Down Expand Up @@ -657,9 +660,10 @@ public function completeStatement(Statement $statement)
if (!$arguments && substr($entity[1], -2) === '[]') {
throw new ServiceCreationException("Missing argument for $entity[1].");
}
} elseif ($type = empty($service) || $entity[1] === 'create'
? $this->resolveEntityType($entity[0])
: $this->definitions[$service]->getType()
} elseif (
$type = empty($service) || $entity[1] === 'create'
? $this->resolveEntityType($entity[0])
: $this->definitions[$service]->getType()
) {
$arguments = $this->autowireArguments($type, $entity[1], $arguments);
}
Expand Down
5 changes: 4 additions & 1 deletion src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ private function generateService($name)
$this->currentService = null;
$code = '$service = ' . $this->formatStatement($factory) . ";\n";

if ((PHP_VERSION_ID < 70000 || $def->getSetup()) && ($type = $def->getType()) && !$serviceRef && $type !== $entity
if (
(PHP_VERSION_ID < 70000 || $def->getSetup())
&& ($type = $def->getType())
&& !$serviceRef && $type !== $entity
&& !(is_string($entity) && preg_match('#^[\w\\\\]+\z#', $entity) && is_subclass_of($entity, $type))
) {
$code .= PhpHelpers::formatArgs("if (!\$service instanceof $type) {\n"
Expand Down
7 changes: 5 additions & 2 deletions src/DI/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ class Statement
*/
public function __construct($entity, array $arguments = [])
{
if (!is_string($entity) && !(is_array($entity) && isset($entity[0], $entity[1]))
&& !$entity instanceof ServiceDefinition && $entity !== null
if (
!is_string($entity)
&& !(is_array($entity) && isset($entity[0], $entity[1]))
&& !$entity instanceof ServiceDefinition
&& $entity !== null
) {
throw new Nette\InvalidArgumentException('Argument is not valid Statement entity.');
}
Expand Down

0 comments on commit 8e717ae

Please sign in to comment.