Skip to content

Commit 174e6c3

Browse files
committed
NodeDumper: Print modifiers as strings
1 parent eefcfee commit 174e6c3

File tree

12 files changed

+73
-39
lines changed

12 files changed

+73
-39
lines changed

lib/PhpParser/NodeDumper.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PhpParser;
44

5+
use PhpParser\Node\Stmt\Class_;
6+
57
class NodeDumper
68
{
79
private $dumpComments;
@@ -38,7 +40,11 @@ public function dump($node) {
3840
} elseif (true === $value) {
3941
$r .= 'true';
4042
} elseif (is_scalar($value)) {
41-
$r .= $value;
43+
if ('flags' === $key || 'newModifier' === $key) {
44+
$r .= $this->dumpFlags($value);
45+
} else {
46+
$r .= $value;
47+
}
4248
} else {
4349
$r .= str_replace("\n", "\n ", $this->dump($value));
4450
}
@@ -73,4 +79,32 @@ public function dump($node) {
7379

7480
return $r . "\n)";
7581
}
82+
83+
protected function dumpFlags($flags) {
84+
$strs = [];
85+
if ($flags & Class_::MODIFIER_PUBLIC) {
86+
$strs[] = 'MODIFIER_PUBLIC';
87+
}
88+
if ($flags & Class_::MODIFIER_PROTECTED) {
89+
$strs[] = 'MODIFIER_PROTECTED';
90+
}
91+
if ($flags & Class_::MODIFIER_PRIVATE) {
92+
$strs[] = 'MODIFIER_PRIVATE';
93+
}
94+
if ($flags & Class_::MODIFIER_ABSTRACT) {
95+
$strs[] = 'MODIFIER_ABSTRACT';
96+
}
97+
if ($flags & Class_::MODIFIER_STATIC) {
98+
$strs[] = 'MODIFIER_STATIC';
99+
}
100+
if ($flags & Class_::MODIFIER_FINAL) {
101+
$strs[] = 'MODIFIER_FINAL';
102+
}
103+
104+
if ($strs) {
105+
return implode(' | ', $strs) . ' (' . $flags . ')';
106+
} else {
107+
return $flags;
108+
}
109+
}
76110
}

test/code/parser/semiReserved.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ array(
8181
)
8282
)
8383
2: Stmt_ClassMethod(
84-
flags: 8
84+
flags: MODIFIER_STATIC (8)
8585
byRef: false
8686
name: list
8787
params: array(
@@ -91,7 +91,7 @@ array(
9191
)
9292
)
9393
3: Stmt_ClassMethod(
94-
flags: 8
94+
flags: MODIFIER_STATIC (8)
9595
byRef: false
9696
name: protected
9797
params: array(
@@ -101,7 +101,7 @@ array(
101101
)
102102
)
103103
4: Stmt_Property(
104-
flags: 1
104+
flags: MODIFIER_PUBLIC (1)
105105
props: array(
106106
0: Stmt_PropertyProperty(
107107
name: class
@@ -110,7 +110,7 @@ array(
110110
)
111111
)
112112
5: Stmt_Property(
113-
flags: 1
113+
flags: MODIFIER_PUBLIC (1)
114114
props: array(
115115
0: Stmt_PropertyProperty(
116116
name: private
@@ -321,7 +321,7 @@ array(
321321
)
322322
)
323323
method: throw
324-
newModifier: 2
324+
newModifier: MODIFIER_PROTECTED (2)
325325
newName: public
326326
)
327327
3: Stmt_TraitUseAdaptation_Alias(
@@ -331,7 +331,7 @@ array(
331331
)
332332
)
333333
method: self
334-
newModifier: 2
334+
newModifier: MODIFIER_PROTECTED (2)
335335
newName: null
336336
)
337337
4: Stmt_TraitUseAdaptation_Alias(

test/code/parser/stmt/class/abstract.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ abstract class A {
99
-----
1010
array(
1111
0: Stmt_Class(
12-
flags: 16
12+
flags: MODIFIER_ABSTRACT (16)
1313
name: A
1414
extends: null
1515
implements: array(
1616
)
1717
stmts: array(
1818
0: Stmt_ClassMethod(
19-
flags: 1
19+
flags: MODIFIER_PUBLIC (1)
2020
byRef: false
2121
name: a
2222
params: array(
@@ -26,7 +26,7 @@ array(
2626
)
2727
)
2828
1: Stmt_ClassMethod(
29-
flags: 17
29+
flags: MODIFIER_PUBLIC | MODIFIER_ABSTRACT (17)
3030
byRef: false
3131
name: b
3232
params: array(

test/code/parser/stmt/class/anonymous.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ array(
3131
)
3232
stmts: array(
3333
0: Stmt_ClassMethod(
34-
flags: 1
34+
flags: MODIFIER_PUBLIC (1)
3535
byRef: false
3636
name: test
3737
params: array(
@@ -81,7 +81,7 @@ array(
8181
)
8282
stmts: array(
8383
0: Stmt_Property(
84-
flags: 1
84+
flags: MODIFIER_PUBLIC (1)
8585
props: array(
8686
0: Stmt_PropertyProperty(
8787
name: foo
@@ -144,7 +144,7 @@ array(
144144
)
145145
stmts: array(
146146
0: Stmt_ClassMethod(
147-
flags: 1
147+
flags: MODIFIER_PUBLIC (1)
148148
byRef: false
149149
name: test
150150
params: array(

test/code/parser/stmt/class/constModifiers.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ array(
3030
)
3131
)
3232
1: Stmt_ClassConst(
33-
flags: 1
33+
flags: MODIFIER_PUBLIC (1)
3434
consts: array(
3535
0: Const(
3636
name: B
@@ -41,7 +41,7 @@ array(
4141
)
4242
)
4343
2: Stmt_ClassConst(
44-
flags: 2
44+
flags: MODIFIER_PROTECTED (2)
4545
consts: array(
4646
0: Const(
4747
name: C
@@ -52,7 +52,7 @@ array(
5252
)
5353
)
5454
3: Stmt_ClassConst(
55-
flags: 4
55+
flags: MODIFIER_PRIVATE (4)
5656
consts: array(
5757
0: Const(
5858
name: D

test/code/parser/stmt/class/final.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class A {}
66
-----
77
array(
88
0: Stmt_Class(
9-
flags: 32
9+
flags: MODIFIER_FINAL (32)
1010
name: A
1111
extends: null
1212
implements: array(

test/code/parser/stmt/class/implicitPublic.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class A {
1414
-----
1515
array(
1616
0: Stmt_Class(
17-
flags: 16
17+
flags: MODIFIER_ABSTRACT (16)
1818
name: A
1919
extends: null
2020
implements: array(
@@ -30,7 +30,7 @@ array(
3030
)
3131
)
3232
1: Stmt_Property(
33-
flags: 8
33+
flags: MODIFIER_STATIC (8)
3434
props: array(
3535
0: Stmt_PropertyProperty(
3636
name: b
@@ -39,7 +39,7 @@ array(
3939
)
4040
)
4141
2: Stmt_ClassMethod(
42-
flags: 16
42+
flags: MODIFIER_ABSTRACT (16)
4343
byRef: false
4444
name: c
4545
params: array(
@@ -48,7 +48,7 @@ array(
4848
stmts: null
4949
)
5050
3: Stmt_ClassMethod(
51-
flags: 32
51+
flags: MODIFIER_FINAL (32)
5252
byRef: false
5353
name: d
5454
params: array(
@@ -58,7 +58,7 @@ array(
5858
)
5959
)
6060
4: Stmt_ClassMethod(
61-
flags: 8
61+
flags: MODIFIER_STATIC (8)
6262
byRef: false
6363
name: e
6464
params: array(
@@ -68,7 +68,7 @@ array(
6868
)
6969
)
7070
5: Stmt_ClassMethod(
71-
flags: 40
71+
flags: MODIFIER_STATIC | MODIFIER_FINAL (40)
7272
byRef: false
7373
name: f
7474
params: array(

test/code/parser/stmt/class/interface.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ array(
2323
)
2424
stmts: array(
2525
0: Stmt_ClassMethod(
26-
flags: 1
26+
flags: MODIFIER_PUBLIC (1)
2727
byRef: false
2828
name: a
2929
params: array(

test/code/parser/stmt/class/modifier.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Cannot use the final modifier on an abstract class member on line 1
3030
Syntax error, unexpected T_FINAL, expecting T_CLASS from 1:16 to 1:20
3131
array(
3232
0: Stmt_Class(
33-
flags: 32
33+
flags: MODIFIER_FINAL (32)
3434
name: A
3535
extends: null
3636
implements: array(

test/code/parser/stmt/class/php4Style.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ array(
3636
)
3737
)
3838
2: Stmt_ClassMethod(
39-
flags: 24
39+
flags: MODIFIER_ABSTRACT | MODIFIER_STATIC (24)
4040
byRef: false
4141
name: baz
4242
params: array(

0 commit comments

Comments
 (0)