Skip to content

Commit

Permalink
FunctionLike changed to abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 10, 2023
1 parent da995ca commit a580c50
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
8 changes: 1 addition & 7 deletions src/PhpGenerator/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

namespace Nette\PhpGenerator;

use Nette;


/**
* Closure.
*
* @property-deprecated string $body
*/
final class Closure
final class Closure extends FunctionLike
{
use Nette\SmartObject;
use Traits\FunctionLike;
use Traits\AttributeAware;

/** @var Parameter[] */
Expand Down
2 changes: 1 addition & 1 deletion src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private function addCommentAndAttributes($element, Node $node): void
}


private function setupFunction(GlobalFunction|Method $function, Node\FunctionLike $node): void
private function setupFunction(FunctionLike $function, Node\FunctionLike $node): void
{
$function->setReturnReference($node->returnsByRef());
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpGenerator/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
}


public function fromCallable(callable $from): Method|GlobalFunction|Closure
public function fromCallable(callable $from): FunctionLike
{
$ref = Nette\Utils\Callback::toReflection($from);
return $ref instanceof \ReflectionMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@

declare(strict_types=1);

namespace Nette\PhpGenerator\Traits;
namespace Nette\PhpGenerator;

use JetBrains\PhpStorm\Language;
use Nette;
use Nette\PhpGenerator\Dumper;
use Nette\PhpGenerator\Parameter;
use Nette\Utils\Type;


/**
* @internal
* GlobalFunction/Closure/Method description.
*
* @property-deprecated string $body
*/
trait FunctionLike
abstract class FunctionLike
{
use Nette\SmartObject;

private string $body = '';

/** @var Parameter[] */
Expand Down
8 changes: 1 addition & 7 deletions src/PhpGenerator/GlobalFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

namespace Nette\PhpGenerator;

use Nette;


/**
* Global function.
*
* @property-deprecated string $body
*/
final class GlobalFunction
final class GlobalFunction extends FunctionLike
{
use Nette\SmartObject;
use Traits\FunctionLike;
use Traits\NameAware;
use Traits\CommentAware;
use Traits\AttributeAware;
Expand Down
12 changes: 6 additions & 6 deletions src/PhpGenerator/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@

/**
* Class method.
*
* @property-deprecated string|null $body
*/
final class Method
final class Method extends FunctionLike
{
use Nette\SmartObject;
use Traits\FunctionLike;
use Traits\NameAware;
use Traits\VisibilityAware;
use Traits\CommentAware;
Expand Down Expand Up @@ -92,7 +88,11 @@ public function addPromotedParameter(string $name, mixed $defaultValue = null):
$param->setDefaultValue($defaultValue);
}

return $this->parameters[$name] = $param;
$params = $this->getParameters();
$params[$name] = $param;
$this->setParameters($params);

return $param;
}


Expand Down
2 changes: 1 addition & 1 deletion src/PhpGenerator/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected function printDocComment(/*Traits\CommentAware*/ $commentable): string
}


private function printReturnType(Closure|GlobalFunction|Method $function): string
private function printReturnType(FunctionLike $function): string
{
return ($tmp = $this->printType($function->getReturnType(), $function->isReturnNullable()))
? $this->returnTypeColon . $tmp
Expand Down

0 comments on commit a580c50

Please sign in to comment.