Skip to content

Commit bcfa014

Browse files
committed
FunctionLike changed to abstract class
1 parent ff7486d commit bcfa014

File tree

7 files changed

+18
-28
lines changed

7 files changed

+18
-28
lines changed

src/PhpGenerator/Closure.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
namespace Nette\PhpGenerator;
1111

12-
use Nette;
13-
1412

1513
/**
1614
* Closure.
17-
*
18-
* @property-deprecated string $body
1915
*/
20-
final class Closure
16+
final class Closure extends FunctionLike
2117
{
22-
use Nette\SmartObject;
23-
use Traits\FunctionLike;
2418
use Traits\AttributeAware;
2519

2620
/** @var Parameter[] */

src/PhpGenerator/Extractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private function addCommentAndAttributes($element, Node $node): void
385385
}
386386

387387

388-
private function setupFunction(GlobalFunction|Method $function, Node\FunctionLike $node): void
388+
private function setupFunction(FunctionLike $function, Node\FunctionLike $node): void
389389
{
390390
$function->setReturnReference($node->returnsByRef());
391391
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);

src/PhpGenerator/Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
194194
}
195195

196196

197-
public function fromCallable(callable $from): Method|GlobalFunction|Closure
197+
public function fromCallable(callable $from): FunctionLike
198198
{
199199
$ref = Nette\Utils\Callback::toReflection($from);
200200
return $ref instanceof \ReflectionMethod

src/PhpGenerator/Traits/FunctionLike.php renamed to src/PhpGenerator/FunctionLike.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77

88
declare(strict_types=1);
99

10-
namespace Nette\PhpGenerator\Traits;
10+
namespace Nette\PhpGenerator;
1111

1212
use JetBrains\PhpStorm\Language;
1313
use Nette;
14-
use Nette\PhpGenerator\Dumper;
15-
use Nette\PhpGenerator\Parameter;
1614
use Nette\Utils\Type;
1715

1816

1917
/**
20-
* @internal
18+
* GlobalFunction/Closure/Method description.
19+
*
20+
* @property-deprecated string $body
2121
*/
22-
trait FunctionLike
22+
abstract class FunctionLike
2323
{
24+
use Nette\SmartObject;
25+
2426
private string $body = '';
2527

2628
/** @var Parameter[] */

src/PhpGenerator/GlobalFunction.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
namespace Nette\PhpGenerator;
1111

12-
use Nette;
13-
1412

1513
/**
1614
* Global function.
17-
*
18-
* @property-deprecated string $body
1915
*/
20-
final class GlobalFunction
16+
final class GlobalFunction extends FunctionLike
2117
{
22-
use Nette\SmartObject;
23-
use Traits\FunctionLike;
2418
use Traits\NameAware;
2519
use Traits\CommentAware;
2620
use Traits\AttributeAware;

src/PhpGenerator/Method.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414

1515
/**
1616
* Class method.
17-
*
18-
* @property-deprecated string|null $body
1917
*/
20-
final class Method
18+
final class Method extends FunctionLike
2119
{
22-
use Nette\SmartObject;
23-
use Traits\FunctionLike;
2420
use Traits\NameAware;
2521
use Traits\VisibilityAware;
2622
use Traits\CommentAware;
@@ -92,7 +88,11 @@ public function addPromotedParameter(string $name, mixed $defaultValue = null):
9288
$param->setDefaultValue($defaultValue);
9389
}
9490

95-
return $this->parameters[$name] = $param;
91+
$params = $this->getParameters();
92+
$params[$name] = $param;
93+
$this->setParameters($params);
94+
95+
return $param;
9696
}
9797

9898

src/PhpGenerator/Printer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected function printDocComment(/*Traits\CommentAware*/ $commentable): string
385385
}
386386

387387

388-
private function printReturnType(Closure|GlobalFunction|Method $function): string
388+
private function printReturnType(FunctionLike $function): string
389389
{
390390
return ($tmp = $this->printType($function->getReturnType(), $function->isReturnNullable()))
391391
? $this->returnTypeColon . $tmp

0 commit comments

Comments
 (0)