Completed
Pull Request — master (#383)
by rakekniven
02:38
created
php-scoper/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php 3 patches
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -4,288 +4,288 @@
 block discarded – undo
4 4
 
5 5
 class NodeTraverser implements NodeTraverserInterface
6 6
 {
7
-    /**
8
-     * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes
9
-     * of the current node will not be traversed for any visitors.
10
-     *
11
-     * For subsequent visitors enterNode() will still be called on the current
12
-     * node and leaveNode() will also be invoked for the current node.
13
-     */
14
-    const DONT_TRAVERSE_CHILDREN = 1;
15
-
16
-    /**
17
-     * If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns
18
-     * STOP_TRAVERSAL, traversal is aborted.
19
-     *
20
-     * The afterTraverse() method will still be invoked.
21
-     */
22
-    const STOP_TRAVERSAL = 2;
23
-
24
-    /**
25
-     * If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs
26
-     * in an array, it will be removed from the array.
27
-     *
28
-     * For subsequent visitors leaveNode() will still be invoked for the
29
-     * removed node.
30
-     */
31
-    const REMOVE_NODE = 3;
32
-
33
-    /**
34
-     * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes
35
-     * of the current node will not be traversed for any visitors.
36
-     *
37
-     * For subsequent visitors enterNode() will not be called as well.
38
-     * leaveNode() will be invoked for visitors that has enterNode() method invoked.
39
-     */
40
-    const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4;
41
-
42
-    /** @var NodeVisitor[] Visitors */
43
-    protected $visitors = [];
44
-
45
-    /** @var bool Whether traversal should be stopped */
46
-    protected $stopTraversal;
47
-
48
-    public function __construct() {
49
-        // for BC
50
-    }
51
-
52
-    /**
53
-     * Adds a visitor.
54
-     *
55
-     * @param NodeVisitor $visitor Visitor to add
56
-     */
57
-    public function addVisitor(NodeVisitor $visitor) {
58
-        $this->visitors[] = $visitor;
59
-    }
60
-
61
-    /**
62
-     * Removes an added visitor.
63
-     *
64
-     * @param NodeVisitor $visitor
65
-     */
66
-    public function removeVisitor(NodeVisitor $visitor) {
67
-        foreach ($this->visitors as $index => $storedVisitor) {
68
-            if ($storedVisitor === $visitor) {
69
-                unset($this->visitors[$index]);
70
-                break;
71
-            }
72
-        }
73
-    }
74
-
75
-    /**
76
-     * Traverses an array of nodes using the registered visitors.
77
-     *
78
-     * @param Node[] $nodes Array of nodes
79
-     *
80
-     * @return Node[] Traversed array of nodes
81
-     */
82
-    public function traverse(array $nodes) : array {
83
-        $this->stopTraversal = false;
84
-
85
-        foreach ($this->visitors as $visitor) {
86
-            if (null !== $return = $visitor->beforeTraverse($nodes)) {
87
-                $nodes = $return;
88
-            }
89
-        }
90
-
91
-        $nodes = $this->traverseArray($nodes);
92
-
93
-        foreach ($this->visitors as $visitor) {
94
-            if (null !== $return = $visitor->afterTraverse($nodes)) {
95
-                $nodes = $return;
96
-            }
97
-        }
98
-
99
-        return $nodes;
100
-    }
101
-
102
-    /**
103
-     * Recursively traverse a node.
104
-     *
105
-     * @param Node $node Node to traverse.
106
-     *
107
-     * @return Node Result of traversal (may be original node or new one)
108
-     */
109
-    protected function traverseNode(Node $node) : Node {
110
-        foreach ($node->getSubNodeNames() as $name) {
111
-            $subNode =& $node->$name;
112
-
113
-            if (\is_array($subNode)) {
114
-                $subNode = $this->traverseArray($subNode);
115
-                if ($this->stopTraversal) {
116
-                    break;
117
-                }
118
-            } elseif ($subNode instanceof Node) {
119
-                $traverseChildren = true;
120
-                $breakVisitorIndex = null;
121
-
122
-                foreach ($this->visitors as $visitorIndex => $visitor) {
123
-                    $return = $visitor->enterNode($subNode);
124
-                    if (null !== $return) {
125
-                        if ($return instanceof Node) {
126
-                            $this->ensureReplacementReasonable($subNode, $return);
127
-                            $subNode = $return;
128
-                        } elseif (self::DONT_TRAVERSE_CHILDREN === $return) {
129
-                            $traverseChildren = false;
130
-                        } elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
131
-                            $traverseChildren = false;
132
-                            $breakVisitorIndex = $visitorIndex;
133
-                            break;
134
-                        } elseif (self::STOP_TRAVERSAL === $return) {
135
-                            $this->stopTraversal = true;
136
-                            break 2;
137
-                        } else {
138
-                            throw new \LogicException(
139
-                                'enterNode() returned invalid value of type ' . gettype($return)
140
-                            );
141
-                        }
142
-                    }
143
-                }
144
-
145
-                if ($traverseChildren) {
146
-                    $subNode = $this->traverseNode($subNode);
147
-                    if ($this->stopTraversal) {
148
-                        break;
149
-                    }
150
-                }
151
-
152
-                foreach ($this->visitors as $visitorIndex => $visitor) {
153
-                    $return = $visitor->leaveNode($subNode);
154
-
155
-                    if (null !== $return) {
156
-                        if ($return instanceof Node) {
157
-                            $this->ensureReplacementReasonable($subNode, $return);
158
-                            $subNode = $return;
159
-                        } elseif (self::STOP_TRAVERSAL === $return) {
160
-                            $this->stopTraversal = true;
161
-                            break 2;
162
-                        } elseif (\is_array($return)) {
163
-                            throw new \LogicException(
164
-                                'leaveNode() may only return an array ' .
165
-                                'if the parent structure is an array'
166
-                            );
167
-                        } else {
168
-                            throw new \LogicException(
169
-                                'leaveNode() returned invalid value of type ' . gettype($return)
170
-                            );
171
-                        }
172
-                    }
173
-
174
-                    if ($breakVisitorIndex === $visitorIndex) {
175
-                        break;
176
-                    }
177
-                }
178
-            }
179
-        }
180
-
181
-        return $node;
182
-    }
183
-
184
-    /**
185
-     * Recursively traverse array (usually of nodes).
186
-     *
187
-     * @param array $nodes Array to traverse
188
-     *
189
-     * @return array Result of traversal (may be original array or changed one)
190
-     */
191
-    protected function traverseArray(array $nodes) : array {
192
-        $doNodes = [];
193
-
194
-        foreach ($nodes as $i => &$node) {
195
-            if ($node instanceof Node) {
196
-                $traverseChildren = true;
197
-                $breakVisitorIndex = null;
198
-
199
-                foreach ($this->visitors as $visitorIndex => $visitor) {
200
-                    $return = $visitor->enterNode($node);
201
-                    if (null !== $return) {
202
-                        if ($return instanceof Node) {
203
-                            $this->ensureReplacementReasonable($node, $return);
204
-                            $node = $return;
205
-                        } elseif (self::DONT_TRAVERSE_CHILDREN === $return) {
206
-                            $traverseChildren = false;
207
-                        } elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
208
-                            $traverseChildren = false;
209
-                            $breakVisitorIndex = $visitorIndex;
210
-                            break;
211
-                        } elseif (self::STOP_TRAVERSAL === $return) {
212
-                            $this->stopTraversal = true;
213
-                            break 2;
214
-                        } else {
215
-                            throw new \LogicException(
216
-                                'enterNode() returned invalid value of type ' . gettype($return)
217
-                            );
218
-                        }
219
-                    }
220
-                }
221
-
222
-                if ($traverseChildren) {
223
-                    $node = $this->traverseNode($node);
224
-                    if ($this->stopTraversal) {
225
-                        break;
226
-                    }
227
-                }
228
-
229
-                foreach ($this->visitors as $visitorIndex => $visitor) {
230
-                    $return = $visitor->leaveNode($node);
231
-
232
-                    if (null !== $return) {
233
-                        if ($return instanceof Node) {
234
-                            $this->ensureReplacementReasonable($node, $return);
235
-                            $node = $return;
236
-                        } elseif (\is_array($return)) {
237
-                            $doNodes[] = [$i, $return];
238
-                            break;
239
-                        } elseif (self::REMOVE_NODE === $return) {
240
-                            $doNodes[] = [$i, []];
241
-                            break;
242
-                        } elseif (self::STOP_TRAVERSAL === $return) {
243
-                            $this->stopTraversal = true;
244
-                            break 2;
245
-                        } elseif (false === $return) {
246
-                            throw new \LogicException(
247
-                                'bool(false) return from leaveNode() no longer supported. ' .
248
-                                'Return NodeTraverser::REMOVE_NODE instead'
249
-                            );
250
-                        } else {
251
-                            throw new \LogicException(
252
-                                'leaveNode() returned invalid value of type ' . gettype($return)
253
-                            );
254
-                        }
255
-                    }
256
-
257
-                    if ($breakVisitorIndex === $visitorIndex) {
258
-                        break;
259
-                    }
260
-                }
261
-            } elseif (\is_array($node)) {
262
-                throw new \LogicException('Invalid node structure: Contains nested arrays');
263
-            }
264
-        }
265
-
266
-        if (!empty($doNodes)) {
267
-            while (list($i, $replace) = array_pop($doNodes)) {
268
-                array_splice($nodes, $i, 1, $replace);
269
-            }
270
-        }
271
-
272
-        return $nodes;
273
-    }
274
-
275
-    private function ensureReplacementReasonable($old, $new) {
276
-        if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
277
-            throw new \LogicException(
278
-                "Trying to replace statement ({$old->getType()}) " .
279
-                "with expression ({$new->getType()}). Are you missing a " .
280
-                "Stmt_Expression wrapper?"
281
-            );
282
-        }
283
-
284
-        if ($old instanceof Node\Expr && $new instanceof Node\Stmt) {
285
-            throw new \LogicException(
286
-                "Trying to replace expression ({$old->getType()}) " .
287
-                "with statement ({$new->getType()})"
288
-            );
289
-        }
290
-    }
7
+	/**
8
+	 * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes
9
+	 * of the current node will not be traversed for any visitors.
10
+	 *
11
+	 * For subsequent visitors enterNode() will still be called on the current
12
+	 * node and leaveNode() will also be invoked for the current node.
13
+	 */
14
+	const DONT_TRAVERSE_CHILDREN = 1;
15
+
16
+	/**
17
+	 * If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns
18
+	 * STOP_TRAVERSAL, traversal is aborted.
19
+	 *
20
+	 * The afterTraverse() method will still be invoked.
21
+	 */
22
+	const STOP_TRAVERSAL = 2;
23
+
24
+	/**
25
+	 * If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs
26
+	 * in an array, it will be removed from the array.
27
+	 *
28
+	 * For subsequent visitors leaveNode() will still be invoked for the
29
+	 * removed node.
30
+	 */
31
+	const REMOVE_NODE = 3;
32
+
33
+	/**
34
+	 * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes
35
+	 * of the current node will not be traversed for any visitors.
36
+	 *
37
+	 * For subsequent visitors enterNode() will not be called as well.
38
+	 * leaveNode() will be invoked for visitors that has enterNode() method invoked.
39
+	 */
40
+	const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4;
41
+
42
+	/** @var NodeVisitor[] Visitors */
43
+	protected $visitors = [];
44
+
45
+	/** @var bool Whether traversal should be stopped */
46
+	protected $stopTraversal;
47
+
48
+	public function __construct() {
49
+		// for BC
50
+	}
51
+
52
+	/**
53
+	 * Adds a visitor.
54
+	 *
55
+	 * @param NodeVisitor $visitor Visitor to add
56
+	 */
57
+	public function addVisitor(NodeVisitor $visitor) {
58
+		$this->visitors[] = $visitor;
59
+	}
60
+
61
+	/**
62
+	 * Removes an added visitor.
63
+	 *
64
+	 * @param NodeVisitor $visitor
65
+	 */
66
+	public function removeVisitor(NodeVisitor $visitor) {
67
+		foreach ($this->visitors as $index => $storedVisitor) {
68
+			if ($storedVisitor === $visitor) {
69
+				unset($this->visitors[$index]);
70
+				break;
71
+			}
72
+		}
73
+	}
74
+
75
+	/**
76
+	 * Traverses an array of nodes using the registered visitors.
77
+	 *
78
+	 * @param Node[] $nodes Array of nodes
79
+	 *
80
+	 * @return Node[] Traversed array of nodes
81
+	 */
82
+	public function traverse(array $nodes) : array {
83
+		$this->stopTraversal = false;
84
+
85
+		foreach ($this->visitors as $visitor) {
86
+			if (null !== $return = $visitor->beforeTraverse($nodes)) {
87
+				$nodes = $return;
88
+			}
89
+		}
90
+
91
+		$nodes = $this->traverseArray($nodes);
92
+
93
+		foreach ($this->visitors as $visitor) {
94
+			if (null !== $return = $visitor->afterTraverse($nodes)) {
95
+				$nodes = $return;
96
+			}
97
+		}
98
+
99
+		return $nodes;
100
+	}
101
+
102
+	/**
103
+	 * Recursively traverse a node.
104
+	 *
105
+	 * @param Node $node Node to traverse.
106
+	 *
107
+	 * @return Node Result of traversal (may be original node or new one)
108
+	 */
109
+	protected function traverseNode(Node $node) : Node {
110
+		foreach ($node->getSubNodeNames() as $name) {
111
+			$subNode =& $node->$name;
112
+
113
+			if (\is_array($subNode)) {
114
+				$subNode = $this->traverseArray($subNode);
115
+				if ($this->stopTraversal) {
116
+					break;
117
+				}
118
+			} elseif ($subNode instanceof Node) {
119
+				$traverseChildren = true;
120
+				$breakVisitorIndex = null;
121
+
122
+				foreach ($this->visitors as $visitorIndex => $visitor) {
123
+					$return = $visitor->enterNode($subNode);
124
+					if (null !== $return) {
125
+						if ($return instanceof Node) {
126
+							$this->ensureReplacementReasonable($subNode, $return);
127
+							$subNode = $return;
128
+						} elseif (self::DONT_TRAVERSE_CHILDREN === $return) {
129
+							$traverseChildren = false;
130
+						} elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
131
+							$traverseChildren = false;
132
+							$breakVisitorIndex = $visitorIndex;
133
+							break;
134
+						} elseif (self::STOP_TRAVERSAL === $return) {
135
+							$this->stopTraversal = true;
136
+							break 2;
137
+						} else {
138
+							throw new \LogicException(
139
+								'enterNode() returned invalid value of type ' . gettype($return)
140
+							);
141
+						}
142
+					}
143
+				}
144
+
145
+				if ($traverseChildren) {
146
+					$subNode = $this->traverseNode($subNode);
147
+					if ($this->stopTraversal) {
148
+						break;
149
+					}
150
+				}
151
+
152
+				foreach ($this->visitors as $visitorIndex => $visitor) {
153
+					$return = $visitor->leaveNode($subNode);
154
+
155
+					if (null !== $return) {
156
+						if ($return instanceof Node) {
157
+							$this->ensureReplacementReasonable($subNode, $return);
158
+							$subNode = $return;
159
+						} elseif (self::STOP_TRAVERSAL === $return) {
160
+							$this->stopTraversal = true;
161
+							break 2;
162
+						} elseif (\is_array($return)) {
163
+							throw new \LogicException(
164
+								'leaveNode() may only return an array ' .
165
+								'if the parent structure is an array'
166
+							);
167
+						} else {
168
+							throw new \LogicException(
169
+								'leaveNode() returned invalid value of type ' . gettype($return)
170
+							);
171
+						}
172
+					}
173
+
174
+					if ($breakVisitorIndex === $visitorIndex) {
175
+						break;
176
+					}
177
+				}
178
+			}
179
+		}
180
+
181
+		return $node;
182
+	}
183
+
184
+	/**
185
+	 * Recursively traverse array (usually of nodes).
186
+	 *
187
+	 * @param array $nodes Array to traverse
188
+	 *
189
+	 * @return array Result of traversal (may be original array or changed one)
190
+	 */
191
+	protected function traverseArray(array $nodes) : array {
192
+		$doNodes = [];
193
+
194
+		foreach ($nodes as $i => &$node) {
195
+			if ($node instanceof Node) {
196
+				$traverseChildren = true;
197
+				$breakVisitorIndex = null;
198
+
199
+				foreach ($this->visitors as $visitorIndex => $visitor) {
200
+					$return = $visitor->enterNode($node);
201
+					if (null !== $return) {
202
+						if ($return instanceof Node) {
203
+							$this->ensureReplacementReasonable($node, $return);
204
+							$node = $return;
205
+						} elseif (self::DONT_TRAVERSE_CHILDREN === $return) {
206
+							$traverseChildren = false;
207
+						} elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
208
+							$traverseChildren = false;
209
+							$breakVisitorIndex = $visitorIndex;
210
+							break;
211
+						} elseif (self::STOP_TRAVERSAL === $return) {
212
+							$this->stopTraversal = true;
213
+							break 2;
214
+						} else {
215
+							throw new \LogicException(
216
+								'enterNode() returned invalid value of type ' . gettype($return)
217
+							);
218
+						}
219
+					}
220
+				}
221
+
222
+				if ($traverseChildren) {
223
+					$node = $this->traverseNode($node);
224
+					if ($this->stopTraversal) {
225
+						break;
226
+					}
227
+				}
228
+
229
+				foreach ($this->visitors as $visitorIndex => $visitor) {
230
+					$return = $visitor->leaveNode($node);
231
+
232
+					if (null !== $return) {
233
+						if ($return instanceof Node) {
234
+							$this->ensureReplacementReasonable($node, $return);
235
+							$node = $return;
236
+						} elseif (\is_array($return)) {
237
+							$doNodes[] = [$i, $return];
238
+							break;
239
+						} elseif (self::REMOVE_NODE === $return) {
240
+							$doNodes[] = [$i, []];
241
+							break;
242
+						} elseif (self::STOP_TRAVERSAL === $return) {
243
+							$this->stopTraversal = true;
244
+							break 2;
245
+						} elseif (false === $return) {
246
+							throw new \LogicException(
247
+								'bool(false) return from leaveNode() no longer supported. ' .
248
+								'Return NodeTraverser::REMOVE_NODE instead'
249
+							);
250
+						} else {
251
+							throw new \LogicException(
252
+								'leaveNode() returned invalid value of type ' . gettype($return)
253
+							);
254
+						}
255
+					}
256
+
257
+					if ($breakVisitorIndex === $visitorIndex) {
258
+						break;
259
+					}
260
+				}
261
+			} elseif (\is_array($node)) {
262
+				throw new \LogicException('Invalid node structure: Contains nested arrays');
263
+			}
264
+		}
265
+
266
+		if (!empty($doNodes)) {
267
+			while (list($i, $replace) = array_pop($doNodes)) {
268
+				array_splice($nodes, $i, 1, $replace);
269
+			}
270
+		}
271
+
272
+		return $nodes;
273
+	}
274
+
275
+	private function ensureReplacementReasonable($old, $new) {
276
+		if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
277
+			throw new \LogicException(
278
+				"Trying to replace statement ({$old->getType()}) " .
279
+				"with expression ({$new->getType()}). Are you missing a " .
280
+				"Stmt_Expression wrapper?"
281
+			);
282
+		}
283
+
284
+		if ($old instanceof Node\Expr && $new instanceof Node\Stmt) {
285
+			throw new \LogicException(
286
+				"Trying to replace expression ({$old->getType()}) " .
287
+				"with statement ({$new->getType()})"
288
+			);
289
+		}
290
+	}
291 291
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     protected function traverseNode(Node $node) : Node {
110 110
         foreach ($node->getSubNodeNames() as $name) {
111
-            $subNode =& $node->$name;
111
+            $subNode = & $node->$name;
112 112
 
113 113
             if (\is_array($subNode)) {
114 114
                 $subNode = $this->traverseArray($subNode);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                             break 2;
137 137
                         } else {
138 138
                             throw new \LogicException(
139
-                                'enterNode() returned invalid value of type ' . gettype($return)
139
+                                'enterNode() returned invalid value of type '.gettype($return)
140 140
                             );
141 141
                         }
142 142
                     }
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
                             break 2;
162 162
                         } elseif (\is_array($return)) {
163 163
                             throw new \LogicException(
164
-                                'leaveNode() may only return an array ' .
164
+                                'leaveNode() may only return an array '.
165 165
                                 'if the parent structure is an array'
166 166
                             );
167 167
                         } else {
168 168
                             throw new \LogicException(
169
-                                'leaveNode() returned invalid value of type ' . gettype($return)
169
+                                'leaveNode() returned invalid value of type '.gettype($return)
170 170
                             );
171 171
                         }
172 172
                     }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
                             break 2;
214 214
                         } else {
215 215
                             throw new \LogicException(
216
-                                'enterNode() returned invalid value of type ' . gettype($return)
216
+                                'enterNode() returned invalid value of type '.gettype($return)
217 217
                             );
218 218
                         }
219 219
                     }
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
                             break 2;
245 245
                         } elseif (false === $return) {
246 246
                             throw new \LogicException(
247
-                                'bool(false) return from leaveNode() no longer supported. ' .
247
+                                'bool(false) return from leaveNode() no longer supported. '.
248 248
                                 'Return NodeTraverser::REMOVE_NODE instead'
249 249
                             );
250 250
                         } else {
251 251
                             throw new \LogicException(
252
-                                'leaveNode() returned invalid value of type ' . gettype($return)
252
+                                'leaveNode() returned invalid value of type '.gettype($return)
253 253
                             );
254 254
                         }
255 255
                     }
@@ -275,15 +275,15 @@  discard block
 block discarded – undo
275 275
     private function ensureReplacementReasonable($old, $new) {
276 276
         if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
277 277
             throw new \LogicException(
278
-                "Trying to replace statement ({$old->getType()}) " .
279
-                "with expression ({$new->getType()}). Are you missing a " .
278
+                "Trying to replace statement ({$old->getType()}) ".
279
+                "with expression ({$new->getType()}). Are you missing a ".
280 280
                 "Stmt_Expression wrapper?"
281 281
             );
282 282
         }
283 283
 
284 284
         if ($old instanceof Node\Expr && $new instanceof Node\Stmt) {
285 285
             throw new \LogicException(
286
-                "Trying to replace expression ({$old->getType()}) " .
286
+                "Trying to replace expression ({$old->getType()}) ".
287 287
                 "with statement ({$new->getType()})"
288 288
             );
289 289
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace PhpParser;
4 4
 
5
-class NodeTraverser implements NodeTraverserInterface
6
-{
5
+class NodeTraverser implements NodeTraverserInterface {
7 6
     /**
8 7
      * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes
9 8
      * of the current node will not be traversed for any visitors.
Please login to merge, or discard this patch.
lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@
 block discarded – undo
12 12
  * PHP 8.1 ReadonlyTokenEmulator.
13 13
  */
14 14
 class ReadonlyFunctionTokenEmulator extends KeywordEmulator {
15
-    public function getKeywordString(): string {
16
-        return 'readonly';
17
-    }
15
+	public function getKeywordString(): string {
16
+		return 'readonly';
17
+	}
18 18
 
19
-    public function getKeywordToken(): int {
20
-        return \T_READONLY;
21
-    }
19
+	public function getKeywordToken(): int {
20
+		return \T_READONLY;
21
+	}
22 22
 
23
-    public function getPhpVersion(): string {
24
-        return Emulative::PHP_8_2;
25
-    }
23
+	public function getPhpVersion(): string {
24
+		return Emulative::PHP_8_2;
25
+	}
26 26
 
27
-    public function reverseEmulate(string $code, array $tokens): array {
28
-        // Don't bother
29
-        return $tokens;
30
-    }
27
+	public function reverseEmulate(string $code, array $tokens): array {
28
+		// Don't bother
29
+		return $tokens;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -5,40 +5,40 @@
 block discarded – undo
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7 7
 class ExplicitOctalEmulator extends TokenEmulator {
8
-    public function getPhpVersion(): string {
9
-        return Emulative::PHP_8_1;
10
-    }
8
+	public function getPhpVersion(): string {
9
+		return Emulative::PHP_8_1;
10
+	}
11 11
 
12
-    public function isEmulationNeeded(string $code): bool {
13
-        return strpos($code, '0o') !== false || strpos($code, '0O') !== false;
14
-    }
12
+	public function isEmulationNeeded(string $code): bool {
13
+		return strpos($code, '0o') !== false || strpos($code, '0O') !== false;
14
+	}
15 15
 
16
-    public function emulate(string $code, array $tokens): array {
17
-        for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
18
-            if ($tokens[$i][0] == \T_LNUMBER && $tokens[$i][1] === '0' &&
19
-                isset($tokens[$i + 1]) && $tokens[$i + 1][0] == \T_STRING &&
20
-                preg_match('/[oO][0-7]+(?:_[0-7]+)*/', $tokens[$i + 1][1])
21
-            ) {
22
-                $tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1][1]);
23
-                array_splice($tokens, $i, 2, [
24
-                    [$tokenKind, '0' . $tokens[$i + 1][1], $tokens[$i][2]],
25
-                ]);
26
-                $c--;
27
-            }
28
-        }
29
-        return $tokens;
30
-    }
16
+	public function emulate(string $code, array $tokens): array {
17
+		for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
18
+			if ($tokens[$i][0] == \T_LNUMBER && $tokens[$i][1] === '0' &&
19
+				isset($tokens[$i + 1]) && $tokens[$i + 1][0] == \T_STRING &&
20
+				preg_match('/[oO][0-7]+(?:_[0-7]+)*/', $tokens[$i + 1][1])
21
+			) {
22
+				$tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1][1]);
23
+				array_splice($tokens, $i, 2, [
24
+					[$tokenKind, '0' . $tokens[$i + 1][1], $tokens[$i][2]],
25
+				]);
26
+				$c--;
27
+			}
28
+		}
29
+		return $tokens;
30
+	}
31 31
 
32
-    private function resolveIntegerOrFloatToken(string $str): int
33
-    {
34
-        $str = substr($str, 1);
35
-        $str = str_replace('_', '', $str);
36
-        $num = octdec($str);
37
-        return is_float($num) ? \T_DNUMBER : \T_LNUMBER;
38
-    }
32
+	private function resolveIntegerOrFloatToken(string $str): int
33
+	{
34
+		$str = substr($str, 1);
35
+		$str = str_replace('_', '', $str);
36
+		$num = octdec($str);
37
+		return is_float($num) ? \T_DNUMBER : \T_LNUMBER;
38
+	}
39 39
 
40
-    public function reverseEmulate(string $code, array $tokens): array {
41
-        // Explicit octals were not legal code previously, don't bother.
42
-        return $tokens;
43
-    }
40
+	public function reverseEmulate(string $code, array $tokens): array {
41
+		// Explicit octals were not legal code previously, don't bother.
42
+		return $tokens;
43
+	}
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
             ) {
22 22
                 $tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1][1]);
23 23
                 array_splice($tokens, $i, 2, [
24
-                    [$tokenKind, '0' . $tokens[$i + 1][1], $tokens[$i][2]],
24
+                    [$tokenKind, '0'.$tokens[$i + 1][1], $tokens[$i][2]],
25 25
                 ]);
26 26
                 $c--;
27 27
             }
Please login to merge, or discard this patch.
nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,30 +7,30 @@
 block discarded – undo
7 7
  */
8 8
 final class ReverseEmulator extends TokenEmulator
9 9
 {
10
-    /** @var TokenEmulator Inner emulator */
11
-    private $emulator;
10
+	/** @var TokenEmulator Inner emulator */
11
+	private $emulator;
12 12
 
13
-    public function __construct(TokenEmulator $emulator) {
14
-        $this->emulator = $emulator;
15
-    }
13
+	public function __construct(TokenEmulator $emulator) {
14
+		$this->emulator = $emulator;
15
+	}
16 16
 
17
-    public function getPhpVersion(): string {
18
-        return $this->emulator->getPhpVersion();
19
-    }
17
+	public function getPhpVersion(): string {
18
+		return $this->emulator->getPhpVersion();
19
+	}
20 20
 
21
-    public function isEmulationNeeded(string $code): bool {
22
-        return $this->emulator->isEmulationNeeded($code);
23
-    }
21
+	public function isEmulationNeeded(string $code): bool {
22
+		return $this->emulator->isEmulationNeeded($code);
23
+	}
24 24
 
25
-    public function emulate(string $code, array $tokens): array {
26
-        return $this->emulator->reverseEmulate($code, $tokens);
27
-    }
25
+	public function emulate(string $code, array $tokens): array {
26
+		return $this->emulator->reverseEmulate($code, $tokens);
27
+	}
28 28
 
29
-    public function reverseEmulate(string $code, array $tokens): array {
30
-        return $this->emulator->emulate($code, $tokens);
31
-    }
29
+	public function reverseEmulate(string $code, array $tokens): array {
30
+		return $this->emulator->emulate($code, $tokens);
31
+	}
32 32
 
33
-    public function preprocessCode(string $code, array &$patches): string {
34
-        return $code;
35
-    }
33
+	public function preprocessCode(string $code, array &$patches): string {
34
+		return $code;
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,7 @@
 block discarded – undo
5 5
 /**
6 6
  * Reverses emulation direction of the inner emulator.
7 7
  */
8
-final class ReverseEmulator extends TokenEmulator
9
-{
8
+final class ReverseEmulator extends TokenEmulator {
10 9
     /** @var TokenEmulator Inner emulator */
11 10
     private $emulator;
12 11
 
Please login to merge, or discard this patch.
nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,18 +6,18 @@
 block discarded – undo
6 6
 
7 7
 final class MatchTokenEmulator extends KeywordEmulator
8 8
 {
9
-    public function getPhpVersion(): string
10
-    {
11
-        return Emulative::PHP_8_0;
12
-    }
9
+	public function getPhpVersion(): string
10
+	{
11
+		return Emulative::PHP_8_0;
12
+	}
13 13
 
14
-    public function getKeywordString(): string
15
-    {
16
-        return 'match';
17
-    }
14
+	public function getKeywordString(): string
15
+	{
16
+		return 'match';
17
+	}
18 18
 
19
-    public function getKeywordToken(): int
20
-    {
21
-        return \T_MATCH;
22
-    }
19
+	public function getKeywordToken(): int
20
+	{
21
+		return \T_MATCH;
22
+	}
23 23
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7
-final class MatchTokenEmulator extends KeywordEmulator
8
-{
7
+final class MatchTokenEmulator extends KeywordEmulator {
9 8
     public function getPhpVersion(): string
10 9
     {
11 10
         return Emulative::PHP_8_0;
Please login to merge, or discard this patch.
php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
6 6
 
7 7
 final class CoaleseEqualTokenEmulator extends TokenEmulator
8 8
 {
9
-    public function getPhpVersion(): string
10
-    {
11
-        return Emulative::PHP_7_4;
12
-    }
9
+	public function getPhpVersion(): string
10
+	{
11
+		return Emulative::PHP_7_4;
12
+	}
13 13
 
14
-    public function isEmulationNeeded(string $code): bool
15
-    {
16
-        return strpos($code, '??=') !== false;
17
-    }
14
+	public function isEmulationNeeded(string $code): bool
15
+	{
16
+		return strpos($code, '??=') !== false;
17
+	}
18 18
 
19
-    public function emulate(string $code, array $tokens): array
20
-    {
21
-        // We need to manually iterate and manage a count because we'll change
22
-        // the tokens array on the way
23
-        $line = 1;
24
-        for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
25
-            if (isset($tokens[$i + 1])) {
26
-                if ($tokens[$i][0] === T_COALESCE && $tokens[$i + 1] === '=') {
27
-                    array_splice($tokens, $i, 2, [
28
-                        [\T_COALESCE_EQUAL, '??=', $line]
29
-                    ]);
30
-                    $c--;
31
-                    continue;
32
-                }
33
-            }
34
-            if (\is_array($tokens[$i])) {
35
-                $line += substr_count($tokens[$i][1], "\n");
36
-            }
37
-        }
19
+	public function emulate(string $code, array $tokens): array
20
+	{
21
+		// We need to manually iterate and manage a count because we'll change
22
+		// the tokens array on the way
23
+		$line = 1;
24
+		for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
25
+			if (isset($tokens[$i + 1])) {
26
+				if ($tokens[$i][0] === T_COALESCE && $tokens[$i + 1] === '=') {
27
+					array_splice($tokens, $i, 2, [
28
+						[\T_COALESCE_EQUAL, '??=', $line]
29
+					]);
30
+					$c--;
31
+					continue;
32
+				}
33
+			}
34
+			if (\is_array($tokens[$i])) {
35
+				$line += substr_count($tokens[$i][1], "\n");
36
+			}
37
+		}
38 38
 
39
-        return $tokens;
40
-    }
39
+		return $tokens;
40
+	}
41 41
 
42
-    public function reverseEmulate(string $code, array $tokens): array
43
-    {
44
-        // ??= was not valid code previously, don't bother.
45
-        return $tokens;
46
-    }
42
+	public function reverseEmulate(string $code, array $tokens): array
43
+	{
44
+		// ??= was not valid code previously, don't bother.
45
+		return $tokens;
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7
-final class CoaleseEqualTokenEmulator extends TokenEmulator
8
-{
7
+final class CoaleseEqualTokenEmulator extends TokenEmulator {
9 8
     public function getPhpVersion(): string
10 9
     {
11 10
         return Emulative::PHP_7_4;
Please login to merge, or discard this patch.
nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 
7 7
 final class EnumTokenEmulator extends KeywordEmulator
8 8
 {
9
-    public function getPhpVersion(): string
10
-    {
11
-        return Emulative::PHP_8_1;
12
-    }
9
+	public function getPhpVersion(): string
10
+	{
11
+		return Emulative::PHP_8_1;
12
+	}
13 13
 
14
-    public function getKeywordString(): string
15
-    {
16
-        return 'enum';
17
-    }
14
+	public function getKeywordString(): string
15
+	{
16
+		return 'enum';
17
+	}
18 18
 
19
-    public function getKeywordToken(): int
20
-    {
21
-        return \T_ENUM;
22
-    }
19
+	public function getKeywordToken(): int
20
+	{
21
+		return \T_ENUM;
22
+	}
23 23
 
24
-    protected function isKeywordContext(array $tokens, int $pos): bool
25
-    {
26
-        return parent::isKeywordContext($tokens, $pos)
27
-            && isset($tokens[$pos + 2])
28
-            && $tokens[$pos + 1][0] === \T_WHITESPACE
29
-            && $tokens[$pos + 2][0] === \T_STRING;
30
-    }
24
+	protected function isKeywordContext(array $tokens, int $pos): bool
25
+	{
26
+		return parent::isKeywordContext($tokens, $pos)
27
+			&& isset($tokens[$pos + 2])
28
+			&& $tokens[$pos + 1][0] === \T_WHITESPACE
29
+			&& $tokens[$pos + 2][0] === \T_STRING;
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7
-final class EnumTokenEmulator extends KeywordEmulator
8
-{
7
+final class EnumTokenEmulator extends KeywordEmulator {
9 8
     public function getPhpVersion(): string
10 9
     {
11 10
         return Emulative::PHP_8_1;
Please login to merge, or discard this patch.
nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -6,51 +6,51 @@
 block discarded – undo
6 6
 
7 7
 final class AttributeEmulator extends TokenEmulator
8 8
 {
9
-    public function getPhpVersion(): string
10
-    {
11
-        return Emulative::PHP_8_0;
12
-    }
13
-
14
-    public function isEmulationNeeded(string $code) : bool
15
-    {
16
-        return strpos($code, '#[') !== false;
17
-    }
18
-
19
-    public function emulate(string $code, array $tokens): array
20
-    {
21
-        // We need to manually iterate and manage a count because we'll change
22
-        // the tokens array on the way.
23
-        $line = 1;
24
-        for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
25
-            if ($tokens[$i] === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1] === '[') {
26
-                array_splice($tokens, $i, 2, [
27
-                    [\T_ATTRIBUTE, '#[', $line]
28
-                ]);
29
-                $c--;
30
-                continue;
31
-            }
32
-            if (\is_array($tokens[$i])) {
33
-                $line += substr_count($tokens[$i][1], "\n");
34
-            }
35
-        }
36
-
37
-        return $tokens;
38
-    }
39
-
40
-    public function reverseEmulate(string $code, array $tokens): array
41
-    {
42
-        // TODO
43
-        return $tokens;
44
-    }
45
-
46
-    public function preprocessCode(string $code, array &$patches): string {
47
-        $pos = 0;
48
-        while (false !== $pos = strpos($code, '#[', $pos)) {
49
-            // Replace #[ with %[
50
-            $code[$pos] = '%';
51
-            $patches[] = [$pos, 'replace', '#'];
52
-            $pos += 2;
53
-        }
54
-        return $code;
55
-    }
9
+	public function getPhpVersion(): string
10
+	{
11
+		return Emulative::PHP_8_0;
12
+	}
13
+
14
+	public function isEmulationNeeded(string $code) : bool
15
+	{
16
+		return strpos($code, '#[') !== false;
17
+	}
18
+
19
+	public function emulate(string $code, array $tokens): array
20
+	{
21
+		// We need to manually iterate and manage a count because we'll change
22
+		// the tokens array on the way.
23
+		$line = 1;
24
+		for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
25
+			if ($tokens[$i] === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1] === '[') {
26
+				array_splice($tokens, $i, 2, [
27
+					[\T_ATTRIBUTE, '#[', $line]
28
+				]);
29
+				$c--;
30
+				continue;
31
+			}
32
+			if (\is_array($tokens[$i])) {
33
+				$line += substr_count($tokens[$i][1], "\n");
34
+			}
35
+		}
36
+
37
+		return $tokens;
38
+	}
39
+
40
+	public function reverseEmulate(string $code, array $tokens): array
41
+	{
42
+		// TODO
43
+		return $tokens;
44
+	}
45
+
46
+	public function preprocessCode(string $code, array &$patches): string {
47
+		$pos = 0;
48
+		while (false !== $pos = strpos($code, '#[', $pos)) {
49
+			// Replace #[ with %[
50
+			$code[$pos] = '%';
51
+			$patches[] = [$pos, 'replace', '#'];
52
+			$pos += 2;
53
+		}
54
+		return $code;
55
+	}
56 56
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7
-final class AttributeEmulator extends TokenEmulator
8
-{
7
+final class AttributeEmulator extends TokenEmulator {
9 8
     public function getPhpVersion(): string
10 9
     {
11 10
         return Emulative::PHP_8_0;
Please login to merge, or discard this patch.
php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,31 +6,31 @@
 block discarded – undo
6 6
 
7 7
 final class ReadonlyTokenEmulator extends KeywordEmulator
8 8
 {
9
-    public function getPhpVersion(): string
10
-    {
11
-        return Emulative::PHP_8_1;
12
-    }
9
+	public function getPhpVersion(): string
10
+	{
11
+		return Emulative::PHP_8_1;
12
+	}
13 13
 
14
-    public function getKeywordString(): string
15
-    {
16
-        return 'readonly';
17
-    }
14
+	public function getKeywordString(): string
15
+	{
16
+		return 'readonly';
17
+	}
18 18
 
19
-    public function getKeywordToken(): int
20
-    {
21
-        return \T_READONLY;
22
-    }
19
+	public function getKeywordToken(): int
20
+	{
21
+		return \T_READONLY;
22
+	}
23 23
 
24
-    protected function isKeywordContext(array $tokens, int $pos): bool
25
-    {
26
-        if (!parent::isKeywordContext($tokens, $pos)) {
27
-            return false;
28
-        }
29
-        // Support "function readonly("
30
-        return !(isset($tokens[$pos + 1]) &&
31
-                 ($tokens[$pos + 1][0] === '(' ||
32
-                  ($tokens[$pos + 1][0] === \T_WHITESPACE &&
33
-                   isset($tokens[$pos + 2]) &&
34
-                   $tokens[$pos + 2][0] === '(')));
35
-    }
24
+	protected function isKeywordContext(array $tokens, int $pos): bool
25
+	{
26
+		if (!parent::isKeywordContext($tokens, $pos)) {
27
+			return false;
28
+		}
29
+		// Support "function readonly("
30
+		return !(isset($tokens[$pos + 1]) &&
31
+				 ($tokens[$pos + 1][0] === '(' ||
32
+				  ($tokens[$pos + 1][0] === \T_WHITESPACE &&
33
+				   isset($tokens[$pos + 2]) &&
34
+				   $tokens[$pos + 2][0] === '(')));
35
+	}
36 36
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use PhpParser\Lexer\Emulative;
6 6
 
7
-final class ReadonlyTokenEmulator extends KeywordEmulator
8
-{
7
+final class ReadonlyTokenEmulator extends KeywordEmulator {
9 8
     public function getPhpVersion(): string
10 9
     {
11 10
         return Emulative::PHP_8_1;
Please login to merge, or discard this patch.