Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 20, 2020
1 parent 04baf6a commit 77d6906
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use Nette;
use Nette\DI\Definitions\Reference;
use Nette\DI\Definitions\Statement;
use Nette\PhpGenerator\Helpers as PhpHelpers;
use Nette\PhpGenerator\PhpLiteral;
use Nette\PhpGenerator as Php;
use Nette\Utils\Strings;


Expand All @@ -40,10 +39,10 @@ public function __construct(ContainerBuilder $builder)
/**
* Generates PHP classes. First class is the container.
*/
public function generate(string $className): Nette\PhpGenerator\ClassType
public function generate(string $className): Php\ClassType
{
$this->className = $className;
$class = new Nette\PhpGenerator\ClassType($this->className);
$class = new Php\ClassType($this->className);
$class->setExtends(Container::class);
$class->addMethod('__construct')
->addBody('parent::__construct($params);')
Expand Down Expand Up @@ -73,7 +72,7 @@ public function generate(string $className): Nette\PhpGenerator\ClassType
}


public function toString(Nette\PhpGenerator\ClassType $class): string
public function toString(Php\ClassType $class): string
{
return '/** @noinspection PhpParamsInspection,PhpMethodMayBeStaticInspection */
Expand All @@ -83,7 +82,7 @@ public function toString(Nette\PhpGenerator\ClassType $class): string
}


public function addInitialization(Nette\PhpGenerator\ClassType $class, CompilerExtension $extension): void
public function addInitialization(Php\ClassType $class, CompilerExtension $extension): void
{
$closure = $extension->getInitialization();
if ($closure->getBody()) {
Expand All @@ -94,11 +93,11 @@ public function addInitialization(Nette\PhpGenerator\ClassType $class, CompilerE
}


public function generateMethod(Definitions\Definition $def): Nette\PhpGenerator\Method
public function generateMethod(Definitions\Definition $def): Php\Method
{
$name = $def->getName();
try {
$method = new Nette\PhpGenerator\Method(Container::getMethodName($name));
$method = new Php\Method(Container::getMethodName($name));
$method->setPublic();
$method->setReturnType($def->getType());
$def->generateMethod($method, $this);
Expand Down Expand Up @@ -171,33 +170,33 @@ public function formatPhp(string $statement, array $args): string
{
array_walk_recursive($args, function (&$val): void {
if ($val instanceof Statement) {
$val = new PhpLiteral($this->formatStatement($val));
$val = new Php\Literal($this->formatStatement($val));

} elseif ($val instanceof Reference) {
$name = $val->getValue();
if ($val->isSelf()) {
$val = new PhpLiteral('$service');
$val = new Php\Literal('$service');
} elseif ($name === ContainerBuilder::THIS_CONTAINER) {
$val = new PhpLiteral('$this');
$val = new Php\Literal('$this');
} else {
$val = ContainerBuilder::literal('$this->getService(?)', [$name]);
}
}
});
return PhpHelpers::formatArgs($statement, $args);
return Php\Helpers::formatArgs($statement, $args);
}


/**
* Converts parameters from Definition to PhpGenerator.
* @return Nette\PhpGenerator\Parameter[]
* @return Php\Parameter[]
*/
public function convertParameters(array $parameters): array
{
$res = [];
foreach ($parameters as $k => $v) {
$tmp = explode(' ', is_int($k) ? $v : $k);
$param = $res[] = new Nette\PhpGenerator\Parameter(end($tmp));
$param = $res[] = new Php\Parameter(end($tmp));
if (!is_int($k)) {
$param->setDefaultValue($v);
}
Expand Down

0 comments on commit 77d6906

Please sign in to comment.