-
-
Notifications
You must be signed in to change notification settings - Fork 333
/
node_helper.php
58 lines (47 loc) · 1.17 KB
/
node_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
use PhpParser\Node;
use PhpParser\PrettyPrinter\Standard;
use Tracy\Dumper;
if (! function_exists('dump_with_depth')) {
function dump_with_depth(mixed $value, int $depth = 2): void
{
Dumper::dump($value, [
Dumper::DEPTH => $depth,
]);
}
}
if (! function_exists('dn')) {
function dn(Node $node, int $depth = 2): void
{
dump_node($node, $depth);
}
}
if (! function_exists('dump_node')) {
/**
* @param Node|Node[] $node
*/
function dump_node(Node | array $node, int $depth = 2): void
{
$nodes = is_array($node) ? $node : [$node];
foreach ($nodes as $node) {
Dumper::dump($node, [
Dumper::DEPTH => $depth,
]);
}
}
}
if (! function_exists('print_node')) {
/**
* @param Node|Node[] $node
*/
function print_node(Node | array $node): void
{
$standard = new Standard();
$nodes = is_array($node) ? $node : [$node];
foreach ($nodes as $node) {
$printedContent = $standard->prettyPrint([$node]);
Dumper::dump($printedContent);
}
}
}