Skip to content

Commit

Permalink
requires nikic/php-parser 5.0 or newer
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 25, 2024
1 parent 919a24a commit 33eac94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"require-dev": {
"nette/tester": "^2.4",
"nikic/php-parser": "^4.18 || ^5.0",
"nikic/php-parser": "^5.0",
"tracy/tracy": "^2.8",
"phpstan/phpstan": "^1.0",
"jetbrains/phpstorm-attributes": "dev-master"
Expand Down
10 changes: 5 additions & 5 deletions src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Nette;
use PhpParser;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\NodeFinder;
use PhpParser\ParserFactory;
Expand Down Expand Up @@ -414,9 +415,8 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);
foreach ($node->getParams() as $item) {
$visibility = $this->toVisibility($item->flags);
$isReadonly = (bool) ($item->flags & Node\Stmt\Class_::MODIFIER_READONLY);
$param = $visibility
? ($function->addPromotedParameter($item->var->name))->setVisibility($visibility)->setReadonly($isReadonly)
? $function->addPromotedParameter($item->var->name)->setVisibility($visibility)->setReadonly($item->isReadonly())
: $function->addParameter($item->var->name);
$param->setType($item->type ? $this->toPhp($item->type) : null);
$param->setReference($item->byRef);
Expand Down Expand Up @@ -483,9 +483,9 @@ private function toValue(Node\Expr $node): mixed
private function toVisibility(int $flags): ?string
{
return match (true) {
(bool) ($flags & Node\Stmt\Class_::MODIFIER_PUBLIC) => ClassType::VisibilityPublic,
(bool) ($flags & Node\Stmt\Class_::MODIFIER_PROTECTED) => ClassType::VisibilityProtected,
(bool) ($flags & Node\Stmt\Class_::MODIFIER_PRIVATE) => ClassType::VisibilityPrivate,
(bool) ($flags & Modifiers::PUBLIC) => ClassType::VisibilityPublic,
(bool) ($flags & Modifiers::PROTECTED) => ClassType::VisibilityProtected,
(bool) ($flags & Modifiers::PRIVATE) => ClassType::VisibilityPrivate,
default => null,
};
}
Expand Down

0 comments on commit 33eac94

Please sign in to comment.