Skip to content

Commit

Permalink
fix issues with anonymous classes & return type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
pk-fr committed Jun 13, 2020
1 parent 4d198ba commit b47fb26
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions include/classes/parser_extensions/my_node_visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down Expand Up @@ -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'}))
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// Use and abuse at your own risks.
//========================================================================

$yakpro_po_version = "2.0.11";
$yakpro_po_version = "2.0.12";

?>

0 comments on commit b47fb26

Please sign in to comment.