Skip to content

Commit

Permalink
use friendly strings
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-therond committed Apr 14, 2022
1 parent d4108b7 commit 7843cf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion lib/PHPCfg/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function renderOp(Op $op)
$result .= "\n declaredType: " . $this->indent($this->renderType($op->declaredType));
}
if ($op instanceof Op\Expr\Include_) {
$result .= "\n type: " . $op->type;
$result .= "\n type: " . $this->indent($this->renderIncludeType($op->type));
}

foreach ($op->getVariableNames() as $varName) {
Expand Down Expand Up @@ -294,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
8 changes: 4 additions & 4 deletions test/code/include.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ require_once($foo);
-----
Block#1
Expr_Include
type: 1
type: include
expr: Var#1<$foo>
result: Var#2
Expr_Include
type: 2
type: include_once
expr: Var#1<$foo>
result: Var#3
Expr_Include
type: 3
type: require
expr: Var#1<$foo>
result: Var#4
Expr_Include
type: 4
type: require_once
expr: Var#1<$foo>
result: Var#5
Terminal_Return
Expand Down

0 comments on commit 7843cf8

Please sign in to comment.