From b47fb2601820490c2ec50a140b3ebc778725ebf8 Mon Sep 17 00:00:00 2001 From: pk-fr Date: Sat, 13 Jun 2020 18:00:00 +0200 Subject: [PATCH] fix issues with anonymous classes & return type declarations --- .../parser_extensions/my_node_visitor.php | 42 +++++++++++++++---- version.php | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/classes/parser_extensions/my_node_visitor.php b/include/classes/parser_extensions/my_node_visitor.php index 23a0d06..323e4f8 100644 --- a/include/classes/parser_extensions/my_node_visitor.php +++ b/include/classes/parser_extensions/my_node_visitor.php @@ -78,7 +78,7 @@ public function enterNode(PhpParser\Node $node) $this->t_loop_stack[] = array($label_loop_break_name,$label_loop_continue_name); } } - if ($node instanceof PhpParser\Node\Stmt\Class_) + if ( ($node instanceof PhpParser\Node\Stmt\Class_) && ($node->name != null) ) { $name = $this->get_identifier_name($node->name); if ( is_string($name) && (strlen($name) !== 0) ) @@ -215,14 +215,17 @@ public function leaveNode(PhpParser\Node $node) $scrambler = $t_scrambler['function_or_class']; if ($node instanceof PhpParser\Node\Stmt\Class_) { - $name = $this->get_identifier_name($node->name); - if ( is_string($name) && (strlen($name) !== 0) ) + if ($node->name != null) { - $r = $scrambler->scramble($name); - if ($r!==$name) + $name = $this->get_identifier_name($node->name); + if ( is_string($name) && (strlen($name) !== 0) ) { - $this->set_identifier_name($node->name,$r); - $node_modified = true; + $r = $scrambler->scramble($name); + if ($r!==$name) + { + $this->set_identifier_name($node->name,$r); + $node_modified = true; + } } } if (isset($node->{'extends'})) @@ -279,6 +282,31 @@ public function leaveNode(PhpParser\Node $node) } } } + if ($node instanceof PhpParser\Node\Stmt\ClassMethod || $node instanceof PhpParser\Node\Stmt\Function_) + { + if (isset($node->returnType)) + { + $node_tmp = $node->returnType; + if ($node_tmp instanceof PhpParser\Node\NullableType && isset($node_tmp->type) ) + { + $node_tmp = $node_tmp->type; + } + if ($node_tmp instanceof PhpParser\Node\Name && isset($node_tmp->parts)) + { + $parts = $node_tmp->parts; + $name = $parts[count($parts)-1]; + if ( is_string($name) && (strlen($name) !== 0) ) + { + $r = $scrambler->scramble($name); + if ($r!==$name) + { + $node_tmp->parts[count($parts)-1] = $r; + $node_modified = true; + } + } + } + } + } if ($node instanceof PhpParser\Node\Stmt\Catch_) { if (isset($node->types)) diff --git a/version.php b/version.php index 4a149c9..aeb6935 100644 --- a/version.php +++ b/version.php @@ -11,6 +11,6 @@ // Use and abuse at your own risks. //======================================================================== -$yakpro_po_version = "2.0.11"; +$yakpro_po_version = "2.0.12"; ?> \ No newline at end of file