Skip to content

Commit

Permalink
Merge pull request #85 from eric-therond/print_include_type
Browse files Browse the repository at this point in the history
print include type
  • Loading branch information
ircmaxell committed Apr 14, 2022
2 parents 232c2ad + 7843cf8 commit 7216eb6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/PHPCfg/Printer.php
Expand Up @@ -129,6 +129,9 @@ protected function renderOp(Op $op)
if ($op instanceof Op\Expr\Param) {
$result .= "\n declaredType: " . $this->indent($this->renderType($op->declaredType));
}
if ($op instanceof Op\Expr\Include_) {
$result .= "\n type: " . $this->indent($this->renderIncludeType($op->type));
}

foreach ($op->getVariableNames() as $varName) {
$vars = $op->{$varName};
Expand Down Expand Up @@ -291,6 +294,22 @@ protected function renderType(?Op\Type $type): string
throw new \LogicException("Unknown type rendering: " . get_class($type));
}

protected function renderIncludeType(int $type): string
{
switch($type) {
case 1:
return "include";
case 2:
return "include_once";
case 3:
return "require";
case 4:
return "require_once";
default:
throw new \LogicException("Unknown include type rendering: " .$type);
}
}

protected function renderFlags(Op\Stmt $stmt): string
{
$result = '';
Expand Down
26 changes: 26 additions & 0 deletions test/code/include.test
@@ -0,0 +1,26 @@
<?php
include($foo);
include_once($foo);
require($foo);
require_once($foo);
-----
Block#1
Expr_Include
type: include
expr: Var#1<$foo>
result: Var#2
Expr_Include
type: include_once
expr: Var#1<$foo>
result: Var#3
Expr_Include
type: require
expr: Var#1<$foo>
result: Var#4
Expr_Include
type: require_once
expr: Var#1<$foo>
result: Var#5
Terminal_Return


0 comments on commit 7216eb6

Please sign in to comment.