Completed
Push — master ( 8e973a...811a95 )
by
unknown
03:40 queued 01:04
created
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Parser.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@
 block discarded – undo
4 4
 
5 5
 interface Parser
6 6
 {
7
-    /**
8
-     * Parses PHP code into a node tree.
9
-     *
10
-     * @param string $code The source code to parse
11
-     * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
12
-     *                                        to ErrorHandler\Throwing.
13
-     *
14
-     * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
15
-     *                          the parser was unable to recover from an error).
16
-     */
17
-    public function parse(string $code, ?ErrorHandler $errorHandler = null);
7
+	/**
8
+	 * Parses PHP code into a node tree.
9
+	 *
10
+	 * @param string $code The source code to parse
11
+	 * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
12
+	 *                                        to ErrorHandler\Throwing.
13
+	 *
14
+	 * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
15
+	 *                          the parser was unable to recover from an error).
16
+	 */
17
+	public function parse(string $code, ?ErrorHandler $errorHandler = null);
18 18
 }
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
-interface Parser
6
-{
5
+interface Parser {
7 6
     /**
8 7
      * Parses PHP code into a node tree.
9 8
      *
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/NameContext.php 3 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -8,278 +8,278 @@
 block discarded – undo
8 8
 
9 9
 class NameContext
10 10
 {
11
-    /** @var null|Name Current namespace */
12
-    protected $namespace;
13
-
14
-    /** @var Name[][] Map of format [aliasType => [aliasName => originalName]] */
15
-    protected $aliases = [];
16
-
17
-    /** @var Name[][] Same as $aliases but preserving original case */
18
-    protected $origAliases = [];
19
-
20
-    /** @var ErrorHandler Error handler */
21
-    protected $errorHandler;
22
-
23
-    /**
24
-     * Create a name context.
25
-     *
26
-     * @param ErrorHandler $errorHandler Error handling used to report errors
27
-     */
28
-    public function __construct(ErrorHandler $errorHandler) {
29
-        $this->errorHandler = $errorHandler;
30
-    }
31
-
32
-    /**
33
-     * Start a new namespace.
34
-     *
35
-     * This also resets the alias table.
36
-     *
37
-     * @param Name|null $namespace Null is the global namespace
38
-     */
39
-    public function startNamespace(?Name $namespace = null) {
40
-        $this->namespace = $namespace;
41
-        $this->origAliases = $this->aliases = [
42
-            Stmt\Use_::TYPE_NORMAL   => [],
43
-            Stmt\Use_::TYPE_FUNCTION => [],
44
-            Stmt\Use_::TYPE_CONSTANT => [],
45
-        ];
46
-    }
47
-
48
-    /**
49
-     * Add an alias / import.
50
-     *
51
-     * @param Name   $name        Original name
52
-     * @param string $aliasName   Aliased name
53
-     * @param int    $type        One of Stmt\Use_::TYPE_*
54
-     * @param array  $errorAttrs Attributes to use to report an error
55
-     */
56
-    public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) {
57
-        // Constant names are case sensitive, everything else case insensitive
58
-        if ($type === Stmt\Use_::TYPE_CONSTANT) {
59
-            $aliasLookupName = $aliasName;
60
-        } else {
61
-            $aliasLookupName = strtolower($aliasName);
62
-        }
63
-
64
-        if (isset($this->aliases[$type][$aliasLookupName])) {
65
-            $typeStringMap = [
66
-                Stmt\Use_::TYPE_NORMAL   => '',
67
-                Stmt\Use_::TYPE_FUNCTION => 'function ',
68
-                Stmt\Use_::TYPE_CONSTANT => 'const ',
69
-            ];
70
-
71
-            $this->errorHandler->handleError(new Error(
72
-                sprintf(
73
-                    'Cannot use %s%s as %s because the name is already in use',
74
-                    $typeStringMap[$type], $name, $aliasName
75
-                ),
76
-                $errorAttrs
77
-            ));
78
-            return;
79
-        }
80
-
81
-        $this->aliases[$type][$aliasLookupName] = $name;
82
-        $this->origAliases[$type][$aliasName] = $name;
83
-    }
84
-
85
-    /**
86
-     * Get current namespace.
87
-     *
88
-     * @return null|Name Namespace (or null if global namespace)
89
-     */
90
-    public function getNamespace() {
91
-        return $this->namespace;
92
-    }
93
-
94
-    /**
95
-     * Get resolved name.
96
-     *
97
-     * @param Name $name Name to resolve
98
-     * @param int  $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT}
99
-     *
100
-     * @return null|Name Resolved name, or null if static resolution is not possible
101
-     */
102
-    public function getResolvedName(Name $name, int $type) {
103
-        // don't resolve special class names
104
-        if ($type === Stmt\Use_::TYPE_NORMAL && $name->isSpecialClassName()) {
105
-            if (!$name->isUnqualified()) {
106
-                $this->errorHandler->handleError(new Error(
107
-                    sprintf("'\\%s' is an invalid class name", $name->toString()),
108
-                    $name->getAttributes()
109
-                ));
110
-            }
111
-            return $name;
112
-        }
113
-
114
-        // fully qualified names are already resolved
115
-        if ($name->isFullyQualified()) {
116
-            return $name;
117
-        }
118
-
119
-        // Try to resolve aliases
120
-        if (null !== $resolvedName = $this->resolveAlias($name, $type)) {
121
-            return $resolvedName;
122
-        }
123
-
124
-        if ($type !== Stmt\Use_::TYPE_NORMAL && $name->isUnqualified()) {
125
-            if (null === $this->namespace) {
126
-                // outside of a namespace unaliased unqualified is same as fully qualified
127
-                return new FullyQualified($name, $name->getAttributes());
128
-            }
129
-
130
-            // Cannot resolve statically
131
-            return null;
132
-        }
133
-
134
-        // if no alias exists prepend current namespace
135
-        return FullyQualified::concat($this->namespace, $name, $name->getAttributes());
136
-    }
137
-
138
-    /**
139
-     * Get resolved class name.
140
-     *
141
-     * @param Name $name Class ame to resolve
142
-     *
143
-     * @return Name Resolved name
144
-     */
145
-    public function getResolvedClassName(Name $name) : Name {
146
-        return $this->getResolvedName($name, Stmt\Use_::TYPE_NORMAL);
147
-    }
148
-
149
-    /**
150
-     * Get possible ways of writing a fully qualified name (e.g., by making use of aliases).
151
-     *
152
-     * @param string $name Fully-qualified name (without leading namespace separator)
153
-     * @param int    $type One of Stmt\Use_::TYPE_*
154
-     *
155
-     * @return Name[] Possible representations of the name
156
-     */
157
-    public function getPossibleNames(string $name, int $type) : array {
158
-        $lcName = strtolower($name);
159
-
160
-        if ($type === Stmt\Use_::TYPE_NORMAL) {
161
-            // self, parent and static must always be unqualified
162
-            if ($lcName === "self" || $lcName === "parent" || $lcName === "static") {
163
-                return [new Name($name)];
164
-            }
165
-        }
166
-
167
-        // Collect possible ways to write this name, starting with the fully-qualified name
168
-        $possibleNames = [new FullyQualified($name)];
169
-
170
-        if (null !== $nsRelativeName = $this->getNamespaceRelativeName($name, $lcName, $type)) {
171
-            // Make sure there is no alias that makes the normally namespace-relative name
172
-            // into something else
173
-            if (null === $this->resolveAlias($nsRelativeName, $type)) {
174
-                $possibleNames[] = $nsRelativeName;
175
-            }
176
-        }
177
-
178
-        // Check for relevant namespace use statements
179
-        foreach ($this->origAliases[Stmt\Use_::TYPE_NORMAL] as $alias => $orig) {
180
-            $lcOrig = $orig->toLowerString();
181
-            if (0 === strpos($lcName, $lcOrig . '\\')) {
182
-                $possibleNames[] = new Name($alias . substr($name, strlen($lcOrig)));
183
-            }
184
-        }
185
-
186
-        // Check for relevant type-specific use statements
187
-        foreach ($this->origAliases[$type] as $alias => $orig) {
188
-            if ($type === Stmt\Use_::TYPE_CONSTANT) {
189
-                // Constants are are complicated-sensitive
190
-                $normalizedOrig = $this->normalizeConstName($orig->toString());
191
-                if ($normalizedOrig === $this->normalizeConstName($name)) {
192
-                    $possibleNames[] = new Name($alias);
193
-                }
194
-            } else {
195
-                // Everything else is case-insensitive
196
-                if ($orig->toLowerString() === $lcName) {
197
-                    $possibleNames[] = new Name($alias);
198
-                }
199
-            }
200
-        }
201
-
202
-        return $possibleNames;
203
-    }
204
-
205
-    /**
206
-     * Get shortest representation of this fully-qualified name.
207
-     *
208
-     * @param string $name Fully-qualified name (without leading namespace separator)
209
-     * @param int    $type One of Stmt\Use_::TYPE_*
210
-     *
211
-     * @return Name Shortest representation
212
-     */
213
-    public function getShortName(string $name, int $type) : Name {
214
-        $possibleNames = $this->getPossibleNames($name, $type);
215
-
216
-        // Find shortest name
217
-        $shortestName = null;
218
-        $shortestLength = \INF;
219
-        foreach ($possibleNames as $possibleName) {
220
-            $length = strlen($possibleName->toCodeString());
221
-            if ($length < $shortestLength) {
222
-                $shortestName = $possibleName;
223
-                $shortestLength = $length;
224
-            }
225
-        }
226
-
227
-       return $shortestName;
228
-    }
229
-
230
-    private function resolveAlias(Name $name, $type) {
231
-        $firstPart = $name->getFirst();
232
-
233
-        if ($name->isQualified()) {
234
-            // resolve aliases for qualified names, always against class alias table
235
-            $checkName = strtolower($firstPart);
236
-            if (isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName])) {
237
-                $alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName];
238
-                return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes());
239
-            }
240
-        } elseif ($name->isUnqualified()) {
241
-            // constant aliases are case-sensitive, function aliases case-insensitive
242
-            $checkName = $type === Stmt\Use_::TYPE_CONSTANT ? $firstPart : strtolower($firstPart);
243
-            if (isset($this->aliases[$type][$checkName])) {
244
-                // resolve unqualified aliases
245
-                return new FullyQualified($this->aliases[$type][$checkName], $name->getAttributes());
246
-            }
247
-        }
248
-
249
-        // No applicable aliases
250
-        return null;
251
-    }
252
-
253
-    private function getNamespaceRelativeName(string $name, string $lcName, int $type) {
254
-        if (null === $this->namespace) {
255
-            return new Name($name);
256
-        }
257
-
258
-        if ($type === Stmt\Use_::TYPE_CONSTANT) {
259
-            // The constants true/false/null always resolve to the global symbols, even inside a
260
-            // namespace, so they may be used without qualification
261
-            if ($lcName === "true" || $lcName === "false" || $lcName === "null") {
262
-                return new Name($name);
263
-            }
264
-        }
265
-
266
-        $namespacePrefix = strtolower($this->namespace . '\\');
267
-        if (0 === strpos($lcName, $namespacePrefix)) {
268
-            return new Name(substr($name, strlen($namespacePrefix)));
269
-        }
270
-
271
-        return null;
272
-    }
273
-
274
-    private function normalizeConstName(string $name) {
275
-        $nsSep = strrpos($name, '\\');
276
-        if (false === $nsSep) {
277
-            return $name;
278
-        }
279
-
280
-        // Constants have case-insensitive namespace and case-sensitive short-name
281
-        $ns = substr($name, 0, $nsSep);
282
-        $shortName = substr($name, $nsSep + 1);
283
-        return strtolower($ns) . '\\' . $shortName;
284
-    }
11
+	/** @var null|Name Current namespace */
12
+	protected $namespace;
13
+
14
+	/** @var Name[][] Map of format [aliasType => [aliasName => originalName]] */
15
+	protected $aliases = [];
16
+
17
+	/** @var Name[][] Same as $aliases but preserving original case */
18
+	protected $origAliases = [];
19
+
20
+	/** @var ErrorHandler Error handler */
21
+	protected $errorHandler;
22
+
23
+	/**
24
+	 * Create a name context.
25
+	 *
26
+	 * @param ErrorHandler $errorHandler Error handling used to report errors
27
+	 */
28
+	public function __construct(ErrorHandler $errorHandler) {
29
+		$this->errorHandler = $errorHandler;
30
+	}
31
+
32
+	/**
33
+	 * Start a new namespace.
34
+	 *
35
+	 * This also resets the alias table.
36
+	 *
37
+	 * @param Name|null $namespace Null is the global namespace
38
+	 */
39
+	public function startNamespace(?Name $namespace = null) {
40
+		$this->namespace = $namespace;
41
+		$this->origAliases = $this->aliases = [
42
+			Stmt\Use_::TYPE_NORMAL   => [],
43
+			Stmt\Use_::TYPE_FUNCTION => [],
44
+			Stmt\Use_::TYPE_CONSTANT => [],
45
+		];
46
+	}
47
+
48
+	/**
49
+	 * Add an alias / import.
50
+	 *
51
+	 * @param Name   $name        Original name
52
+	 * @param string $aliasName   Aliased name
53
+	 * @param int    $type        One of Stmt\Use_::TYPE_*
54
+	 * @param array  $errorAttrs Attributes to use to report an error
55
+	 */
56
+	public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) {
57
+		// Constant names are case sensitive, everything else case insensitive
58
+		if ($type === Stmt\Use_::TYPE_CONSTANT) {
59
+			$aliasLookupName = $aliasName;
60
+		} else {
61
+			$aliasLookupName = strtolower($aliasName);
62
+		}
63
+
64
+		if (isset($this->aliases[$type][$aliasLookupName])) {
65
+			$typeStringMap = [
66
+				Stmt\Use_::TYPE_NORMAL   => '',
67
+				Stmt\Use_::TYPE_FUNCTION => 'function ',
68
+				Stmt\Use_::TYPE_CONSTANT => 'const ',
69
+			];
70
+
71
+			$this->errorHandler->handleError(new Error(
72
+				sprintf(
73
+					'Cannot use %s%s as %s because the name is already in use',
74
+					$typeStringMap[$type], $name, $aliasName
75
+				),
76
+				$errorAttrs
77
+			));
78
+			return;
79
+		}
80
+
81
+		$this->aliases[$type][$aliasLookupName] = $name;
82
+		$this->origAliases[$type][$aliasName] = $name;
83
+	}
84
+
85
+	/**
86
+	 * Get current namespace.
87
+	 *
88
+	 * @return null|Name Namespace (or null if global namespace)
89
+	 */
90
+	public function getNamespace() {
91
+		return $this->namespace;
92
+	}
93
+
94
+	/**
95
+	 * Get resolved name.
96
+	 *
97
+	 * @param Name $name Name to resolve
98
+	 * @param int  $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT}
99
+	 *
100
+	 * @return null|Name Resolved name, or null if static resolution is not possible
101
+	 */
102
+	public function getResolvedName(Name $name, int $type) {
103
+		// don't resolve special class names
104
+		if ($type === Stmt\Use_::TYPE_NORMAL && $name->isSpecialClassName()) {
105
+			if (!$name->isUnqualified()) {
106
+				$this->errorHandler->handleError(new Error(
107
+					sprintf("'\\%s' is an invalid class name", $name->toString()),
108
+					$name->getAttributes()
109
+				));
110
+			}
111
+			return $name;
112
+		}
113
+
114
+		// fully qualified names are already resolved
115
+		if ($name->isFullyQualified()) {
116
+			return $name;
117
+		}
118
+
119
+		// Try to resolve aliases
120
+		if (null !== $resolvedName = $this->resolveAlias($name, $type)) {
121
+			return $resolvedName;
122
+		}
123
+
124
+		if ($type !== Stmt\Use_::TYPE_NORMAL && $name->isUnqualified()) {
125
+			if (null === $this->namespace) {
126
+				// outside of a namespace unaliased unqualified is same as fully qualified
127
+				return new FullyQualified($name, $name->getAttributes());
128
+			}
129
+
130
+			// Cannot resolve statically
131
+			return null;
132
+		}
133
+
134
+		// if no alias exists prepend current namespace
135
+		return FullyQualified::concat($this->namespace, $name, $name->getAttributes());
136
+	}
137
+
138
+	/**
139
+	 * Get resolved class name.
140
+	 *
141
+	 * @param Name $name Class ame to resolve
142
+	 *
143
+	 * @return Name Resolved name
144
+	 */
145
+	public function getResolvedClassName(Name $name) : Name {
146
+		return $this->getResolvedName($name, Stmt\Use_::TYPE_NORMAL);
147
+	}
148
+
149
+	/**
150
+	 * Get possible ways of writing a fully qualified name (e.g., by making use of aliases).
151
+	 *
152
+	 * @param string $name Fully-qualified name (without leading namespace separator)
153
+	 * @param int    $type One of Stmt\Use_::TYPE_*
154
+	 *
155
+	 * @return Name[] Possible representations of the name
156
+	 */
157
+	public function getPossibleNames(string $name, int $type) : array {
158
+		$lcName = strtolower($name);
159
+
160
+		if ($type === Stmt\Use_::TYPE_NORMAL) {
161
+			// self, parent and static must always be unqualified
162
+			if ($lcName === "self" || $lcName === "parent" || $lcName === "static") {
163
+				return [new Name($name)];
164
+			}
165
+		}
166
+
167
+		// Collect possible ways to write this name, starting with the fully-qualified name
168
+		$possibleNames = [new FullyQualified($name)];
169
+
170
+		if (null !== $nsRelativeName = $this->getNamespaceRelativeName($name, $lcName, $type)) {
171
+			// Make sure there is no alias that makes the normally namespace-relative name
172
+			// into something else
173
+			if (null === $this->resolveAlias($nsRelativeName, $type)) {
174
+				$possibleNames[] = $nsRelativeName;
175
+			}
176
+		}
177
+
178
+		// Check for relevant namespace use statements
179
+		foreach ($this->origAliases[Stmt\Use_::TYPE_NORMAL] as $alias => $orig) {
180
+			$lcOrig = $orig->toLowerString();
181
+			if (0 === strpos($lcName, $lcOrig . '\\')) {
182
+				$possibleNames[] = new Name($alias . substr($name, strlen($lcOrig)));
183
+			}
184
+		}
185
+
186
+		// Check for relevant type-specific use statements
187
+		foreach ($this->origAliases[$type] as $alias => $orig) {
188
+			if ($type === Stmt\Use_::TYPE_CONSTANT) {
189
+				// Constants are are complicated-sensitive
190
+				$normalizedOrig = $this->normalizeConstName($orig->toString());
191
+				if ($normalizedOrig === $this->normalizeConstName($name)) {
192
+					$possibleNames[] = new Name($alias);
193
+				}
194
+			} else {
195
+				// Everything else is case-insensitive
196
+				if ($orig->toLowerString() === $lcName) {
197
+					$possibleNames[] = new Name($alias);
198
+				}
199
+			}
200
+		}
201
+
202
+		return $possibleNames;
203
+	}
204
+
205
+	/**
206
+	 * Get shortest representation of this fully-qualified name.
207
+	 *
208
+	 * @param string $name Fully-qualified name (without leading namespace separator)
209
+	 * @param int    $type One of Stmt\Use_::TYPE_*
210
+	 *
211
+	 * @return Name Shortest representation
212
+	 */
213
+	public function getShortName(string $name, int $type) : Name {
214
+		$possibleNames = $this->getPossibleNames($name, $type);
215
+
216
+		// Find shortest name
217
+		$shortestName = null;
218
+		$shortestLength = \INF;
219
+		foreach ($possibleNames as $possibleName) {
220
+			$length = strlen($possibleName->toCodeString());
221
+			if ($length < $shortestLength) {
222
+				$shortestName = $possibleName;
223
+				$shortestLength = $length;
224
+			}
225
+		}
226
+
227
+	   return $shortestName;
228
+	}
229
+
230
+	private function resolveAlias(Name $name, $type) {
231
+		$firstPart = $name->getFirst();
232
+
233
+		if ($name->isQualified()) {
234
+			// resolve aliases for qualified names, always against class alias table
235
+			$checkName = strtolower($firstPart);
236
+			if (isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName])) {
237
+				$alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$checkName];
238
+				return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes());
239
+			}
240
+		} elseif ($name->isUnqualified()) {
241
+			// constant aliases are case-sensitive, function aliases case-insensitive
242
+			$checkName = $type === Stmt\Use_::TYPE_CONSTANT ? $firstPart : strtolower($firstPart);
243
+			if (isset($this->aliases[$type][$checkName])) {
244
+				// resolve unqualified aliases
245
+				return new FullyQualified($this->aliases[$type][$checkName], $name->getAttributes());
246
+			}
247
+		}
248
+
249
+		// No applicable aliases
250
+		return null;
251
+	}
252
+
253
+	private function getNamespaceRelativeName(string $name, string $lcName, int $type) {
254
+		if (null === $this->namespace) {
255
+			return new Name($name);
256
+		}
257
+
258
+		if ($type === Stmt\Use_::TYPE_CONSTANT) {
259
+			// The constants true/false/null always resolve to the global symbols, even inside a
260
+			// namespace, so they may be used without qualification
261
+			if ($lcName === "true" || $lcName === "false" || $lcName === "null") {
262
+				return new Name($name);
263
+			}
264
+		}
265
+
266
+		$namespacePrefix = strtolower($this->namespace . '\\');
267
+		if (0 === strpos($lcName, $namespacePrefix)) {
268
+			return new Name(substr($name, strlen($namespacePrefix)));
269
+		}
270
+
271
+		return null;
272
+	}
273
+
274
+	private function normalizeConstName(string $name) {
275
+		$nsSep = strrpos($name, '\\');
276
+		if (false === $nsSep) {
277
+			return $name;
278
+		}
279
+
280
+		// Constants have case-insensitive namespace and case-sensitive short-name
281
+		$ns = substr($name, 0, $nsSep);
282
+		$shortName = substr($name, $nsSep + 1);
283
+		return strtolower($ns) . '\\' . $shortName;
284
+	}
285 285
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         // Check for relevant namespace use statements
179 179
         foreach ($this->origAliases[Stmt\Use_::TYPE_NORMAL] as $alias => $orig) {
180 180
             $lcOrig = $orig->toLowerString();
181
-            if (0 === strpos($lcName, $lcOrig . '\\')) {
182
-                $possibleNames[] = new Name($alias . substr($name, strlen($lcOrig)));
181
+            if (0 === strpos($lcName, $lcOrig.'\\')) {
182
+                $possibleNames[] = new Name($alias.substr($name, strlen($lcOrig)));
183 183
             }
184 184
         }
185 185
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
             }
264 264
         }
265 265
 
266
-        $namespacePrefix = strtolower($this->namespace . '\\');
266
+        $namespacePrefix = strtolower($this->namespace.'\\');
267 267
         if (0 === strpos($lcName, $namespacePrefix)) {
268 268
             return new Name(substr($name, strlen($namespacePrefix)));
269 269
         }
@@ -280,6 +280,6 @@  discard block
 block discarded – undo
280 280
         // Constants have case-insensitive namespace and case-sensitive short-name
281 281
         $ns = substr($name, 0, $nsSep);
282 282
         $shortName = substr($name, $nsSep + 1);
283
-        return strtolower($ns) . '\\' . $shortName;
283
+        return strtolower($ns).'\\'.$shortName;
284 284
     }
285 285
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,7 @@
 block discarded – undo
6 6
 use PhpParser\Node\Name\FullyQualified;
7 7
 use PhpParser\Node\Stmt;
8 8
 
9
-class NameContext
10
-{
9
+class NameContext {
11 10
     /** @var null|Name Current namespace */
12 11
     protected $namespace;
13 12
 
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@
 block discarded – undo
7 7
  */
8 8
 class NodeVisitorAbstract implements NodeVisitor
9 9
 {
10
-    public function beforeTraverse(array $nodes) {
11
-        return null;
12
-    }
10
+	public function beforeTraverse(array $nodes) {
11
+		return null;
12
+	}
13 13
 
14
-    public function enterNode(Node $node) {
15
-        return null;
16
-    }
14
+	public function enterNode(Node $node) {
15
+		return null;
16
+	}
17 17
 
18
-    public function leaveNode(Node $node) {
19
-        return null;
20
-    }
18
+	public function leaveNode(Node $node) {
19
+		return null;
20
+	}
21 21
 
22
-    public function afterTraverse(array $nodes) {
23
-        return null;
24
-    }
22
+	public function afterTraverse(array $nodes) {
23
+		return null;
24
+	}
25 25
 }
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
  * @codeCoverageIgnore
7 7
  */
8
-class NodeVisitorAbstract implements NodeVisitor
9
-{
8
+class NodeVisitorAbstract implements NodeVisitor {
10 9
     public function beforeTraverse(array $nodes) {
11 10
         return null;
12 11
     }
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/Comment.php 2 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -4,236 +4,236 @@
 block discarded – undo
4 4
 
5 5
 class Comment implements \JsonSerializable
6 6
 {
7
-    protected $text;
8
-    protected $startLine;
9
-    protected $startFilePos;
10
-    protected $startTokenPos;
11
-    protected $endLine;
12
-    protected $endFilePos;
13
-    protected $endTokenPos;
14
-
15
-    /**
16
-     * Constructs a comment node.
17
-     *
18
-     * @param string $text          Comment text (including comment delimiters like /*)
19
-     * @param int    $startLine     Line number the comment started on
20
-     * @param int    $startFilePos  File offset the comment started on
21
-     * @param int    $startTokenPos Token offset the comment started on
22
-     */
23
-    public function __construct(
24
-        string $text,
25
-        int $startLine = -1, int $startFilePos = -1, int $startTokenPos = -1,
26
-        int $endLine = -1, int $endFilePos = -1, int $endTokenPos = -1
27
-    ) {
28
-        $this->text = $text;
29
-        $this->startLine = $startLine;
30
-        $this->startFilePos = $startFilePos;
31
-        $this->startTokenPos = $startTokenPos;
32
-        $this->endLine = $endLine;
33
-        $this->endFilePos = $endFilePos;
34
-        $this->endTokenPos = $endTokenPos;
35
-    }
36
-
37
-    /**
38
-     * Gets the comment text.
39
-     *
40
-     * @return string The comment text (including comment delimiters like /*)
41
-     */
42
-    public function getText() : string {
43
-        return $this->text;
44
-    }
45
-
46
-    /**
47
-     * Gets the line number the comment started on.
48
-     *
49
-     * @return int Line number (or -1 if not available)
50
-     */
51
-    public function getStartLine() : int {
52
-        return $this->startLine;
53
-    }
54
-
55
-    /**
56
-     * Gets the file offset the comment started on.
57
-     *
58
-     * @return int File offset (or -1 if not available)
59
-     */
60
-    public function getStartFilePos() : int {
61
-        return $this->startFilePos;
62
-    }
63
-
64
-    /**
65
-     * Gets the token offset the comment started on.
66
-     *
67
-     * @return int Token offset (or -1 if not available)
68
-     */
69
-    public function getStartTokenPos() : int {
70
-        return $this->startTokenPos;
71
-    }
72
-
73
-    /**
74
-     * Gets the line number the comment ends on.
75
-     *
76
-     * @return int Line number (or -1 if not available)
77
-     */
78
-    public function getEndLine() : int {
79
-        return $this->endLine;
80
-    }
81
-
82
-    /**
83
-     * Gets the file offset the comment ends on.
84
-     *
85
-     * @return int File offset (or -1 if not available)
86
-     */
87
-    public function getEndFilePos() : int {
88
-        return $this->endFilePos;
89
-    }
90
-
91
-    /**
92
-     * Gets the token offset the comment ends on.
93
-     *
94
-     * @return int Token offset (or -1 if not available)
95
-     */
96
-    public function getEndTokenPos() : int {
97
-        return $this->endTokenPos;
98
-    }
99
-
100
-    /**
101
-     * Gets the line number the comment started on.
102
-     *
103
-     * @deprecated Use getStartLine() instead
104
-     *
105
-     * @return int Line number
106
-     */
107
-    public function getLine() : int {
108
-        return $this->startLine;
109
-    }
110
-
111
-    /**
112
-     * Gets the file offset the comment started on.
113
-     *
114
-     * @deprecated Use getStartFilePos() instead
115
-     *
116
-     * @return int File offset
117
-     */
118
-    public function getFilePos() : int {
119
-        return $this->startFilePos;
120
-    }
121
-
122
-    /**
123
-     * Gets the token offset the comment started on.
124
-     *
125
-     * @deprecated Use getStartTokenPos() instead
126
-     *
127
-     * @return int Token offset
128
-     */
129
-    public function getTokenPos() : int {
130
-        return $this->startTokenPos;
131
-    }
132
-
133
-    /**
134
-     * Gets the comment text.
135
-     *
136
-     * @return string The comment text (including comment delimiters like /*)
137
-     */
138
-    public function __toString() : string {
139
-        return $this->text;
140
-    }
141
-
142
-    /**
143
-     * Gets the reformatted comment text.
144
-     *
145
-     * "Reformatted" here means that we try to clean up the whitespace at the
146
-     * starts of the lines. This is necessary because we receive the comments
147
-     * without trailing whitespace on the first line, but with trailing whitespace
148
-     * on all subsequent lines.
149
-     *
150
-     * @return mixed|string
151
-     */
152
-    public function getReformattedText() {
153
-        $text = trim($this->text);
154
-        $newlinePos = strpos($text, "\n");
155
-        if (false === $newlinePos) {
156
-            // Single line comments don't need further processing
157
-            return $text;
158
-        } elseif (preg_match('((*BSR_ANYCRLF)(*ANYCRLF)^.*(?:\R\s+\*.*)+$)', $text)) {
159
-            // Multi line comment of the type
160
-            //
161
-            //     /*
162
-            //      * Some text.
163
-            //      * Some more text.
164
-            //      */
165
-            //
166
-            // is handled by replacing the whitespace sequences before the * by a single space
167
-            return preg_replace('(^\s+\*)m', ' *', $this->text);
168
-        } elseif (preg_match('(^/\*\*?\s*[\r\n])', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) {
169
-            // Multi line comment of the type
170
-            //
171
-            //    /*
172
-            //        Some text.
173
-            //        Some more text.
174
-            //    */
175
-            //
176
-            // is handled by removing the whitespace sequence on the line before the closing
177
-            // */ on all lines. So if the last line is "    */", then "    " is removed at the
178
-            // start of all lines.
179
-            return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text);
180
-        } elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) {
181
-            // Multi line comment of the type
182
-            //
183
-            //     /* Some text.
184
-            //        Some more text.
185
-            //          Indented text.
186
-            //        Even more text. */
187
-            //
188
-            // is handled by removing the difference between the shortest whitespace prefix on all
189
-            // lines and the length of the "/* " opening sequence.
190
-            $prefixLen = $this->getShortestWhitespacePrefixLen(substr($text, $newlinePos + 1));
191
-            $removeLen = $prefixLen - strlen($matches[0]);
192
-            return preg_replace('(^\s{' . $removeLen . '})m', '', $text);
193
-        }
194
-
195
-        // No idea how to format this comment, so simply return as is
196
-        return $text;
197
-    }
198
-
199
-    /**
200
-     * Get length of shortest whitespace prefix (at the start of a line).
201
-     *
202
-     * If there is a line with no prefix whitespace, 0 is a valid return value.
203
-     *
204
-     * @param string $str String to check
205
-     * @return int Length in characters. Tabs count as single characters.
206
-     */
207
-    private function getShortestWhitespacePrefixLen(string $str) : int {
208
-        $lines = explode("\n", $str);
209
-        $shortestPrefixLen = \INF;
210
-        foreach ($lines as $line) {
211
-            preg_match('(^\s*)', $line, $matches);
212
-            $prefixLen = strlen($matches[0]);
213
-            if ($prefixLen < $shortestPrefixLen) {
214
-                $shortestPrefixLen = $prefixLen;
215
-            }
216
-        }
217
-        return $shortestPrefixLen;
218
-    }
219
-
220
-    /**
221
-     * @return       array
222
-     * @psalm-return array{nodeType:string, text:mixed, line:mixed, filePos:mixed}
223
-     */
224
-    public function jsonSerialize() : array {
225
-        // Technically not a node, but we make it look like one anyway
226
-        $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment';
227
-        return [
228
-            'nodeType' => $type,
229
-            'text' => $this->text,
230
-            // TODO: Rename these to include "start".
231
-            'line' => $this->startLine,
232
-            'filePos' => $this->startFilePos,
233
-            'tokenPos' => $this->startTokenPos,
234
-            'endLine' => $this->endLine,
235
-            'endFilePos' => $this->endFilePos,
236
-            'endTokenPos' => $this->endTokenPos,
237
-        ];
238
-    }
7
+	protected $text;
8
+	protected $startLine;
9
+	protected $startFilePos;
10
+	protected $startTokenPos;
11
+	protected $endLine;
12
+	protected $endFilePos;
13
+	protected $endTokenPos;
14
+
15
+	/**
16
+	 * Constructs a comment node.
17
+	 *
18
+	 * @param string $text          Comment text (including comment delimiters like /*)
19
+	 * @param int    $startLine     Line number the comment started on
20
+	 * @param int    $startFilePos  File offset the comment started on
21
+	 * @param int    $startTokenPos Token offset the comment started on
22
+	 */
23
+	public function __construct(
24
+		string $text,
25
+		int $startLine = -1, int $startFilePos = -1, int $startTokenPos = -1,
26
+		int $endLine = -1, int $endFilePos = -1, int $endTokenPos = -1
27
+	) {
28
+		$this->text = $text;
29
+		$this->startLine = $startLine;
30
+		$this->startFilePos = $startFilePos;
31
+		$this->startTokenPos = $startTokenPos;
32
+		$this->endLine = $endLine;
33
+		$this->endFilePos = $endFilePos;
34
+		$this->endTokenPos = $endTokenPos;
35
+	}
36
+
37
+	/**
38
+	 * Gets the comment text.
39
+	 *
40
+	 * @return string The comment text (including comment delimiters like /*)
41
+	 */
42
+	public function getText() : string {
43
+		return $this->text;
44
+	}
45
+
46
+	/**
47
+	 * Gets the line number the comment started on.
48
+	 *
49
+	 * @return int Line number (or -1 if not available)
50
+	 */
51
+	public function getStartLine() : int {
52
+		return $this->startLine;
53
+	}
54
+
55
+	/**
56
+	 * Gets the file offset the comment started on.
57
+	 *
58
+	 * @return int File offset (or -1 if not available)
59
+	 */
60
+	public function getStartFilePos() : int {
61
+		return $this->startFilePos;
62
+	}
63
+
64
+	/**
65
+	 * Gets the token offset the comment started on.
66
+	 *
67
+	 * @return int Token offset (or -1 if not available)
68
+	 */
69
+	public function getStartTokenPos() : int {
70
+		return $this->startTokenPos;
71
+	}
72
+
73
+	/**
74
+	 * Gets the line number the comment ends on.
75
+	 *
76
+	 * @return int Line number (or -1 if not available)
77
+	 */
78
+	public function getEndLine() : int {
79
+		return $this->endLine;
80
+	}
81
+
82
+	/**
83
+	 * Gets the file offset the comment ends on.
84
+	 *
85
+	 * @return int File offset (or -1 if not available)
86
+	 */
87
+	public function getEndFilePos() : int {
88
+		return $this->endFilePos;
89
+	}
90
+
91
+	/**
92
+	 * Gets the token offset the comment ends on.
93
+	 *
94
+	 * @return int Token offset (or -1 if not available)
95
+	 */
96
+	public function getEndTokenPos() : int {
97
+		return $this->endTokenPos;
98
+	}
99
+
100
+	/**
101
+	 * Gets the line number the comment started on.
102
+	 *
103
+	 * @deprecated Use getStartLine() instead
104
+	 *
105
+	 * @return int Line number
106
+	 */
107
+	public function getLine() : int {
108
+		return $this->startLine;
109
+	}
110
+
111
+	/**
112
+	 * Gets the file offset the comment started on.
113
+	 *
114
+	 * @deprecated Use getStartFilePos() instead
115
+	 *
116
+	 * @return int File offset
117
+	 */
118
+	public function getFilePos() : int {
119
+		return $this->startFilePos;
120
+	}
121
+
122
+	/**
123
+	 * Gets the token offset the comment started on.
124
+	 *
125
+	 * @deprecated Use getStartTokenPos() instead
126
+	 *
127
+	 * @return int Token offset
128
+	 */
129
+	public function getTokenPos() : int {
130
+		return $this->startTokenPos;
131
+	}
132
+
133
+	/**
134
+	 * Gets the comment text.
135
+	 *
136
+	 * @return string The comment text (including comment delimiters like /*)
137
+	 */
138
+	public function __toString() : string {
139
+		return $this->text;
140
+	}
141
+
142
+	/**
143
+	 * Gets the reformatted comment text.
144
+	 *
145
+	 * "Reformatted" here means that we try to clean up the whitespace at the
146
+	 * starts of the lines. This is necessary because we receive the comments
147
+	 * without trailing whitespace on the first line, but with trailing whitespace
148
+	 * on all subsequent lines.
149
+	 *
150
+	 * @return mixed|string
151
+	 */
152
+	public function getReformattedText() {
153
+		$text = trim($this->text);
154
+		$newlinePos = strpos($text, "\n");
155
+		if (false === $newlinePos) {
156
+			// Single line comments don't need further processing
157
+			return $text;
158
+		} elseif (preg_match('((*BSR_ANYCRLF)(*ANYCRLF)^.*(?:\R\s+\*.*)+$)', $text)) {
159
+			// Multi line comment of the type
160
+			//
161
+			//     /*
162
+			//      * Some text.
163
+			//      * Some more text.
164
+			//      */
165
+			//
166
+			// is handled by replacing the whitespace sequences before the * by a single space
167
+			return preg_replace('(^\s+\*)m', ' *', $this->text);
168
+		} elseif (preg_match('(^/\*\*?\s*[\r\n])', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) {
169
+			// Multi line comment of the type
170
+			//
171
+			//    /*
172
+			//        Some text.
173
+			//        Some more text.
174
+			//    */
175
+			//
176
+			// is handled by removing the whitespace sequence on the line before the closing
177
+			// */ on all lines. So if the last line is "    */", then "    " is removed at the
178
+			// start of all lines.
179
+			return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text);
180
+		} elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) {
181
+			// Multi line comment of the type
182
+			//
183
+			//     /* Some text.
184
+			//        Some more text.
185
+			//          Indented text.
186
+			//        Even more text. */
187
+			//
188
+			// is handled by removing the difference between the shortest whitespace prefix on all
189
+			// lines and the length of the "/* " opening sequence.
190
+			$prefixLen = $this->getShortestWhitespacePrefixLen(substr($text, $newlinePos + 1));
191
+			$removeLen = $prefixLen - strlen($matches[0]);
192
+			return preg_replace('(^\s{' . $removeLen . '})m', '', $text);
193
+		}
194
+
195
+		// No idea how to format this comment, so simply return as is
196
+		return $text;
197
+	}
198
+
199
+	/**
200
+	 * Get length of shortest whitespace prefix (at the start of a line).
201
+	 *
202
+	 * If there is a line with no prefix whitespace, 0 is a valid return value.
203
+	 *
204
+	 * @param string $str String to check
205
+	 * @return int Length in characters. Tabs count as single characters.
206
+	 */
207
+	private function getShortestWhitespacePrefixLen(string $str) : int {
208
+		$lines = explode("\n", $str);
209
+		$shortestPrefixLen = \INF;
210
+		foreach ($lines as $line) {
211
+			preg_match('(^\s*)', $line, $matches);
212
+			$prefixLen = strlen($matches[0]);
213
+			if ($prefixLen < $shortestPrefixLen) {
214
+				$shortestPrefixLen = $prefixLen;
215
+			}
216
+		}
217
+		return $shortestPrefixLen;
218
+	}
219
+
220
+	/**
221
+	 * @return       array
222
+	 * @psalm-return array{nodeType:string, text:mixed, line:mixed, filePos:mixed}
223
+	 */
224
+	public function jsonSerialize() : array {
225
+		// Technically not a node, but we make it look like one anyway
226
+		$type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment';
227
+		return [
228
+			'nodeType' => $type,
229
+			'text' => $this->text,
230
+			// TODO: Rename these to include "start".
231
+			'line' => $this->startLine,
232
+			'filePos' => $this->startFilePos,
233
+			'tokenPos' => $this->startTokenPos,
234
+			'endLine' => $this->endLine,
235
+			'endFilePos' => $this->endFilePos,
236
+			'endTokenPos' => $this->endTokenPos,
237
+		];
238
+	}
239 239
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
             // is handled by removing the whitespace sequence on the line before the closing
177 177
             // */ on all lines. So if the last line is "    */", then "    " is removed at the
178 178
             // start of all lines.
179
-            return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text);
179
+            return preg_replace('(^'.preg_quote($matches[1]).')m', '', $text);
180 180
         } elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) {
181 181
             // Multi line comment of the type
182 182
             //
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
             // lines and the length of the "/* " opening sequence.
190 190
             $prefixLen = $this->getShortestWhitespacePrefixLen(substr($text, $newlinePos + 1));
191 191
             $removeLen = $prefixLen - strlen($matches[0]);
192
-            return preg_replace('(^\s{' . $removeLen . '})m', '', $text);
192
+            return preg_replace('(^\s{'.$removeLen.'})m', '', $text);
193 193
         }
194 194
 
195 195
         // No idea how to format this comment, so simply return as is
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php 3 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -17,319 +17,319 @@
 block discarded – undo
17 17
  */
18 18
 final class BuilderHelpers
19 19
 {
20
-    /**
21
-     * Normalizes a node: Converts builder objects to nodes.
22
-     *
23
-     * @param Node|Builder $node The node to normalize
24
-     *
25
-     * @return Node The normalized node
26
-     */
27
-    public static function normalizeNode($node) : Node {
28
-        if ($node instanceof Builder) {
29
-            return $node->getNode();
30
-        }
31
-
32
-        if ($node instanceof Node) {
33
-            return $node;
34
-        }
35
-
36
-        throw new \LogicException('Expected node or builder object');
37
-    }
38
-
39
-    /**
40
-     * Normalizes a node to a statement.
41
-     *
42
-     * Expressions are wrapped in a Stmt\Expression node.
43
-     *
44
-     * @param Node|Builder $node The node to normalize
45
-     *
46
-     * @return Stmt The normalized statement node
47
-     */
48
-    public static function normalizeStmt($node) : Stmt {
49
-        $node = self::normalizeNode($node);
50
-        if ($node instanceof Stmt) {
51
-            return $node;
52
-        }
53
-
54
-        if ($node instanceof Expr) {
55
-            return new Stmt\Expression($node);
56
-        }
57
-
58
-        throw new \LogicException('Expected statement or expression node');
59
-    }
60
-
61
-    /**
62
-     * Normalizes strings to Identifier.
63
-     *
64
-     * @param string|Identifier $name The identifier to normalize
65
-     *
66
-     * @return Identifier The normalized identifier
67
-     */
68
-    public static function normalizeIdentifier($name) : Identifier {
69
-        if ($name instanceof Identifier) {
70
-            return $name;
71
-        }
72
-
73
-        if (\is_string($name)) {
74
-            return new Identifier($name);
75
-        }
76
-
77
-        throw new \LogicException('Expected string or instance of Node\Identifier');
78
-    }
79
-
80
-    /**
81
-     * Normalizes strings to Identifier, also allowing expressions.
82
-     *
83
-     * @param string|Identifier|Expr $name The identifier to normalize
84
-     *
85
-     * @return Identifier|Expr The normalized identifier or expression
86
-     */
87
-    public static function normalizeIdentifierOrExpr($name) {
88
-        if ($name instanceof Identifier || $name instanceof Expr) {
89
-            return $name;
90
-        }
91
-
92
-        if (\is_string($name)) {
93
-            return new Identifier($name);
94
-        }
95
-
96
-        throw new \LogicException('Expected string or instance of Node\Identifier or Node\Expr');
97
-    }
98
-
99
-    /**
100
-     * Normalizes a name: Converts string names to Name nodes.
101
-     *
102
-     * @param Name|string $name The name to normalize
103
-     *
104
-     * @return Name The normalized name
105
-     */
106
-    public static function normalizeName($name) : Name {
107
-        if ($name instanceof Name) {
108
-            return $name;
109
-        }
110
-
111
-        if (is_string($name)) {
112
-            if (!$name) {
113
-                throw new \LogicException('Name cannot be empty');
114
-            }
115
-
116
-            if ($name[0] === '\\') {
117
-                return new Name\FullyQualified(substr($name, 1));
118
-            }
119
-
120
-            if (0 === strpos($name, 'namespace\\')) {
121
-                return new Name\Relative(substr($name, strlen('namespace\\')));
122
-            }
123
-
124
-            return new Name($name);
125
-        }
126
-
127
-        throw new \LogicException('Name must be a string or an instance of Node\Name');
128
-    }
129
-
130
-    /**
131
-     * Normalizes a name: Converts string names to Name nodes, while also allowing expressions.
132
-     *
133
-     * @param Expr|Name|string $name The name to normalize
134
-     *
135
-     * @return Name|Expr The normalized name or expression
136
-     */
137
-    public static function normalizeNameOrExpr($name) {
138
-        if ($name instanceof Expr) {
139
-            return $name;
140
-        }
141
-
142
-        if (!is_string($name) && !($name instanceof Name)) {
143
-            throw new \LogicException(
144
-                'Name must be a string or an instance of Node\Name or Node\Expr'
145
-            );
146
-        }
147
-
148
-        return self::normalizeName($name);
149
-    }
150
-
151
-    /**
152
-     * Normalizes a type: Converts plain-text type names into proper AST representation.
153
-     *
154
-     * In particular, builtin types become Identifiers, custom types become Names and nullables
155
-     * are wrapped in NullableType nodes.
156
-     *
157
-     * @param string|Name|Identifier|ComplexType $type The type to normalize
158
-     *
159
-     * @return Name|Identifier|ComplexType The normalized type
160
-     */
161
-    public static function normalizeType($type) {
162
-        if (!is_string($type)) {
163
-            if (
164
-                !$type instanceof Name && !$type instanceof Identifier &&
165
-                !$type instanceof ComplexType
166
-            ) {
167
-                throw new \LogicException(
168
-                    'Type must be a string, or an instance of Name, Identifier or ComplexType'
169
-                );
170
-            }
171
-            return $type;
172
-        }
173
-
174
-        $nullable = false;
175
-        if (strlen($type) > 0 && $type[0] === '?') {
176
-            $nullable = true;
177
-            $type = substr($type, 1);
178
-        }
179
-
180
-        $builtinTypes = [
181
-            'array',
182
-            'callable',
183
-            'bool',
184
-            'int',
185
-            'float',
186
-            'string',
187
-            'iterable',
188
-            'void',
189
-            'object',
190
-            'null',
191
-            'false',
192
-            'mixed',
193
-            'never',
194
-            'true',
195
-        ];
196
-
197
-        $lowerType = strtolower($type);
198
-        if (in_array($lowerType, $builtinTypes)) {
199
-            $type = new Identifier($lowerType);
200
-        } else {
201
-            $type = self::normalizeName($type);
202
-        }
203
-
204
-        $notNullableTypes = [
205
-            'void', 'mixed', 'never',
206
-        ];
207
-        if ($nullable && in_array((string) $type, $notNullableTypes)) {
208
-            throw new \LogicException(sprintf('%s type cannot be nullable', $type));
209
-        }
210
-
211
-        return $nullable ? new NullableType($type) : $type;
212
-    }
213
-
214
-    /**
215
-     * Normalizes a value: Converts nulls, booleans, integers,
216
-     * floats, strings and arrays into their respective nodes
217
-     *
218
-     * @param Node\Expr|bool|null|int|float|string|array $value The value to normalize
219
-     *
220
-     * @return Expr The normalized value
221
-     */
222
-    public static function normalizeValue($value) : Expr {
223
-        if ($value instanceof Node\Expr) {
224
-            return $value;
225
-        }
226
-
227
-        if (is_null($value)) {
228
-            return new Expr\ConstFetch(
229
-                new Name('null')
230
-            );
231
-        }
232
-
233
-        if (is_bool($value)) {
234
-            return new Expr\ConstFetch(
235
-                new Name($value ? 'true' : 'false')
236
-            );
237
-        }
238
-
239
-        if (is_int($value)) {
240
-            return new Scalar\LNumber($value);
241
-        }
242
-
243
-        if (is_float($value)) {
244
-            return new Scalar\DNumber($value);
245
-        }
246
-
247
-        if (is_string($value)) {
248
-            return new Scalar\String_($value);
249
-        }
250
-
251
-        if (is_array($value)) {
252
-            $items = [];
253
-            $lastKey = -1;
254
-            foreach ($value as $itemKey => $itemValue) {
255
-                // for consecutive, numeric keys don't generate keys
256
-                if (null !== $lastKey && ++$lastKey === $itemKey) {
257
-                    $items[] = new Expr\ArrayItem(
258
-                        self::normalizeValue($itemValue)
259
-                    );
260
-                } else {
261
-                    $lastKey = null;
262
-                    $items[] = new Expr\ArrayItem(
263
-                        self::normalizeValue($itemValue),
264
-                        self::normalizeValue($itemKey)
265
-                    );
266
-                }
267
-            }
268
-
269
-            return new Expr\Array_($items);
270
-        }
271
-
272
-        throw new \LogicException('Invalid value');
273
-    }
274
-
275
-    /**
276
-     * Normalizes a doc comment: Converts plain strings to PhpParser\Comment\Doc.
277
-     *
278
-     * @param Comment\Doc|string $docComment The doc comment to normalize
279
-     *
280
-     * @return Comment\Doc The normalized doc comment
281
-     */
282
-    public static function normalizeDocComment($docComment) : Comment\Doc {
283
-        if ($docComment instanceof Comment\Doc) {
284
-            return $docComment;
285
-        }
286
-
287
-        if (is_string($docComment)) {
288
-            return new Comment\Doc($docComment);
289
-        }
290
-
291
-        throw new \LogicException('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
292
-    }
293
-
294
-    /**
295
-     * Normalizes a attribute: Converts attribute to the Attribute Group if needed.
296
-     *
297
-     * @param Node\Attribute|Node\AttributeGroup $attribute
298
-     *
299
-     * @return Node\AttributeGroup The Attribute Group
300
-     */
301
-    public static function normalizeAttribute($attribute) : Node\AttributeGroup
302
-    {
303
-        if ($attribute instanceof Node\AttributeGroup) {
304
-            return $attribute;
305
-        }
306
-
307
-        if (!($attribute instanceof Node\Attribute)) {
308
-            throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup');
309
-        }
310
-
311
-        return new Node\AttributeGroup([$attribute]);
312
-    }
313
-
314
-    /**
315
-     * Adds a modifier and returns new modifier bitmask.
316
-     *
317
-     * @param int $modifiers Existing modifiers
318
-     * @param int $modifier  Modifier to set
319
-     *
320
-     * @return int New modifiers
321
-     */
322
-    public static function addModifier(int $modifiers, int $modifier) : int {
323
-        Stmt\Class_::verifyModifier($modifiers, $modifier);
324
-        return $modifiers | $modifier;
325
-    }
326
-
327
-    /**
328
-     * Adds a modifier and returns new modifier bitmask.
329
-     * @return int New modifiers
330
-     */
331
-    public static function addClassModifier(int $existingModifiers, int $modifierToSet) : int {
332
-        Stmt\Class_::verifyClassModifier($existingModifiers, $modifierToSet);
333
-        return $existingModifiers | $modifierToSet;
334
-    }
20
+	/**
21
+	 * Normalizes a node: Converts builder objects to nodes.
22
+	 *
23
+	 * @param Node|Builder $node The node to normalize
24
+	 *
25
+	 * @return Node The normalized node
26
+	 */
27
+	public static function normalizeNode($node) : Node {
28
+		if ($node instanceof Builder) {
29
+			return $node->getNode();
30
+		}
31
+
32
+		if ($node instanceof Node) {
33
+			return $node;
34
+		}
35
+
36
+		throw new \LogicException('Expected node or builder object');
37
+	}
38
+
39
+	/**
40
+	 * Normalizes a node to a statement.
41
+	 *
42
+	 * Expressions are wrapped in a Stmt\Expression node.
43
+	 *
44
+	 * @param Node|Builder $node The node to normalize
45
+	 *
46
+	 * @return Stmt The normalized statement node
47
+	 */
48
+	public static function normalizeStmt($node) : Stmt {
49
+		$node = self::normalizeNode($node);
50
+		if ($node instanceof Stmt) {
51
+			return $node;
52
+		}
53
+
54
+		if ($node instanceof Expr) {
55
+			return new Stmt\Expression($node);
56
+		}
57
+
58
+		throw new \LogicException('Expected statement or expression node');
59
+	}
60
+
61
+	/**
62
+	 * Normalizes strings to Identifier.
63
+	 *
64
+	 * @param string|Identifier $name The identifier to normalize
65
+	 *
66
+	 * @return Identifier The normalized identifier
67
+	 */
68
+	public static function normalizeIdentifier($name) : Identifier {
69
+		if ($name instanceof Identifier) {
70
+			return $name;
71
+		}
72
+
73
+		if (\is_string($name)) {
74
+			return new Identifier($name);
75
+		}
76
+
77
+		throw new \LogicException('Expected string or instance of Node\Identifier');
78
+	}
79
+
80
+	/**
81
+	 * Normalizes strings to Identifier, also allowing expressions.
82
+	 *
83
+	 * @param string|Identifier|Expr $name The identifier to normalize
84
+	 *
85
+	 * @return Identifier|Expr The normalized identifier or expression
86
+	 */
87
+	public static function normalizeIdentifierOrExpr($name) {
88
+		if ($name instanceof Identifier || $name instanceof Expr) {
89
+			return $name;
90
+		}
91
+
92
+		if (\is_string($name)) {
93
+			return new Identifier($name);
94
+		}
95
+
96
+		throw new \LogicException('Expected string or instance of Node\Identifier or Node\Expr');
97
+	}
98
+
99
+	/**
100
+	 * Normalizes a name: Converts string names to Name nodes.
101
+	 *
102
+	 * @param Name|string $name The name to normalize
103
+	 *
104
+	 * @return Name The normalized name
105
+	 */
106
+	public static function normalizeName($name) : Name {
107
+		if ($name instanceof Name) {
108
+			return $name;
109
+		}
110
+
111
+		if (is_string($name)) {
112
+			if (!$name) {
113
+				throw new \LogicException('Name cannot be empty');
114
+			}
115
+
116
+			if ($name[0] === '\\') {
117
+				return new Name\FullyQualified(substr($name, 1));
118
+			}
119
+
120
+			if (0 === strpos($name, 'namespace\\')) {
121
+				return new Name\Relative(substr($name, strlen('namespace\\')));
122
+			}
123
+
124
+			return new Name($name);
125
+		}
126
+
127
+		throw new \LogicException('Name must be a string or an instance of Node\Name');
128
+	}
129
+
130
+	/**
131
+	 * Normalizes a name: Converts string names to Name nodes, while also allowing expressions.
132
+	 *
133
+	 * @param Expr|Name|string $name The name to normalize
134
+	 *
135
+	 * @return Name|Expr The normalized name or expression
136
+	 */
137
+	public static function normalizeNameOrExpr($name) {
138
+		if ($name instanceof Expr) {
139
+			return $name;
140
+		}
141
+
142
+		if (!is_string($name) && !($name instanceof Name)) {
143
+			throw new \LogicException(
144
+				'Name must be a string or an instance of Node\Name or Node\Expr'
145
+			);
146
+		}
147
+
148
+		return self::normalizeName($name);
149
+	}
150
+
151
+	/**
152
+	 * Normalizes a type: Converts plain-text type names into proper AST representation.
153
+	 *
154
+	 * In particular, builtin types become Identifiers, custom types become Names and nullables
155
+	 * are wrapped in NullableType nodes.
156
+	 *
157
+	 * @param string|Name|Identifier|ComplexType $type The type to normalize
158
+	 *
159
+	 * @return Name|Identifier|ComplexType The normalized type
160
+	 */
161
+	public static function normalizeType($type) {
162
+		if (!is_string($type)) {
163
+			if (
164
+				!$type instanceof Name && !$type instanceof Identifier &&
165
+				!$type instanceof ComplexType
166
+			) {
167
+				throw new \LogicException(
168
+					'Type must be a string, or an instance of Name, Identifier or ComplexType'
169
+				);
170
+			}
171
+			return $type;
172
+		}
173
+
174
+		$nullable = false;
175
+		if (strlen($type) > 0 && $type[0] === '?') {
176
+			$nullable = true;
177
+			$type = substr($type, 1);
178
+		}
179
+
180
+		$builtinTypes = [
181
+			'array',
182
+			'callable',
183
+			'bool',
184
+			'int',
185
+			'float',
186
+			'string',
187
+			'iterable',
188
+			'void',
189
+			'object',
190
+			'null',
191
+			'false',
192
+			'mixed',
193
+			'never',
194
+			'true',
195
+		];
196
+
197
+		$lowerType = strtolower($type);
198
+		if (in_array($lowerType, $builtinTypes)) {
199
+			$type = new Identifier($lowerType);
200
+		} else {
201
+			$type = self::normalizeName($type);
202
+		}
203
+
204
+		$notNullableTypes = [
205
+			'void', 'mixed', 'never',
206
+		];
207
+		if ($nullable && in_array((string) $type, $notNullableTypes)) {
208
+			throw new \LogicException(sprintf('%s type cannot be nullable', $type));
209
+		}
210
+
211
+		return $nullable ? new NullableType($type) : $type;
212
+	}
213
+
214
+	/**
215
+	 * Normalizes a value: Converts nulls, booleans, integers,
216
+	 * floats, strings and arrays into their respective nodes
217
+	 *
218
+	 * @param Node\Expr|bool|null|int|float|string|array $value The value to normalize
219
+	 *
220
+	 * @return Expr The normalized value
221
+	 */
222
+	public static function normalizeValue($value) : Expr {
223
+		if ($value instanceof Node\Expr) {
224
+			return $value;
225
+		}
226
+
227
+		if (is_null($value)) {
228
+			return new Expr\ConstFetch(
229
+				new Name('null')
230
+			);
231
+		}
232
+
233
+		if (is_bool($value)) {
234
+			return new Expr\ConstFetch(
235
+				new Name($value ? 'true' : 'false')
236
+			);
237
+		}
238
+
239
+		if (is_int($value)) {
240
+			return new Scalar\LNumber($value);
241
+		}
242
+
243
+		if (is_float($value)) {
244
+			return new Scalar\DNumber($value);
245
+		}
246
+
247
+		if (is_string($value)) {
248
+			return new Scalar\String_($value);
249
+		}
250
+
251
+		if (is_array($value)) {
252
+			$items = [];
253
+			$lastKey = -1;
254
+			foreach ($value as $itemKey => $itemValue) {
255
+				// for consecutive, numeric keys don't generate keys
256
+				if (null !== $lastKey && ++$lastKey === $itemKey) {
257
+					$items[] = new Expr\ArrayItem(
258
+						self::normalizeValue($itemValue)
259
+					);
260
+				} else {
261
+					$lastKey = null;
262
+					$items[] = new Expr\ArrayItem(
263
+						self::normalizeValue($itemValue),
264
+						self::normalizeValue($itemKey)
265
+					);
266
+				}
267
+			}
268
+
269
+			return new Expr\Array_($items);
270
+		}
271
+
272
+		throw new \LogicException('Invalid value');
273
+	}
274
+
275
+	/**
276
+	 * Normalizes a doc comment: Converts plain strings to PhpParser\Comment\Doc.
277
+	 *
278
+	 * @param Comment\Doc|string $docComment The doc comment to normalize
279
+	 *
280
+	 * @return Comment\Doc The normalized doc comment
281
+	 */
282
+	public static function normalizeDocComment($docComment) : Comment\Doc {
283
+		if ($docComment instanceof Comment\Doc) {
284
+			return $docComment;
285
+		}
286
+
287
+		if (is_string($docComment)) {
288
+			return new Comment\Doc($docComment);
289
+		}
290
+
291
+		throw new \LogicException('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
292
+	}
293
+
294
+	/**
295
+	 * Normalizes a attribute: Converts attribute to the Attribute Group if needed.
296
+	 *
297
+	 * @param Node\Attribute|Node\AttributeGroup $attribute
298
+	 *
299
+	 * @return Node\AttributeGroup The Attribute Group
300
+	 */
301
+	public static function normalizeAttribute($attribute) : Node\AttributeGroup
302
+	{
303
+		if ($attribute instanceof Node\AttributeGroup) {
304
+			return $attribute;
305
+		}
306
+
307
+		if (!($attribute instanceof Node\Attribute)) {
308
+			throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup');
309
+		}
310
+
311
+		return new Node\AttributeGroup([$attribute]);
312
+	}
313
+
314
+	/**
315
+	 * Adds a modifier and returns new modifier bitmask.
316
+	 *
317
+	 * @param int $modifiers Existing modifiers
318
+	 * @param int $modifier  Modifier to set
319
+	 *
320
+	 * @return int New modifiers
321
+	 */
322
+	public static function addModifier(int $modifiers, int $modifier) : int {
323
+		Stmt\Class_::verifyModifier($modifiers, $modifier);
324
+		return $modifiers | $modifier;
325
+	}
326
+
327
+	/**
328
+	 * Adds a modifier and returns new modifier bitmask.
329
+	 * @return int New modifiers
330
+	 */
331
+	public static function addClassModifier(int $existingModifiers, int $modifierToSet) : int {
332
+		Stmt\Class_::verifyClassModifier($existingModifiers, $modifierToSet);
333
+		return $existingModifiers | $modifierToSet;
334
+	}
335 335
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@
 block discarded – undo
204 204
         $notNullableTypes = [
205 205
             'void', 'mixed', 'never',
206 206
         ];
207
-        if ($nullable && in_array((string) $type, $notNullableTypes)) {
207
+        if ($nullable && in_array((string)$type, $notNullableTypes)) {
208 208
             throw new \LogicException(sprintf('%s type cannot be nullable', $type));
209 209
         }
210 210
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@
 block discarded – undo
15 15
  *
16 16
  * @internal
17 17
  */
18
-final class BuilderHelpers
19
-{
18
+final class BuilderHelpers {
20 19
     /**
21 20
      * Normalizes a node: Converts builder objects to nodes.
22 21
      *
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/NodeTraverserInterface.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 block discarded – undo
4 4
 
5 5
 interface NodeTraverserInterface
6 6
 {
7
-    /**
8
-     * Adds a visitor.
9
-     *
10
-     * @param NodeVisitor $visitor Visitor to add
11
-     */
12
-    public function addVisitor(NodeVisitor $visitor);
7
+	/**
8
+	 * Adds a visitor.
9
+	 *
10
+	 * @param NodeVisitor $visitor Visitor to add
11
+	 */
12
+	public function addVisitor(NodeVisitor $visitor);
13 13
 
14
-    /**
15
-     * Removes an added visitor.
16
-     *
17
-     * @param NodeVisitor $visitor
18
-     */
19
-    public function removeVisitor(NodeVisitor $visitor);
14
+	/**
15
+	 * Removes an added visitor.
16
+	 *
17
+	 * @param NodeVisitor $visitor
18
+	 */
19
+	public function removeVisitor(NodeVisitor $visitor);
20 20
 
21
-    /**
22
-     * Traverses an array of nodes using the registered visitors.
23
-     *
24
-     * @param Node[] $nodes Array of nodes
25
-     *
26
-     * @return Node[] Traversed array of nodes
27
-     */
28
-    public function traverse(array $nodes) : array;
21
+	/**
22
+	 * Traverses an array of nodes using the registered visitors.
23
+	 *
24
+	 * @param Node[] $nodes Array of nodes
25
+	 *
26
+	 * @return Node[] Traversed array of nodes
27
+	 */
28
+	public function traverse(array $nodes) : array;
29 29
 }
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
-interface NodeTraverserInterface
6
-{
5
+interface NodeTraverserInterface {
7 6
     /**
8 7
      * Adds a visitor.
9 8
      *
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php 3 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -10,197 +10,197 @@
 block discarded – undo
10 10
 
11 11
 class NodeDumper
12 12
 {
13
-    private $dumpComments;
14
-    private $dumpPositions;
15
-    private $code;
16
-
17
-    /**
18
-     * Constructs a NodeDumper.
19
-     *
20
-     * Supported options:
21
-     *  * bool dumpComments: Whether comments should be dumped.
22
-     *  * bool dumpPositions: Whether line/offset information should be dumped. To dump offset
23
-     *                        information, the code needs to be passed to dump().
24
-     *
25
-     * @param array $options Options (see description)
26
-     */
27
-    public function __construct(array $options = []) {
28
-        $this->dumpComments = !empty($options['dumpComments']);
29
-        $this->dumpPositions = !empty($options['dumpPositions']);
30
-    }
31
-
32
-    /**
33
-     * Dumps a node or array.
34
-     *
35
-     * @param array|Node  $node Node or array to dump
36
-     * @param string|null $code Code corresponding to dumped AST. This only needs to be passed if
37
-     *                          the dumpPositions option is enabled and the dumping of node offsets
38
-     *                          is desired.
39
-     *
40
-     * @return string Dumped value
41
-     */
42
-    public function dump($node, ?string $code = null) : string {
43
-        $this->code = $code;
44
-        return $this->dumpRecursive($node);
45
-    }
46
-
47
-    protected function dumpRecursive($node) {
48
-        if ($node instanceof Node) {
49
-            $r = $node->getType();
50
-            if ($this->dumpPositions && null !== $p = $this->dumpPosition($node)) {
51
-                $r .= $p;
52
-            }
53
-            $r .= '(';
54
-
55
-            foreach ($node->getSubNodeNames() as $key) {
56
-                $r .= "\n    " . $key . ': ';
57
-
58
-                $value = $node->$key;
59
-                if (null === $value) {
60
-                    $r .= 'null';
61
-                } elseif (false === $value) {
62
-                    $r .= 'false';
63
-                } elseif (true === $value) {
64
-                    $r .= 'true';
65
-                } elseif (is_scalar($value)) {
66
-                    if ('flags' === $key || 'newModifier' === $key) {
67
-                        $r .= $this->dumpFlags($value);
68
-                    } elseif ('type' === $key && $node instanceof Include_) {
69
-                        $r .= $this->dumpIncludeType($value);
70
-                    } elseif ('type' === $key
71
-                            && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) {
72
-                        $r .= $this->dumpUseType($value);
73
-                    } else {
74
-                        $r .= $value;
75
-                    }
76
-                } else {
77
-                    $r .= str_replace("\n", "\n    ", $this->dumpRecursive($value));
78
-                }
79
-            }
80
-
81
-            if ($this->dumpComments && $comments = $node->getComments()) {
82
-                $r .= "\n    comments: " . str_replace("\n", "\n    ", $this->dumpRecursive($comments));
83
-            }
84
-        } elseif (is_array($node)) {
85
-            $r = 'array(';
86
-
87
-            foreach ($node as $key => $value) {
88
-                $r .= "\n    " . $key . ': ';
89
-
90
-                if (null === $value) {
91
-                    $r .= 'null';
92
-                } elseif (false === $value) {
93
-                    $r .= 'false';
94
-                } elseif (true === $value) {
95
-                    $r .= 'true';
96
-                } elseif (is_scalar($value)) {
97
-                    $r .= $value;
98
-                } else {
99
-                    $r .= str_replace("\n", "\n    ", $this->dumpRecursive($value));
100
-                }
101
-            }
102
-        } elseif ($node instanceof Comment) {
103
-            return $node->getReformattedText();
104
-        } else {
105
-            throw new \InvalidArgumentException('Can only dump nodes and arrays.');
106
-        }
107
-
108
-        return $r . "\n)";
109
-    }
110
-
111
-    protected function dumpFlags($flags) {
112
-        $strs = [];
113
-        if ($flags & Class_::MODIFIER_PUBLIC) {
114
-            $strs[] = 'MODIFIER_PUBLIC';
115
-        }
116
-        if ($flags & Class_::MODIFIER_PROTECTED) {
117
-            $strs[] = 'MODIFIER_PROTECTED';
118
-        }
119
-        if ($flags & Class_::MODIFIER_PRIVATE) {
120
-            $strs[] = 'MODIFIER_PRIVATE';
121
-        }
122
-        if ($flags & Class_::MODIFIER_ABSTRACT) {
123
-            $strs[] = 'MODIFIER_ABSTRACT';
124
-        }
125
-        if ($flags & Class_::MODIFIER_STATIC) {
126
-            $strs[] = 'MODIFIER_STATIC';
127
-        }
128
-        if ($flags & Class_::MODIFIER_FINAL) {
129
-            $strs[] = 'MODIFIER_FINAL';
130
-        }
131
-        if ($flags & Class_::MODIFIER_READONLY) {
132
-            $strs[] = 'MODIFIER_READONLY';
133
-        }
134
-
135
-        if ($strs) {
136
-            return implode(' | ', $strs) . ' (' . $flags . ')';
137
-        } else {
138
-            return $flags;
139
-        }
140
-    }
141
-
142
-    protected function dumpIncludeType($type) {
143
-        $map = [
144
-            Include_::TYPE_INCLUDE      => 'TYPE_INCLUDE',
145
-            Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE',
146
-            Include_::TYPE_REQUIRE      => 'TYPE_REQUIRE',
147
-            Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE',
148
-        ];
149
-
150
-        if (!isset($map[$type])) {
151
-            return $type;
152
-        }
153
-        return $map[$type] . ' (' . $type . ')';
154
-    }
155
-
156
-    protected function dumpUseType($type) {
157
-        $map = [
158
-            Use_::TYPE_UNKNOWN  => 'TYPE_UNKNOWN',
159
-            Use_::TYPE_NORMAL   => 'TYPE_NORMAL',
160
-            Use_::TYPE_FUNCTION => 'TYPE_FUNCTION',
161
-            Use_::TYPE_CONSTANT => 'TYPE_CONSTANT',
162
-        ];
163
-
164
-        if (!isset($map[$type])) {
165
-            return $type;
166
-        }
167
-        return $map[$type] . ' (' . $type . ')';
168
-    }
169
-
170
-    /**
171
-     * Dump node position, if possible.
172
-     *
173
-     * @param Node $node Node for which to dump position
174
-     *
175
-     * @return string|null Dump of position, or null if position information not available
176
-     */
177
-    protected function dumpPosition(Node $node) {
178
-        if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) {
179
-            return null;
180
-        }
181
-
182
-        $start = $node->getStartLine();
183
-        $end = $node->getEndLine();
184
-        if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos')
185
-            && null !== $this->code
186
-        ) {
187
-            $start .= ':' . $this->toColumn($this->code, $node->getStartFilePos());
188
-            $end .= ':' . $this->toColumn($this->code, $node->getEndFilePos());
189
-        }
190
-        return "[$start - $end]";
191
-    }
192
-
193
-    // Copied from Error class
194
-    private function toColumn($code, $pos) {
195
-        if ($pos > strlen($code)) {
196
-            throw new \RuntimeException('Invalid position information');
197
-        }
198
-
199
-        $lineStartPos = strrpos($code, "\n", $pos - strlen($code));
200
-        if (false === $lineStartPos) {
201
-            $lineStartPos = -1;
202
-        }
203
-
204
-        return $pos - $lineStartPos;
205
-    }
13
+	private $dumpComments;
14
+	private $dumpPositions;
15
+	private $code;
16
+
17
+	/**
18
+	 * Constructs a NodeDumper.
19
+	 *
20
+	 * Supported options:
21
+	 *  * bool dumpComments: Whether comments should be dumped.
22
+	 *  * bool dumpPositions: Whether line/offset information should be dumped. To dump offset
23
+	 *                        information, the code needs to be passed to dump().
24
+	 *
25
+	 * @param array $options Options (see description)
26
+	 */
27
+	public function __construct(array $options = []) {
28
+		$this->dumpComments = !empty($options['dumpComments']);
29
+		$this->dumpPositions = !empty($options['dumpPositions']);
30
+	}
31
+
32
+	/**
33
+	 * Dumps a node or array.
34
+	 *
35
+	 * @param array|Node  $node Node or array to dump
36
+	 * @param string|null $code Code corresponding to dumped AST. This only needs to be passed if
37
+	 *                          the dumpPositions option is enabled and the dumping of node offsets
38
+	 *                          is desired.
39
+	 *
40
+	 * @return string Dumped value
41
+	 */
42
+	public function dump($node, ?string $code = null) : string {
43
+		$this->code = $code;
44
+		return $this->dumpRecursive($node);
45
+	}
46
+
47
+	protected function dumpRecursive($node) {
48
+		if ($node instanceof Node) {
49
+			$r = $node->getType();
50
+			if ($this->dumpPositions && null !== $p = $this->dumpPosition($node)) {
51
+				$r .= $p;
52
+			}
53
+			$r .= '(';
54
+
55
+			foreach ($node->getSubNodeNames() as $key) {
56
+				$r .= "\n    " . $key . ': ';
57
+
58
+				$value = $node->$key;
59
+				if (null === $value) {
60
+					$r .= 'null';
61
+				} elseif (false === $value) {
62
+					$r .= 'false';
63
+				} elseif (true === $value) {
64
+					$r .= 'true';
65
+				} elseif (is_scalar($value)) {
66
+					if ('flags' === $key || 'newModifier' === $key) {
67
+						$r .= $this->dumpFlags($value);
68
+					} elseif ('type' === $key && $node instanceof Include_) {
69
+						$r .= $this->dumpIncludeType($value);
70
+					} elseif ('type' === $key
71
+							&& ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) {
72
+						$r .= $this->dumpUseType($value);
73
+					} else {
74
+						$r .= $value;
75
+					}
76
+				} else {
77
+					$r .= str_replace("\n", "\n    ", $this->dumpRecursive($value));
78
+				}
79
+			}
80
+
81
+			if ($this->dumpComments && $comments = $node->getComments()) {
82
+				$r .= "\n    comments: " . str_replace("\n", "\n    ", $this->dumpRecursive($comments));
83
+			}
84
+		} elseif (is_array($node)) {
85
+			$r = 'array(';
86
+
87
+			foreach ($node as $key => $value) {
88
+				$r .= "\n    " . $key . ': ';
89
+
90
+				if (null === $value) {
91
+					$r .= 'null';
92
+				} elseif (false === $value) {
93
+					$r .= 'false';
94
+				} elseif (true === $value) {
95
+					$r .= 'true';
96
+				} elseif (is_scalar($value)) {
97
+					$r .= $value;
98
+				} else {
99
+					$r .= str_replace("\n", "\n    ", $this->dumpRecursive($value));
100
+				}
101
+			}
102
+		} elseif ($node instanceof Comment) {
103
+			return $node->getReformattedText();
104
+		} else {
105
+			throw new \InvalidArgumentException('Can only dump nodes and arrays.');
106
+		}
107
+
108
+		return $r . "\n)";
109
+	}
110
+
111
+	protected function dumpFlags($flags) {
112
+		$strs = [];
113
+		if ($flags & Class_::MODIFIER_PUBLIC) {
114
+			$strs[] = 'MODIFIER_PUBLIC';
115
+		}
116
+		if ($flags & Class_::MODIFIER_PROTECTED) {
117
+			$strs[] = 'MODIFIER_PROTECTED';
118
+		}
119
+		if ($flags & Class_::MODIFIER_PRIVATE) {
120
+			$strs[] = 'MODIFIER_PRIVATE';
121
+		}
122
+		if ($flags & Class_::MODIFIER_ABSTRACT) {
123
+			$strs[] = 'MODIFIER_ABSTRACT';
124
+		}
125
+		if ($flags & Class_::MODIFIER_STATIC) {
126
+			$strs[] = 'MODIFIER_STATIC';
127
+		}
128
+		if ($flags & Class_::MODIFIER_FINAL) {
129
+			$strs[] = 'MODIFIER_FINAL';
130
+		}
131
+		if ($flags & Class_::MODIFIER_READONLY) {
132
+			$strs[] = 'MODIFIER_READONLY';
133
+		}
134
+
135
+		if ($strs) {
136
+			return implode(' | ', $strs) . ' (' . $flags . ')';
137
+		} else {
138
+			return $flags;
139
+		}
140
+	}
141
+
142
+	protected function dumpIncludeType($type) {
143
+		$map = [
144
+			Include_::TYPE_INCLUDE      => 'TYPE_INCLUDE',
145
+			Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE',
146
+			Include_::TYPE_REQUIRE      => 'TYPE_REQUIRE',
147
+			Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE',
148
+		];
149
+
150
+		if (!isset($map[$type])) {
151
+			return $type;
152
+		}
153
+		return $map[$type] . ' (' . $type . ')';
154
+	}
155
+
156
+	protected function dumpUseType($type) {
157
+		$map = [
158
+			Use_::TYPE_UNKNOWN  => 'TYPE_UNKNOWN',
159
+			Use_::TYPE_NORMAL   => 'TYPE_NORMAL',
160
+			Use_::TYPE_FUNCTION => 'TYPE_FUNCTION',
161
+			Use_::TYPE_CONSTANT => 'TYPE_CONSTANT',
162
+		];
163
+
164
+		if (!isset($map[$type])) {
165
+			return $type;
166
+		}
167
+		return $map[$type] . ' (' . $type . ')';
168
+	}
169
+
170
+	/**
171
+	 * Dump node position, if possible.
172
+	 *
173
+	 * @param Node $node Node for which to dump position
174
+	 *
175
+	 * @return string|null Dump of position, or null if position information not available
176
+	 */
177
+	protected function dumpPosition(Node $node) {
178
+		if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) {
179
+			return null;
180
+		}
181
+
182
+		$start = $node->getStartLine();
183
+		$end = $node->getEndLine();
184
+		if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos')
185
+			&& null !== $this->code
186
+		) {
187
+			$start .= ':' . $this->toColumn($this->code, $node->getStartFilePos());
188
+			$end .= ':' . $this->toColumn($this->code, $node->getEndFilePos());
189
+		}
190
+		return "[$start - $end]";
191
+	}
192
+
193
+	// Copied from Error class
194
+	private function toColumn($code, $pos) {
195
+		if ($pos > strlen($code)) {
196
+			throw new \RuntimeException('Invalid position information');
197
+		}
198
+
199
+		$lineStartPos = strrpos($code, "\n", $pos - strlen($code));
200
+		if (false === $lineStartPos) {
201
+			$lineStartPos = -1;
202
+		}
203
+
204
+		return $pos - $lineStartPos;
205
+	}
206 206
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             $r .= '(';
54 54
 
55 55
             foreach ($node->getSubNodeNames() as $key) {
56
-                $r .= "\n    " . $key . ': ';
56
+                $r .= "\n    ".$key.': ';
57 57
 
58 58
                 $value = $node->$key;
59 59
                 if (null === $value) {
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
             }
80 80
 
81 81
             if ($this->dumpComments && $comments = $node->getComments()) {
82
-                $r .= "\n    comments: " . str_replace("\n", "\n    ", $this->dumpRecursive($comments));
82
+                $r .= "\n    comments: ".str_replace("\n", "\n    ", $this->dumpRecursive($comments));
83 83
             }
84 84
         } elseif (is_array($node)) {
85 85
             $r = 'array(';
86 86
 
87 87
             foreach ($node as $key => $value) {
88
-                $r .= "\n    " . $key . ': ';
88
+                $r .= "\n    ".$key.': ';
89 89
 
90 90
                 if (null === $value) {
91 91
                     $r .= 'null';
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             throw new \InvalidArgumentException('Can only dump nodes and arrays.');
106 106
         }
107 107
 
108
-        return $r . "\n)";
108
+        return $r."\n)";
109 109
     }
110 110
 
111 111
     protected function dumpFlags($flags) {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         }
134 134
 
135 135
         if ($strs) {
136
-            return implode(' | ', $strs) . ' (' . $flags . ')';
136
+            return implode(' | ', $strs).' ('.$flags.')';
137 137
         } else {
138 138
             return $flags;
139 139
         }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         if (!isset($map[$type])) {
151 151
             return $type;
152 152
         }
153
-        return $map[$type] . ' (' . $type . ')';
153
+        return $map[$type].' ('.$type.')';
154 154
     }
155 155
 
156 156
     protected function dumpUseType($type) {
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         if (!isset($map[$type])) {
165 165
             return $type;
166 166
         }
167
-        return $map[$type] . ' (' . $type . ')';
167
+        return $map[$type].' ('.$type.')';
168 168
     }
169 169
 
170 170
     /**
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
         if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos')
185 185
             && null !== $this->code
186 186
         ) {
187
-            $start .= ':' . $this->toColumn($this->code, $node->getStartFilePos());
188
-            $end .= ':' . $this->toColumn($this->code, $node->getEndFilePos());
187
+            $start .= ':'.$this->toColumn($this->code, $node->getStartFilePos());
188
+            $end .= ':'.$this->toColumn($this->code, $node->getEndFilePos());
189 189
         }
190 190
         return "[$start - $end]";
191 191
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,8 +8,7 @@
 block discarded – undo
8 8
 use PhpParser\Node\Stmt\Use_;
9 9
 use PhpParser\Node\Stmt\UseUse;
10 10
 
11
-class NodeDumper
12
-{
11
+class NodeDumper {
13 12
     private $dumpComments;
14 13
     private $dumpPositions;
15 14
     private $code;
Please login to merge, or discard this patch.
vendor-bin/php-scoper/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -4,69 +4,69 @@
 block discarded – undo
4 4
 
5 5
 interface NodeVisitor
6 6
 {
7
-    /**
8
-     * Called once before traversal.
9
-     *
10
-     * Return value semantics:
11
-     *  * null:      $nodes stays as-is
12
-     *  * otherwise: $nodes is set to the return value
13
-     *
14
-     * @param Node[] $nodes Array of nodes
15
-     *
16
-     * @return null|Node[] Array of nodes
17
-     */
18
-    public function beforeTraverse(array $nodes);
7
+	/**
8
+	 * Called once before traversal.
9
+	 *
10
+	 * Return value semantics:
11
+	 *  * null:      $nodes stays as-is
12
+	 *  * otherwise: $nodes is set to the return value
13
+	 *
14
+	 * @param Node[] $nodes Array of nodes
15
+	 *
16
+	 * @return null|Node[] Array of nodes
17
+	 */
18
+	public function beforeTraverse(array $nodes);
19 19
 
20
-    /**
21
-     * Called when entering a node.
22
-     *
23
-     * Return value semantics:
24
-     *  * null
25
-     *        => $node stays as-is
26
-     *  * NodeTraverser::DONT_TRAVERSE_CHILDREN
27
-     *        => Children of $node are not traversed. $node stays as-is
28
-     *  * NodeTraverser::STOP_TRAVERSAL
29
-     *        => Traversal is aborted. $node stays as-is
30
-     *  * otherwise
31
-     *        => $node is set to the return value
32
-     *
33
-     * @param Node $node Node
34
-     *
35
-     * @return null|int|Node Replacement node (or special return value)
36
-     */
37
-    public function enterNode(Node $node);
20
+	/**
21
+	 * Called when entering a node.
22
+	 *
23
+	 * Return value semantics:
24
+	 *  * null
25
+	 *        => $node stays as-is
26
+	 *  * NodeTraverser::DONT_TRAVERSE_CHILDREN
27
+	 *        => Children of $node are not traversed. $node stays as-is
28
+	 *  * NodeTraverser::STOP_TRAVERSAL
29
+	 *        => Traversal is aborted. $node stays as-is
30
+	 *  * otherwise
31
+	 *        => $node is set to the return value
32
+	 *
33
+	 * @param Node $node Node
34
+	 *
35
+	 * @return null|int|Node Replacement node (or special return value)
36
+	 */
37
+	public function enterNode(Node $node);
38 38
 
39
-    /**
40
-     * Called when leaving a node.
41
-     *
42
-     * Return value semantics:
43
-     *  * null
44
-     *        => $node stays as-is
45
-     *  * NodeTraverser::REMOVE_NODE
46
-     *        => $node is removed from the parent array
47
-     *  * NodeTraverser::STOP_TRAVERSAL
48
-     *        => Traversal is aborted. $node stays as-is
49
-     *  * array (of Nodes)
50
-     *        => The return value is merged into the parent array (at the position of the $node)
51
-     *  * otherwise
52
-     *        => $node is set to the return value
53
-     *
54
-     * @param Node $node Node
55
-     *
56
-     * @return null|int|Node|Node[] Replacement node (or special return value)
57
-     */
58
-    public function leaveNode(Node $node);
39
+	/**
40
+	 * Called when leaving a node.
41
+	 *
42
+	 * Return value semantics:
43
+	 *  * null
44
+	 *        => $node stays as-is
45
+	 *  * NodeTraverser::REMOVE_NODE
46
+	 *        => $node is removed from the parent array
47
+	 *  * NodeTraverser::STOP_TRAVERSAL
48
+	 *        => Traversal is aborted. $node stays as-is
49
+	 *  * array (of Nodes)
50
+	 *        => The return value is merged into the parent array (at the position of the $node)
51
+	 *  * otherwise
52
+	 *        => $node is set to the return value
53
+	 *
54
+	 * @param Node $node Node
55
+	 *
56
+	 * @return null|int|Node|Node[] Replacement node (or special return value)
57
+	 */
58
+	public function leaveNode(Node $node);
59 59
 
60
-    /**
61
-     * Called once after traversal.
62
-     *
63
-     * Return value semantics:
64
-     *  * null:      $nodes stays as-is
65
-     *  * otherwise: $nodes is set to the return value
66
-     *
67
-     * @param Node[] $nodes Array of nodes
68
-     *
69
-     * @return null|Node[] Array of nodes
70
-     */
71
-    public function afterTraverse(array $nodes);
60
+	/**
61
+	 * Called once after traversal.
62
+	 *
63
+	 * Return value semantics:
64
+	 *  * null:      $nodes stays as-is
65
+	 *  * otherwise: $nodes is set to the return value
66
+	 *
67
+	 * @param Node[] $nodes Array of nodes
68
+	 *
69
+	 * @return null|Node[] Array of nodes
70
+	 */
71
+	public function afterTraverse(array $nodes);
72 72
 }
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
-interface NodeVisitor
6
-{
5
+interface NodeVisitor {
7 6
     /**
8 7
      * Called once before traversal.
9 8
      *
Please login to merge, or discard this patch.
php-scoper/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php 3 patches
Indentation   +1088 added lines, -1088 removed lines patch added patch discarded remove patch
@@ -15,1011 +15,1011 @@  discard block
 block discarded – undo
15 15
 
16 16
 class Standard extends PrettyPrinterAbstract
17 17
 {
18
-    // Special nodes
19
-
20
-    protected function pParam(Node\Param $node) {
21
-        return $this->pAttrGroups($node->attrGroups, true)
22
-             . $this->pModifiers($node->flags)
23
-             . ($node->type ? $this->p($node->type) . ' ' : '')
24
-             . ($node->byRef ? '&' : '')
25
-             . ($node->variadic ? '...' : '')
26
-             . $this->p($node->var)
27
-             . ($node->default ? ' = ' . $this->p($node->default) : '');
28
-    }
29
-
30
-    protected function pArg(Node\Arg $node) {
31
-        return ($node->name ? $node->name->toString() . ': ' : '')
32
-             . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '')
33
-             . $this->p($node->value);
34
-    }
35
-
36
-    protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node) {
37
-        return '...';
38
-    }
39
-
40
-    protected function pConst(Node\Const_ $node) {
41
-        return $node->name . ' = ' . $this->p($node->value);
42
-    }
43
-
44
-    protected function pNullableType(Node\NullableType $node) {
45
-        return '?' . $this->p($node->type);
46
-    }
47
-
48
-    protected function pUnionType(Node\UnionType $node) {
49
-        $types = [];
50
-        foreach ($node->types as $typeNode) {
51
-            if ($typeNode instanceof Node\IntersectionType) {
52
-                $types[] = '('. $this->p($typeNode) . ')';
53
-                continue;
54
-            }
55
-            $types[] = $this->p($typeNode);
56
-        }
57
-        return implode('|', $types);
58
-    }
59
-
60
-    protected function pIntersectionType(Node\IntersectionType $node) {
61
-        return $this->pImplode($node->types, '&');
62
-    }
63
-
64
-    protected function pIdentifier(Node\Identifier $node) {
65
-        return $node->name;
66
-    }
67
-
68
-    protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) {
69
-        return '$' . $node->name;
70
-    }
71
-
72
-    protected function pAttribute(Node\Attribute $node) {
73
-        return $this->p($node->name)
74
-             . ($node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : '');
75
-    }
76
-
77
-    protected function pAttributeGroup(Node\AttributeGroup $node) {
78
-        return '#[' . $this->pCommaSeparated($node->attrs) . ']';
79
-    }
80
-
81
-    // Names
82
-
83
-    protected function pName(Name $node) {
84
-        return implode('\\', $node->parts);
85
-    }
86
-
87
-    protected function pName_FullyQualified(Name\FullyQualified $node) {
88
-        return '\\' . implode('\\', $node->parts);
89
-    }
90
-
91
-    protected function pName_Relative(Name\Relative $node) {
92
-        return 'namespace\\' . implode('\\', $node->parts);
93
-    }
94
-
95
-    // Magic Constants
96
-
97
-    protected function pScalar_MagicConst_Class(MagicConst\Class_ $node) {
98
-        return '__CLASS__';
99
-    }
100
-
101
-    protected function pScalar_MagicConst_Dir(MagicConst\Dir $node) {
102
-        return '__DIR__';
103
-    }
104
-
105
-    protected function pScalar_MagicConst_File(MagicConst\File $node) {
106
-        return '__FILE__';
107
-    }
108
-
109
-    protected function pScalar_MagicConst_Function(MagicConst\Function_ $node) {
110
-        return '__FUNCTION__';
111
-    }
112
-
113
-    protected function pScalar_MagicConst_Line(MagicConst\Line $node) {
114
-        return '__LINE__';
115
-    }
116
-
117
-    protected function pScalar_MagicConst_Method(MagicConst\Method $node) {
118
-        return '__METHOD__';
119
-    }
120
-
121
-    protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) {
122
-        return '__NAMESPACE__';
123
-    }
124
-
125
-    protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) {
126
-        return '__TRAIT__';
127
-    }
128
-
129
-    // Scalars
130
-
131
-    protected function pScalar_String(Scalar\String_ $node) {
132
-        $kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED);
133
-        switch ($kind) {
134
-            case Scalar\String_::KIND_NOWDOC:
135
-                $label = $node->getAttribute('docLabel');
136
-                if ($label && !$this->containsEndLabel($node->value, $label)) {
137
-                    if ($node->value === '') {
138
-                        return "<<<'$label'\n$label" . $this->docStringEndToken;
139
-                    }
140
-
141
-                    return "<<<'$label'\n$node->value\n$label"
142
-                         . $this->docStringEndToken;
143
-                }
144
-                /* break missing intentionally */
145
-            case Scalar\String_::KIND_SINGLE_QUOTED:
146
-                return $this->pSingleQuotedString($node->value);
147
-            case Scalar\String_::KIND_HEREDOC:
148
-                $label = $node->getAttribute('docLabel');
149
-                if ($label && !$this->containsEndLabel($node->value, $label)) {
150
-                    if ($node->value === '') {
151
-                        return "<<<$label\n$label" . $this->docStringEndToken;
152
-                    }
153
-
154
-                    $escaped = $this->escapeString($node->value, null);
155
-                    return "<<<$label\n" . $escaped . "\n$label"
156
-                         . $this->docStringEndToken;
157
-                }
158
-            /* break missing intentionally */
159
-            case Scalar\String_::KIND_DOUBLE_QUOTED:
160
-                return '"' . $this->escapeString($node->value, '"') . '"';
161
-        }
162
-        throw new \Exception('Invalid string kind');
163
-    }
164
-
165
-    protected function pScalar_Encapsed(Scalar\Encapsed $node) {
166
-        if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) {
167
-            $label = $node->getAttribute('docLabel');
168
-            if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) {
169
-                if (count($node->parts) === 1
170
-                    && $node->parts[0] instanceof Scalar\EncapsedStringPart
171
-                    && $node->parts[0]->value === ''
172
-                ) {
173
-                    return "<<<$label\n$label" . $this->docStringEndToken;
174
-                }
175
-
176
-                return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label"
177
-                     . $this->docStringEndToken;
178
-            }
179
-        }
180
-        return '"' . $this->pEncapsList($node->parts, '"') . '"';
181
-    }
182
-
183
-    protected function pScalar_LNumber(Scalar\LNumber $node) {
184
-        if ($node->value === -\PHP_INT_MAX-1) {
185
-            // PHP_INT_MIN cannot be represented as a literal,
186
-            // because the sign is not part of the literal
187
-            return '(-' . \PHP_INT_MAX . '-1)';
188
-        }
189
-
190
-        $kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC);
191
-        if (Scalar\LNumber::KIND_DEC === $kind) {
192
-            return (string) $node->value;
193
-        }
194
-
195
-        if ($node->value < 0) {
196
-            $sign = '-';
197
-            $str = (string) -$node->value;
198
-        } else {
199
-            $sign = '';
200
-            $str = (string) $node->value;
201
-        }
202
-        switch ($kind) {
203
-            case Scalar\LNumber::KIND_BIN:
204
-                return $sign . '0b' . base_convert($str, 10, 2);
205
-            case Scalar\LNumber::KIND_OCT:
206
-                return $sign . '0' . base_convert($str, 10, 8);
207
-            case Scalar\LNumber::KIND_HEX:
208
-                return $sign . '0x' . base_convert($str, 10, 16);
209
-        }
210
-        throw new \Exception('Invalid number kind');
211
-    }
212
-
213
-    protected function pScalar_DNumber(Scalar\DNumber $node) {
214
-        if (!is_finite($node->value)) {
215
-            if ($node->value === \INF) {
216
-                return '\INF';
217
-            } elseif ($node->value === -\INF) {
218
-                return '-\INF';
219
-            } else {
220
-                return '\NAN';
221
-            }
222
-        }
223
-
224
-        // Try to find a short full-precision representation
225
-        $stringValue = sprintf('%.16G', $node->value);
226
-        if ($node->value !== (double) $stringValue) {
227
-            $stringValue = sprintf('%.17G', $node->value);
228
-        }
229
-
230
-        // %G is locale dependent and there exists no locale-independent alternative. We don't want
231
-        // mess with switching locales here, so let's assume that a comma is the only non-standard
232
-        // decimal separator we may encounter...
233
-        $stringValue = str_replace(',', '.', $stringValue);
234
-
235
-        // ensure that number is really printed as float
236
-        return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
237
-    }
238
-
239
-    protected function pScalar_EncapsedStringPart(Scalar\EncapsedStringPart $node) {
240
-        throw new \LogicException('Cannot directly print EncapsedStringPart');
241
-    }
242
-
243
-    // Assignments
244
-
245
-    protected function pExpr_Assign(Expr\Assign $node) {
246
-        return $this->pInfixOp(Expr\Assign::class, $node->var, ' = ', $node->expr);
247
-    }
248
-
249
-    protected function pExpr_AssignRef(Expr\AssignRef $node) {
250
-        return $this->pInfixOp(Expr\AssignRef::class, $node->var, ' =& ', $node->expr);
251
-    }
252
-
253
-    protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) {
254
-        return $this->pInfixOp(AssignOp\Plus::class, $node->var, ' += ', $node->expr);
255
-    }
256
-
257
-    protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) {
258
-        return $this->pInfixOp(AssignOp\Minus::class, $node->var, ' -= ', $node->expr);
259
-    }
260
-
261
-    protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) {
262
-        return $this->pInfixOp(AssignOp\Mul::class, $node->var, ' *= ', $node->expr);
263
-    }
264
-
265
-    protected function pExpr_AssignOp_Div(AssignOp\Div $node) {
266
-        return $this->pInfixOp(AssignOp\Div::class, $node->var, ' /= ', $node->expr);
267
-    }
268
-
269
-    protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) {
270
-        return $this->pInfixOp(AssignOp\Concat::class, $node->var, ' .= ', $node->expr);
271
-    }
272
-
273
-    protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) {
274
-        return $this->pInfixOp(AssignOp\Mod::class, $node->var, ' %= ', $node->expr);
275
-    }
276
-
277
-    protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) {
278
-        return $this->pInfixOp(AssignOp\BitwiseAnd::class, $node->var, ' &= ', $node->expr);
279
-    }
280
-
281
-    protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) {
282
-        return $this->pInfixOp(AssignOp\BitwiseOr::class, $node->var, ' |= ', $node->expr);
283
-    }
284
-
285
-    protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) {
286
-        return $this->pInfixOp(AssignOp\BitwiseXor::class, $node->var, ' ^= ', $node->expr);
287
-    }
288
-
289
-    protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) {
290
-        return $this->pInfixOp(AssignOp\ShiftLeft::class, $node->var, ' <<= ', $node->expr);
291
-    }
292
-
293
-    protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) {
294
-        return $this->pInfixOp(AssignOp\ShiftRight::class, $node->var, ' >>= ', $node->expr);
295
-    }
296
-
297
-    protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) {
298
-        return $this->pInfixOp(AssignOp\Pow::class, $node->var, ' **= ', $node->expr);
299
-    }
300
-
301
-    protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node) {
302
-        return $this->pInfixOp(AssignOp\Coalesce::class, $node->var, ' ??= ', $node->expr);
303
-    }
304
-
305
-    // Binary expressions
306
-
307
-    protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) {
308
-        return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right);
309
-    }
310
-
311
-    protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) {
312
-        return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right);
313
-    }
314
-
315
-    protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) {
316
-        return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right);
317
-    }
318
-
319
-    protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) {
320
-        return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right);
321
-    }
18
+	// Special nodes
19
+
20
+	protected function pParam(Node\Param $node) {
21
+		return $this->pAttrGroups($node->attrGroups, true)
22
+			 . $this->pModifiers($node->flags)
23
+			 . ($node->type ? $this->p($node->type) . ' ' : '')
24
+			 . ($node->byRef ? '&' : '')
25
+			 . ($node->variadic ? '...' : '')
26
+			 . $this->p($node->var)
27
+			 . ($node->default ? ' = ' . $this->p($node->default) : '');
28
+	}
29
+
30
+	protected function pArg(Node\Arg $node) {
31
+		return ($node->name ? $node->name->toString() . ': ' : '')
32
+			 . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '')
33
+			 . $this->p($node->value);
34
+	}
35
+
36
+	protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node) {
37
+		return '...';
38
+	}
39
+
40
+	protected function pConst(Node\Const_ $node) {
41
+		return $node->name . ' = ' . $this->p($node->value);
42
+	}
43
+
44
+	protected function pNullableType(Node\NullableType $node) {
45
+		return '?' . $this->p($node->type);
46
+	}
47
+
48
+	protected function pUnionType(Node\UnionType $node) {
49
+		$types = [];
50
+		foreach ($node->types as $typeNode) {
51
+			if ($typeNode instanceof Node\IntersectionType) {
52
+				$types[] = '('. $this->p($typeNode) . ')';
53
+				continue;
54
+			}
55
+			$types[] = $this->p($typeNode);
56
+		}
57
+		return implode('|', $types);
58
+	}
59
+
60
+	protected function pIntersectionType(Node\IntersectionType $node) {
61
+		return $this->pImplode($node->types, '&');
62
+	}
63
+
64
+	protected function pIdentifier(Node\Identifier $node) {
65
+		return $node->name;
66
+	}
67
+
68
+	protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) {
69
+		return '$' . $node->name;
70
+	}
71
+
72
+	protected function pAttribute(Node\Attribute $node) {
73
+		return $this->p($node->name)
74
+			 . ($node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : '');
75
+	}
76
+
77
+	protected function pAttributeGroup(Node\AttributeGroup $node) {
78
+		return '#[' . $this->pCommaSeparated($node->attrs) . ']';
79
+	}
80
+
81
+	// Names
82
+
83
+	protected function pName(Name $node) {
84
+		return implode('\\', $node->parts);
85
+	}
86
+
87
+	protected function pName_FullyQualified(Name\FullyQualified $node) {
88
+		return '\\' . implode('\\', $node->parts);
89
+	}
90
+
91
+	protected function pName_Relative(Name\Relative $node) {
92
+		return 'namespace\\' . implode('\\', $node->parts);
93
+	}
94
+
95
+	// Magic Constants
96
+
97
+	protected function pScalar_MagicConst_Class(MagicConst\Class_ $node) {
98
+		return '__CLASS__';
99
+	}
100
+
101
+	protected function pScalar_MagicConst_Dir(MagicConst\Dir $node) {
102
+		return '__DIR__';
103
+	}
104
+
105
+	protected function pScalar_MagicConst_File(MagicConst\File $node) {
106
+		return '__FILE__';
107
+	}
108
+
109
+	protected function pScalar_MagicConst_Function(MagicConst\Function_ $node) {
110
+		return '__FUNCTION__';
111
+	}
112
+
113
+	protected function pScalar_MagicConst_Line(MagicConst\Line $node) {
114
+		return '__LINE__';
115
+	}
116
+
117
+	protected function pScalar_MagicConst_Method(MagicConst\Method $node) {
118
+		return '__METHOD__';
119
+	}
120
+
121
+	protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) {
122
+		return '__NAMESPACE__';
123
+	}
124
+
125
+	protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) {
126
+		return '__TRAIT__';
127
+	}
128
+
129
+	// Scalars
130
+
131
+	protected function pScalar_String(Scalar\String_ $node) {
132
+		$kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED);
133
+		switch ($kind) {
134
+			case Scalar\String_::KIND_NOWDOC:
135
+				$label = $node->getAttribute('docLabel');
136
+				if ($label && !$this->containsEndLabel($node->value, $label)) {
137
+					if ($node->value === '') {
138
+						return "<<<'$label'\n$label" . $this->docStringEndToken;
139
+					}
140
+
141
+					return "<<<'$label'\n$node->value\n$label"
142
+						 . $this->docStringEndToken;
143
+				}
144
+				/* break missing intentionally */
145
+			case Scalar\String_::KIND_SINGLE_QUOTED:
146
+				return $this->pSingleQuotedString($node->value);
147
+			case Scalar\String_::KIND_HEREDOC:
148
+				$label = $node->getAttribute('docLabel');
149
+				if ($label && !$this->containsEndLabel($node->value, $label)) {
150
+					if ($node->value === '') {
151
+						return "<<<$label\n$label" . $this->docStringEndToken;
152
+					}
153
+
154
+					$escaped = $this->escapeString($node->value, null);
155
+					return "<<<$label\n" . $escaped . "\n$label"
156
+						 . $this->docStringEndToken;
157
+				}
158
+			/* break missing intentionally */
159
+			case Scalar\String_::KIND_DOUBLE_QUOTED:
160
+				return '"' . $this->escapeString($node->value, '"') . '"';
161
+		}
162
+		throw new \Exception('Invalid string kind');
163
+	}
164
+
165
+	protected function pScalar_Encapsed(Scalar\Encapsed $node) {
166
+		if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) {
167
+			$label = $node->getAttribute('docLabel');
168
+			if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) {
169
+				if (count($node->parts) === 1
170
+					&& $node->parts[0] instanceof Scalar\EncapsedStringPart
171
+					&& $node->parts[0]->value === ''
172
+				) {
173
+					return "<<<$label\n$label" . $this->docStringEndToken;
174
+				}
175
+
176
+				return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label"
177
+					 . $this->docStringEndToken;
178
+			}
179
+		}
180
+		return '"' . $this->pEncapsList($node->parts, '"') . '"';
181
+	}
182
+
183
+	protected function pScalar_LNumber(Scalar\LNumber $node) {
184
+		if ($node->value === -\PHP_INT_MAX-1) {
185
+			// PHP_INT_MIN cannot be represented as a literal,
186
+			// because the sign is not part of the literal
187
+			return '(-' . \PHP_INT_MAX . '-1)';
188
+		}
189
+
190
+		$kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC);
191
+		if (Scalar\LNumber::KIND_DEC === $kind) {
192
+			return (string) $node->value;
193
+		}
194
+
195
+		if ($node->value < 0) {
196
+			$sign = '-';
197
+			$str = (string) -$node->value;
198
+		} else {
199
+			$sign = '';
200
+			$str = (string) $node->value;
201
+		}
202
+		switch ($kind) {
203
+			case Scalar\LNumber::KIND_BIN:
204
+				return $sign . '0b' . base_convert($str, 10, 2);
205
+			case Scalar\LNumber::KIND_OCT:
206
+				return $sign . '0' . base_convert($str, 10, 8);
207
+			case Scalar\LNumber::KIND_HEX:
208
+				return $sign . '0x' . base_convert($str, 10, 16);
209
+		}
210
+		throw new \Exception('Invalid number kind');
211
+	}
212
+
213
+	protected function pScalar_DNumber(Scalar\DNumber $node) {
214
+		if (!is_finite($node->value)) {
215
+			if ($node->value === \INF) {
216
+				return '\INF';
217
+			} elseif ($node->value === -\INF) {
218
+				return '-\INF';
219
+			} else {
220
+				return '\NAN';
221
+			}
222
+		}
223
+
224
+		// Try to find a short full-precision representation
225
+		$stringValue = sprintf('%.16G', $node->value);
226
+		if ($node->value !== (double) $stringValue) {
227
+			$stringValue = sprintf('%.17G', $node->value);
228
+		}
229
+
230
+		// %G is locale dependent and there exists no locale-independent alternative. We don't want
231
+		// mess with switching locales here, so let's assume that a comma is the only non-standard
232
+		// decimal separator we may encounter...
233
+		$stringValue = str_replace(',', '.', $stringValue);
234
+
235
+		// ensure that number is really printed as float
236
+		return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
237
+	}
238
+
239
+	protected function pScalar_EncapsedStringPart(Scalar\EncapsedStringPart $node) {
240
+		throw new \LogicException('Cannot directly print EncapsedStringPart');
241
+	}
242
+
243
+	// Assignments
244
+
245
+	protected function pExpr_Assign(Expr\Assign $node) {
246
+		return $this->pInfixOp(Expr\Assign::class, $node->var, ' = ', $node->expr);
247
+	}
248
+
249
+	protected function pExpr_AssignRef(Expr\AssignRef $node) {
250
+		return $this->pInfixOp(Expr\AssignRef::class, $node->var, ' =& ', $node->expr);
251
+	}
252
+
253
+	protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) {
254
+		return $this->pInfixOp(AssignOp\Plus::class, $node->var, ' += ', $node->expr);
255
+	}
256
+
257
+	protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) {
258
+		return $this->pInfixOp(AssignOp\Minus::class, $node->var, ' -= ', $node->expr);
259
+	}
260
+
261
+	protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) {
262
+		return $this->pInfixOp(AssignOp\Mul::class, $node->var, ' *= ', $node->expr);
263
+	}
264
+
265
+	protected function pExpr_AssignOp_Div(AssignOp\Div $node) {
266
+		return $this->pInfixOp(AssignOp\Div::class, $node->var, ' /= ', $node->expr);
267
+	}
268
+
269
+	protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) {
270
+		return $this->pInfixOp(AssignOp\Concat::class, $node->var, ' .= ', $node->expr);
271
+	}
272
+
273
+	protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) {
274
+		return $this->pInfixOp(AssignOp\Mod::class, $node->var, ' %= ', $node->expr);
275
+	}
276
+
277
+	protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) {
278
+		return $this->pInfixOp(AssignOp\BitwiseAnd::class, $node->var, ' &= ', $node->expr);
279
+	}
280
+
281
+	protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) {
282
+		return $this->pInfixOp(AssignOp\BitwiseOr::class, $node->var, ' |= ', $node->expr);
283
+	}
284
+
285
+	protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) {
286
+		return $this->pInfixOp(AssignOp\BitwiseXor::class, $node->var, ' ^= ', $node->expr);
287
+	}
288
+
289
+	protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) {
290
+		return $this->pInfixOp(AssignOp\ShiftLeft::class, $node->var, ' <<= ', $node->expr);
291
+	}
292
+
293
+	protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) {
294
+		return $this->pInfixOp(AssignOp\ShiftRight::class, $node->var, ' >>= ', $node->expr);
295
+	}
296
+
297
+	protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) {
298
+		return $this->pInfixOp(AssignOp\Pow::class, $node->var, ' **= ', $node->expr);
299
+	}
300
+
301
+	protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node) {
302
+		return $this->pInfixOp(AssignOp\Coalesce::class, $node->var, ' ??= ', $node->expr);
303
+	}
304
+
305
+	// Binary expressions
306
+
307
+	protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) {
308
+		return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right);
309
+	}
310
+
311
+	protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) {
312
+		return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right);
313
+	}
314
+
315
+	protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) {
316
+		return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right);
317
+	}
318
+
319
+	protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) {
320
+		return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right);
321
+	}
322 322
 
323
-    protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) {
324
-        return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right);
325
-    }
323
+	protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) {
324
+		return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right);
325
+	}
326 326
 
327
-    protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) {
328
-        return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right);
329
-    }
327
+	protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) {
328
+		return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right);
329
+	}
330 330
 
331
-    protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) {
332
-        return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right);
333
-    }
331
+	protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) {
332
+		return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right);
333
+	}
334 334
 
335
-    protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) {
336
-        return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right);
337
-    }
335
+	protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) {
336
+		return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right);
337
+	}
338 338
 
339
-    protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) {
340
-        return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right);
341
-    }
339
+	protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) {
340
+		return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right);
341
+	}
342 342
 
343
-    protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) {
344
-        return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right);
345
-    }
346
-
347
-    protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) {
348
-        return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right);
349
-    }
350
-
351
-    protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) {
352
-        return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right);
353
-    }
354
-
355
-    protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) {
356
-        return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right);
357
-    }
358
-
359
-    protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) {
360
-        return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right);
361
-    }
362
-
363
-    protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) {
364
-        return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right);
365
-    }
366
-
367
-    protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) {
368
-        return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right);
369
-    }
370
-
371
-    protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) {
372
-        return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right);
373
-    }
374
-
375
-    protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) {
376
-        return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right);
377
-    }
378
-
379
-    protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) {
380
-        return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right);
381
-    }
382
-
383
-    protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) {
384
-        return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right);
385
-    }
386
-
387
-    protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) {
388
-        return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right);
389
-    }
390
-
391
-    protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) {
392
-        return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right);
393
-    }
394
-
395
-    protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) {
396
-        return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right);
397
-    }
398
-
399
-    protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) {
400
-        return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right);
401
-    }
402
-
403
-    protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) {
404
-        return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right);
405
-    }
406
-
407
-    protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) {
408
-        return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right);
409
-    }
410
-
411
-    protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) {
412
-        return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right);
413
-    }
414
-
415
-    protected function pExpr_Instanceof(Expr\Instanceof_ $node) {
416
-        list($precedence, $associativity) = $this->precedenceMap[Expr\Instanceof_::class];
417
-        return $this->pPrec($node->expr, $precedence, $associativity, -1)
418
-             . ' instanceof '
419
-             . $this->pNewVariable($node->class);
420
-    }
421
-
422
-    // Unary expressions
423
-
424
-    protected function pExpr_BooleanNot(Expr\BooleanNot $node) {
425
-        return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr);
426
-    }
427
-
428
-    protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) {
429
-        return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr);
430
-    }
431
-
432
-    protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
433
-        if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) {
434
-            // Enforce -(-$expr) instead of --$expr
435
-            return '-(' . $this->p($node->expr) . ')';
436
-        }
437
-        return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr);
438
-    }
439
-
440
-    protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
441
-        if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) {
442
-            // Enforce +(+$expr) instead of ++$expr
443
-            return '+(' . $this->p($node->expr) . ')';
444
-        }
445
-        return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr);
446
-    }
447
-
448
-    protected function pExpr_PreInc(Expr\PreInc $node) {
449
-        return $this->pPrefixOp(Expr\PreInc::class, '++', $node->var);
450
-    }
451
-
452
-    protected function pExpr_PreDec(Expr\PreDec $node) {
453
-        return $this->pPrefixOp(Expr\PreDec::class, '--', $node->var);
454
-    }
455
-
456
-    protected function pExpr_PostInc(Expr\PostInc $node) {
457
-        return $this->pPostfixOp(Expr\PostInc::class, $node->var, '++');
458
-    }
459
-
460
-    protected function pExpr_PostDec(Expr\PostDec $node) {
461
-        return $this->pPostfixOp(Expr\PostDec::class, $node->var, '--');
462
-    }
463
-
464
-    protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) {
465
-        return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr);
466
-    }
467
-
468
-    protected function pExpr_YieldFrom(Expr\YieldFrom $node) {
469
-        return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr);
470
-    }
471
-
472
-    protected function pExpr_Print(Expr\Print_ $node) {
473
-        return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr);
474
-    }
475
-
476
-    // Casts
477
-
478
-    protected function pExpr_Cast_Int(Cast\Int_ $node) {
479
-        return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr);
480
-    }
481
-
482
-    protected function pExpr_Cast_Double(Cast\Double $node) {
483
-        $kind = $node->getAttribute('kind', Cast\Double::KIND_DOUBLE);
484
-        if ($kind === Cast\Double::KIND_DOUBLE) {
485
-            $cast = '(double)';
486
-        } elseif ($kind === Cast\Double::KIND_FLOAT) {
487
-            $cast = '(float)';
488
-        } elseif ($kind === Cast\Double::KIND_REAL) {
489
-            $cast = '(real)';
490
-        }
491
-        return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr);
492
-    }
493
-
494
-    protected function pExpr_Cast_String(Cast\String_ $node) {
495
-        return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr);
496
-    }
497
-
498
-    protected function pExpr_Cast_Array(Cast\Array_ $node) {
499
-        return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr);
500
-    }
501
-
502
-    protected function pExpr_Cast_Object(Cast\Object_ $node) {
503
-        return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr);
504
-    }
505
-
506
-    protected function pExpr_Cast_Bool(Cast\Bool_ $node) {
507
-        return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr);
508
-    }
509
-
510
-    protected function pExpr_Cast_Unset(Cast\Unset_ $node) {
511
-        return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr);
512
-    }
513
-
514
-    // Function calls and similar constructs
515
-
516
-    protected function pExpr_FuncCall(Expr\FuncCall $node) {
517
-        return $this->pCallLhs($node->name)
518
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
519
-    }
520
-
521
-    protected function pExpr_MethodCall(Expr\MethodCall $node) {
522
-        return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name)
523
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
524
-    }
525
-
526
-    protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node) {
527
-        return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name)
528
-            . '(' . $this->pMaybeMultiline($node->args) . ')';
529
-    }
530
-
531
-    protected function pExpr_StaticCall(Expr\StaticCall $node) {
532
-        return $this->pStaticDereferenceLhs($node->class) . '::'
533
-             . ($node->name instanceof Expr
534
-                ? ($node->name instanceof Expr\Variable
535
-                   ? $this->p($node->name)
536
-                   : '{' . $this->p($node->name) . '}')
537
-                : $node->name)
538
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
539
-    }
540
-
541
-    protected function pExpr_Empty(Expr\Empty_ $node) {
542
-        return 'empty(' . $this->p($node->expr) . ')';
543
-    }
544
-
545
-    protected function pExpr_Isset(Expr\Isset_ $node) {
546
-        return 'isset(' . $this->pCommaSeparated($node->vars) . ')';
547
-    }
548
-
549
-    protected function pExpr_Eval(Expr\Eval_ $node) {
550
-        return 'eval(' . $this->p($node->expr) . ')';
551
-    }
552
-
553
-    protected function pExpr_Include(Expr\Include_ $node) {
554
-        static $map = [
555
-            Expr\Include_::TYPE_INCLUDE      => 'include',
556
-            Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once',
557
-            Expr\Include_::TYPE_REQUIRE      => 'require',
558
-            Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once',
559
-        ];
560
-
561
-        return $map[$node->type] . ' ' . $this->p($node->expr);
562
-    }
563
-
564
-    protected function pExpr_List(Expr\List_ $node) {
565
-        return 'list(' . $this->pCommaSeparated($node->items) . ')';
566
-    }
567
-
568
-    // Other
569
-
570
-    protected function pExpr_Error(Expr\Error $node) {
571
-        throw new \LogicException('Cannot pretty-print AST with Error nodes');
572
-    }
573
-
574
-    protected function pExpr_Variable(Expr\Variable $node) {
575
-        if ($node->name instanceof Expr) {
576
-            return '${' . $this->p($node->name) . '}';
577
-        } else {
578
-            return '$' . $node->name;
579
-        }
580
-    }
581
-
582
-    protected function pExpr_Array(Expr\Array_ $node) {
583
-        $syntax = $node->getAttribute('kind',
584
-            $this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG);
585
-        if ($syntax === Expr\Array_::KIND_SHORT) {
586
-            return '[' . $this->pMaybeMultiline($node->items, true) . ']';
587
-        } else {
588
-            return 'array(' . $this->pMaybeMultiline($node->items, true) . ')';
589
-        }
590
-    }
591
-
592
-    protected function pExpr_ArrayItem(Expr\ArrayItem $node) {
593
-        return (null !== $node->key ? $this->p($node->key) . ' => ' : '')
594
-             . ($node->byRef ? '&' : '')
595
-             . ($node->unpack ? '...' : '')
596
-             . $this->p($node->value);
597
-    }
598
-
599
-    protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) {
600
-        return $this->pDereferenceLhs($node->var)
601
-             . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']';
602
-    }
603
-
604
-    protected function pExpr_ConstFetch(Expr\ConstFetch $node) {
605
-        return $this->p($node->name);
606
-    }
607
-
608
-    protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
609
-        return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name);
610
-    }
611
-
612
-    protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
613
-        return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name);
614
-    }
615
-
616
-    protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node) {
617
-        return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name);
618
-    }
619
-
620
-    protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
621
-        return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
622
-    }
623
-
624
-    protected function pExpr_ShellExec(Expr\ShellExec $node) {
625
-        return '`' . $this->pEncapsList($node->parts, '`') . '`';
626
-    }
627
-
628
-    protected function pExpr_Closure(Expr\Closure $node) {
629
-        return $this->pAttrGroups($node->attrGroups, true)
630
-             . ($node->static ? 'static ' : '')
631
-             . 'function ' . ($node->byRef ? '&' : '')
632
-             . '(' . $this->pCommaSeparated($node->params) . ')'
633
-             . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '')
634
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
635
-             . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
636
-    }
637
-
638
-    protected function pExpr_Match(Expr\Match_ $node) {
639
-        return 'match (' . $this->p($node->cond) . ') {'
640
-            . $this->pCommaSeparatedMultiline($node->arms, true)
641
-            . $this->nl
642
-            . '}';
643
-    }
644
-
645
-    protected function pMatchArm(Node\MatchArm $node) {
646
-        return ($node->conds ? $this->pCommaSeparated($node->conds) : 'default')
647
-            . ' => ' . $this->p($node->body);
648
-    }
649
-
650
-    protected function pExpr_ArrowFunction(Expr\ArrowFunction $node) {
651
-        return $this->pAttrGroups($node->attrGroups, true)
652
-            . ($node->static ? 'static ' : '')
653
-            . 'fn' . ($node->byRef ? '&' : '')
654
-            . '(' . $this->pCommaSeparated($node->params) . ')'
655
-            . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
656
-            . ' => '
657
-            . $this->p($node->expr);
658
-    }
659
-
660
-    protected function pExpr_ClosureUse(Expr\ClosureUse $node) {
661
-        return ($node->byRef ? '&' : '') . $this->p($node->var);
662
-    }
663
-
664
-    protected function pExpr_New(Expr\New_ $node) {
665
-        if ($node->class instanceof Stmt\Class_) {
666
-            $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : '';
667
-            return 'new ' . $this->pClassCommon($node->class, $args);
668
-        }
669
-        return 'new ' . $this->pNewVariable($node->class)
670
-            . '(' . $this->pMaybeMultiline($node->args) . ')';
671
-    }
672
-
673
-    protected function pExpr_Clone(Expr\Clone_ $node) {
674
-        return 'clone ' . $this->p($node->expr);
675
-    }
676
-
677
-    protected function pExpr_Ternary(Expr\Ternary $node) {
678
-        // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator.
679
-        // this is okay because the part between ? and : never needs parentheses.
680
-        return $this->pInfixOp(Expr\Ternary::class,
681
-            $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else
682
-        );
683
-    }
684
-
685
-    protected function pExpr_Exit(Expr\Exit_ $node) {
686
-        $kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE);
687
-        return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die')
688
-             . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : '');
689
-    }
690
-
691
-    protected function pExpr_Throw(Expr\Throw_ $node) {
692
-        return 'throw ' . $this->p($node->expr);
693
-    }
694
-
695
-    protected function pExpr_Yield(Expr\Yield_ $node) {
696
-        if ($node->value === null) {
697
-            return 'yield';
698
-        } else {
699
-            // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary
700
-            return '(yield '
701
-                 . ($node->key !== null ? $this->p($node->key) . ' => ' : '')
702
-                 . $this->p($node->value)
703
-                 . ')';
704
-        }
705
-    }
706
-
707
-    // Declarations
708
-
709
-    protected function pStmt_Namespace(Stmt\Namespace_ $node) {
710
-        if ($this->canUseSemicolonNamespaces) {
711
-            return 'namespace ' . $this->p($node->name) . ';'
712
-                 . $this->nl . $this->pStmts($node->stmts, false);
713
-        } else {
714
-            return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '')
715
-                 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
716
-        }
717
-    }
718
-
719
-    protected function pStmt_Use(Stmt\Use_ $node) {
720
-        return 'use ' . $this->pUseType($node->type)
721
-             . $this->pCommaSeparated($node->uses) . ';';
722
-    }
723
-
724
-    protected function pStmt_GroupUse(Stmt\GroupUse $node) {
725
-        return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix)
726
-             . '\{' . $this->pCommaSeparated($node->uses) . '};';
727
-    }
728
-
729
-    protected function pStmt_UseUse(Stmt\UseUse $node) {
730
-        return $this->pUseType($node->type) . $this->p($node->name)
731
-             . (null !== $node->alias ? ' as ' . $node->alias : '');
732
-    }
733
-
734
-    protected function pUseType($type) {
735
-        return $type === Stmt\Use_::TYPE_FUNCTION ? 'function '
736
-            : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : '');
737
-    }
738
-
739
-    protected function pStmt_Interface(Stmt\Interface_ $node) {
740
-        return $this->pAttrGroups($node->attrGroups)
741
-             . 'interface ' . $node->name
742
-             . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '')
743
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
744
-    }
745
-
746
-    protected function pStmt_Enum(Stmt\Enum_ $node) {
747
-        return $this->pAttrGroups($node->attrGroups)
748
-             . 'enum ' . $node->name
749
-             . ($node->scalarType ? " : $node->scalarType" : '')
750
-             . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
751
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
752
-    }
753
-
754
-    protected function pStmt_Class(Stmt\Class_ $node) {
755
-        return $this->pClassCommon($node, ' ' . $node->name);
756
-    }
757
-
758
-    protected function pStmt_Trait(Stmt\Trait_ $node) {
759
-        return $this->pAttrGroups($node->attrGroups)
760
-             . 'trait ' . $node->name
761
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
762
-    }
763
-
764
-    protected function pStmt_EnumCase(Stmt\EnumCase $node) {
765
-        return $this->pAttrGroups($node->attrGroups)
766
-             . 'case ' . $node->name
767
-             . ($node->expr ? ' = ' . $this->p($node->expr) : '')
768
-             . ';';
769
-    }
770
-
771
-    protected function pStmt_TraitUse(Stmt\TraitUse $node) {
772
-        return 'use ' . $this->pCommaSeparated($node->traits)
773
-             . (empty($node->adaptations)
774
-                ? ';'
775
-                : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}');
776
-    }
777
-
778
-    protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) {
779
-        return $this->p($node->trait) . '::' . $node->method
780
-             . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
781
-    }
782
-
783
-    protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) {
784
-        return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
785
-             . $node->method . ' as'
786
-             . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
787
-             . (null !== $node->newName     ? ' ' . $node->newName                        : '')
788
-             . ';';
789
-    }
790
-
791
-    protected function pStmt_Property(Stmt\Property $node) {
792
-        return $this->pAttrGroups($node->attrGroups)
793
-            . (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags))
794
-            . ($node->type ? $this->p($node->type) . ' ' : '')
795
-            . $this->pCommaSeparated($node->props) . ';';
796
-    }
797
-
798
-    protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) {
799
-        return '$' . $node->name
800
-             . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
801
-    }
802
-
803
-    protected function pStmt_ClassMethod(Stmt\ClassMethod $node) {
804
-        return $this->pAttrGroups($node->attrGroups)
805
-             . $this->pModifiers($node->flags)
806
-             . 'function ' . ($node->byRef ? '&' : '') . $node->name
807
-             . '(' . $this->pMaybeMultiline($node->params) . ')'
808
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
809
-             . (null !== $node->stmts
810
-                ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'
811
-                : ';');
812
-    }
813
-
814
-    protected function pStmt_ClassConst(Stmt\ClassConst $node) {
815
-        return $this->pAttrGroups($node->attrGroups)
816
-             . $this->pModifiers($node->flags)
817
-             . 'const '
818
-             . (null !== $node->type ? $this->p($node->type) . ' ' : '')
819
-             . $this->pCommaSeparated($node->consts) . ';';
820
-    }
821
-
822
-    protected function pStmt_Function(Stmt\Function_ $node) {
823
-        return $this->pAttrGroups($node->attrGroups)
824
-             . 'function ' . ($node->byRef ? '&' : '') . $node->name
825
-             . '(' . $this->pCommaSeparated($node->params) . ')'
826
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
827
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
828
-    }
829
-
830
-    protected function pStmt_Const(Stmt\Const_ $node) {
831
-        return 'const ' . $this->pCommaSeparated($node->consts) . ';';
832
-    }
833
-
834
-    protected function pStmt_Declare(Stmt\Declare_ $node) {
835
-        return 'declare (' . $this->pCommaSeparated($node->declares) . ')'
836
-             . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';');
837
-    }
838
-
839
-    protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) {
840
-        return $node->key . '=' . $this->p($node->value);
841
-    }
842
-
843
-    // Control flow
844
-
845
-    protected function pStmt_If(Stmt\If_ $node) {
846
-        return 'if (' . $this->p($node->cond) . ') {'
847
-             . $this->pStmts($node->stmts) . $this->nl . '}'
848
-             . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '')
849
-             . (null !== $node->else ? ' ' . $this->p($node->else) : '');
850
-    }
851
-
852
-    protected function pStmt_ElseIf(Stmt\ElseIf_ $node) {
853
-        return 'elseif (' . $this->p($node->cond) . ') {'
854
-             . $this->pStmts($node->stmts) . $this->nl . '}';
855
-    }
856
-
857
-    protected function pStmt_Else(Stmt\Else_ $node) {
858
-        return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}';
859
-    }
860
-
861
-    protected function pStmt_For(Stmt\For_ $node) {
862
-        return 'for ('
863
-             . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '')
864
-             . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '')
865
-             . $this->pCommaSeparated($node->loop)
866
-             . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
867
-    }
868
-
869
-    protected function pStmt_Foreach(Stmt\Foreach_ $node) {
870
-        return 'foreach (' . $this->p($node->expr) . ' as '
871
-             . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '')
872
-             . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {'
873
-             . $this->pStmts($node->stmts) . $this->nl . '}';
874
-    }
875
-
876
-    protected function pStmt_While(Stmt\While_ $node) {
877
-        return 'while (' . $this->p($node->cond) . ') {'
878
-             . $this->pStmts($node->stmts) . $this->nl . '}';
879
-    }
880
-
881
-    protected function pStmt_Do(Stmt\Do_ $node) {
882
-        return 'do {' . $this->pStmts($node->stmts) . $this->nl
883
-             . '} while (' . $this->p($node->cond) . ');';
884
-    }
885
-
886
-    protected function pStmt_Switch(Stmt\Switch_ $node) {
887
-        return 'switch (' . $this->p($node->cond) . ') {'
888
-             . $this->pStmts($node->cases) . $this->nl . '}';
889
-    }
890
-
891
-    protected function pStmt_Case(Stmt\Case_ $node) {
892
-        return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
893
-             . $this->pStmts($node->stmts);
894
-    }
895
-
896
-    protected function pStmt_TryCatch(Stmt\TryCatch $node) {
897
-        return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}'
898
-             . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '')
899
-             . ($node->finally !== null ? ' ' . $this->p($node->finally) : '');
900
-    }
901
-
902
-    protected function pStmt_Catch(Stmt\Catch_ $node) {
903
-        return 'catch (' . $this->pImplode($node->types, '|')
904
-             . ($node->var !== null ? ' ' . $this->p($node->var) : '')
905
-             . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
906
-    }
907
-
908
-    protected function pStmt_Finally(Stmt\Finally_ $node) {
909
-        return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}';
910
-    }
911
-
912
-    protected function pStmt_Break(Stmt\Break_ $node) {
913
-        return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
914
-    }
915
-
916
-    protected function pStmt_Continue(Stmt\Continue_ $node) {
917
-        return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
918
-    }
919
-
920
-    protected function pStmt_Return(Stmt\Return_ $node) {
921
-        return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
922
-    }
923
-
924
-    protected function pStmt_Throw(Stmt\Throw_ $node) {
925
-        return 'throw ' . $this->p($node->expr) . ';';
926
-    }
927
-
928
-    protected function pStmt_Label(Stmt\Label $node) {
929
-        return $node->name . ':';
930
-    }
931
-
932
-    protected function pStmt_Goto(Stmt\Goto_ $node) {
933
-        return 'goto ' . $node->name . ';';
934
-    }
935
-
936
-    // Other
937
-
938
-    protected function pStmt_Expression(Stmt\Expression $node) {
939
-        return $this->p($node->expr) . ';';
940
-    }
941
-
942
-    protected function pStmt_Echo(Stmt\Echo_ $node) {
943
-        return 'echo ' . $this->pCommaSeparated($node->exprs) . ';';
944
-    }
945
-
946
-    protected function pStmt_Static(Stmt\Static_ $node) {
947
-        return 'static ' . $this->pCommaSeparated($node->vars) . ';';
948
-    }
949
-
950
-    protected function pStmt_Global(Stmt\Global_ $node) {
951
-        return 'global ' . $this->pCommaSeparated($node->vars) . ';';
952
-    }
953
-
954
-    protected function pStmt_StaticVar(Stmt\StaticVar $node) {
955
-        return $this->p($node->var)
956
-             . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
957
-    }
958
-
959
-    protected function pStmt_Unset(Stmt\Unset_ $node) {
960
-        return 'unset(' . $this->pCommaSeparated($node->vars) . ');';
961
-    }
962
-
963
-    protected function pStmt_InlineHTML(Stmt\InlineHTML $node) {
964
-        $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : '';
965
-        return '?>' . $newline . $node->value . '<?php ';
966
-    }
967
-
968
-    protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) {
969
-        return '__halt_compiler();' . $node->remaining;
970
-    }
971
-
972
-    protected function pStmt_Nop(Stmt\Nop $node) {
973
-        return '';
974
-    }
975
-
976
-    // Helpers
977
-
978
-    protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) {
979
-        return $this->pAttrGroups($node->attrGroups, $node->name === null)
980
-            . $this->pModifiers($node->flags)
981
-            . 'class' . $afterClassToken
982
-            . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '')
983
-            . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
984
-            . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
985
-    }
986
-
987
-    protected function pObjectProperty($node) {
988
-        if ($node instanceof Expr) {
989
-            return '{' . $this->p($node) . '}';
990
-        } else {
991
-            return $node;
992
-        }
993
-    }
994
-
995
-    protected function pEncapsList(array $encapsList, $quote) {
996
-        $return = '';
997
-        foreach ($encapsList as $element) {
998
-            if ($element instanceof Scalar\EncapsedStringPart) {
999
-                $return .= $this->escapeString($element->value, $quote);
1000
-            } else {
1001
-                $return .= '{' . $this->p($element) . '}';
1002
-            }
1003
-        }
1004
-
1005
-        return $return;
1006
-    }
1007
-
1008
-    protected function pSingleQuotedString(string $string) {
1009
-        return '\'' . addcslashes($string, '\'\\') . '\'';
1010
-    }
1011
-
1012
-    protected function escapeString($string, $quote) {
1013
-        if (null === $quote) {
1014
-            // For doc strings, don't escape newlines
1015
-            $escaped = addcslashes($string, "\t\f\v$\\");
1016
-        } else {
1017
-            $escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\");
1018
-        }
1019
-
1020
-        // Escape control characters and non-UTF-8 characters.
1021
-        // Regex based on https://stackoverflow.com/a/11709412/385378.
1022
-        $regex = '/(
343
+	protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) {
344
+		return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right);
345
+	}
346
+
347
+	protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) {
348
+		return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right);
349
+	}
350
+
351
+	protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) {
352
+		return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right);
353
+	}
354
+
355
+	protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) {
356
+		return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right);
357
+	}
358
+
359
+	protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) {
360
+		return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right);
361
+	}
362
+
363
+	protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) {
364
+		return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right);
365
+	}
366
+
367
+	protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) {
368
+		return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right);
369
+	}
370
+
371
+	protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) {
372
+		return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right);
373
+	}
374
+
375
+	protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) {
376
+		return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right);
377
+	}
378
+
379
+	protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) {
380
+		return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right);
381
+	}
382
+
383
+	protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) {
384
+		return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right);
385
+	}
386
+
387
+	protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) {
388
+		return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right);
389
+	}
390
+
391
+	protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) {
392
+		return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right);
393
+	}
394
+
395
+	protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) {
396
+		return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right);
397
+	}
398
+
399
+	protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) {
400
+		return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right);
401
+	}
402
+
403
+	protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) {
404
+		return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right);
405
+	}
406
+
407
+	protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) {
408
+		return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right);
409
+	}
410
+
411
+	protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) {
412
+		return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right);
413
+	}
414
+
415
+	protected function pExpr_Instanceof(Expr\Instanceof_ $node) {
416
+		list($precedence, $associativity) = $this->precedenceMap[Expr\Instanceof_::class];
417
+		return $this->pPrec($node->expr, $precedence, $associativity, -1)
418
+			 . ' instanceof '
419
+			 . $this->pNewVariable($node->class);
420
+	}
421
+
422
+	// Unary expressions
423
+
424
+	protected function pExpr_BooleanNot(Expr\BooleanNot $node) {
425
+		return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr);
426
+	}
427
+
428
+	protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) {
429
+		return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr);
430
+	}
431
+
432
+	protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
433
+		if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) {
434
+			// Enforce -(-$expr) instead of --$expr
435
+			return '-(' . $this->p($node->expr) . ')';
436
+		}
437
+		return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr);
438
+	}
439
+
440
+	protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
441
+		if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) {
442
+			// Enforce +(+$expr) instead of ++$expr
443
+			return '+(' . $this->p($node->expr) . ')';
444
+		}
445
+		return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr);
446
+	}
447
+
448
+	protected function pExpr_PreInc(Expr\PreInc $node) {
449
+		return $this->pPrefixOp(Expr\PreInc::class, '++', $node->var);
450
+	}
451
+
452
+	protected function pExpr_PreDec(Expr\PreDec $node) {
453
+		return $this->pPrefixOp(Expr\PreDec::class, '--', $node->var);
454
+	}
455
+
456
+	protected function pExpr_PostInc(Expr\PostInc $node) {
457
+		return $this->pPostfixOp(Expr\PostInc::class, $node->var, '++');
458
+	}
459
+
460
+	protected function pExpr_PostDec(Expr\PostDec $node) {
461
+		return $this->pPostfixOp(Expr\PostDec::class, $node->var, '--');
462
+	}
463
+
464
+	protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) {
465
+		return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr);
466
+	}
467
+
468
+	protected function pExpr_YieldFrom(Expr\YieldFrom $node) {
469
+		return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr);
470
+	}
471
+
472
+	protected function pExpr_Print(Expr\Print_ $node) {
473
+		return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr);
474
+	}
475
+
476
+	// Casts
477
+
478
+	protected function pExpr_Cast_Int(Cast\Int_ $node) {
479
+		return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr);
480
+	}
481
+
482
+	protected function pExpr_Cast_Double(Cast\Double $node) {
483
+		$kind = $node->getAttribute('kind', Cast\Double::KIND_DOUBLE);
484
+		if ($kind === Cast\Double::KIND_DOUBLE) {
485
+			$cast = '(double)';
486
+		} elseif ($kind === Cast\Double::KIND_FLOAT) {
487
+			$cast = '(float)';
488
+		} elseif ($kind === Cast\Double::KIND_REAL) {
489
+			$cast = '(real)';
490
+		}
491
+		return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr);
492
+	}
493
+
494
+	protected function pExpr_Cast_String(Cast\String_ $node) {
495
+		return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr);
496
+	}
497
+
498
+	protected function pExpr_Cast_Array(Cast\Array_ $node) {
499
+		return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr);
500
+	}
501
+
502
+	protected function pExpr_Cast_Object(Cast\Object_ $node) {
503
+		return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr);
504
+	}
505
+
506
+	protected function pExpr_Cast_Bool(Cast\Bool_ $node) {
507
+		return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr);
508
+	}
509
+
510
+	protected function pExpr_Cast_Unset(Cast\Unset_ $node) {
511
+		return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr);
512
+	}
513
+
514
+	// Function calls and similar constructs
515
+
516
+	protected function pExpr_FuncCall(Expr\FuncCall $node) {
517
+		return $this->pCallLhs($node->name)
518
+			 . '(' . $this->pMaybeMultiline($node->args) . ')';
519
+	}
520
+
521
+	protected function pExpr_MethodCall(Expr\MethodCall $node) {
522
+		return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name)
523
+			 . '(' . $this->pMaybeMultiline($node->args) . ')';
524
+	}
525
+
526
+	protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node) {
527
+		return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name)
528
+			. '(' . $this->pMaybeMultiline($node->args) . ')';
529
+	}
530
+
531
+	protected function pExpr_StaticCall(Expr\StaticCall $node) {
532
+		return $this->pStaticDereferenceLhs($node->class) . '::'
533
+			 . ($node->name instanceof Expr
534
+				? ($node->name instanceof Expr\Variable
535
+				   ? $this->p($node->name)
536
+				   : '{' . $this->p($node->name) . '}')
537
+				: $node->name)
538
+			 . '(' . $this->pMaybeMultiline($node->args) . ')';
539
+	}
540
+
541
+	protected function pExpr_Empty(Expr\Empty_ $node) {
542
+		return 'empty(' . $this->p($node->expr) . ')';
543
+	}
544
+
545
+	protected function pExpr_Isset(Expr\Isset_ $node) {
546
+		return 'isset(' . $this->pCommaSeparated($node->vars) . ')';
547
+	}
548
+
549
+	protected function pExpr_Eval(Expr\Eval_ $node) {
550
+		return 'eval(' . $this->p($node->expr) . ')';
551
+	}
552
+
553
+	protected function pExpr_Include(Expr\Include_ $node) {
554
+		static $map = [
555
+			Expr\Include_::TYPE_INCLUDE      => 'include',
556
+			Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once',
557
+			Expr\Include_::TYPE_REQUIRE      => 'require',
558
+			Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once',
559
+		];
560
+
561
+		return $map[$node->type] . ' ' . $this->p($node->expr);
562
+	}
563
+
564
+	protected function pExpr_List(Expr\List_ $node) {
565
+		return 'list(' . $this->pCommaSeparated($node->items) . ')';
566
+	}
567
+
568
+	// Other
569
+
570
+	protected function pExpr_Error(Expr\Error $node) {
571
+		throw new \LogicException('Cannot pretty-print AST with Error nodes');
572
+	}
573
+
574
+	protected function pExpr_Variable(Expr\Variable $node) {
575
+		if ($node->name instanceof Expr) {
576
+			return '${' . $this->p($node->name) . '}';
577
+		} else {
578
+			return '$' . $node->name;
579
+		}
580
+	}
581
+
582
+	protected function pExpr_Array(Expr\Array_ $node) {
583
+		$syntax = $node->getAttribute('kind',
584
+			$this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG);
585
+		if ($syntax === Expr\Array_::KIND_SHORT) {
586
+			return '[' . $this->pMaybeMultiline($node->items, true) . ']';
587
+		} else {
588
+			return 'array(' . $this->pMaybeMultiline($node->items, true) . ')';
589
+		}
590
+	}
591
+
592
+	protected function pExpr_ArrayItem(Expr\ArrayItem $node) {
593
+		return (null !== $node->key ? $this->p($node->key) . ' => ' : '')
594
+			 . ($node->byRef ? '&' : '')
595
+			 . ($node->unpack ? '...' : '')
596
+			 . $this->p($node->value);
597
+	}
598
+
599
+	protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) {
600
+		return $this->pDereferenceLhs($node->var)
601
+			 . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']';
602
+	}
603
+
604
+	protected function pExpr_ConstFetch(Expr\ConstFetch $node) {
605
+		return $this->p($node->name);
606
+	}
607
+
608
+	protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
609
+		return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name);
610
+	}
611
+
612
+	protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
613
+		return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name);
614
+	}
615
+
616
+	protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node) {
617
+		return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name);
618
+	}
619
+
620
+	protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
621
+		return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
622
+	}
623
+
624
+	protected function pExpr_ShellExec(Expr\ShellExec $node) {
625
+		return '`' . $this->pEncapsList($node->parts, '`') . '`';
626
+	}
627
+
628
+	protected function pExpr_Closure(Expr\Closure $node) {
629
+		return $this->pAttrGroups($node->attrGroups, true)
630
+			 . ($node->static ? 'static ' : '')
631
+			 . 'function ' . ($node->byRef ? '&' : '')
632
+			 . '(' . $this->pCommaSeparated($node->params) . ')'
633
+			 . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '')
634
+			 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
635
+			 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
636
+	}
637
+
638
+	protected function pExpr_Match(Expr\Match_ $node) {
639
+		return 'match (' . $this->p($node->cond) . ') {'
640
+			. $this->pCommaSeparatedMultiline($node->arms, true)
641
+			. $this->nl
642
+			. '}';
643
+	}
644
+
645
+	protected function pMatchArm(Node\MatchArm $node) {
646
+		return ($node->conds ? $this->pCommaSeparated($node->conds) : 'default')
647
+			. ' => ' . $this->p($node->body);
648
+	}
649
+
650
+	protected function pExpr_ArrowFunction(Expr\ArrowFunction $node) {
651
+		return $this->pAttrGroups($node->attrGroups, true)
652
+			. ($node->static ? 'static ' : '')
653
+			. 'fn' . ($node->byRef ? '&' : '')
654
+			. '(' . $this->pCommaSeparated($node->params) . ')'
655
+			. (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
656
+			. ' => '
657
+			. $this->p($node->expr);
658
+	}
659
+
660
+	protected function pExpr_ClosureUse(Expr\ClosureUse $node) {
661
+		return ($node->byRef ? '&' : '') . $this->p($node->var);
662
+	}
663
+
664
+	protected function pExpr_New(Expr\New_ $node) {
665
+		if ($node->class instanceof Stmt\Class_) {
666
+			$args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : '';
667
+			return 'new ' . $this->pClassCommon($node->class, $args);
668
+		}
669
+		return 'new ' . $this->pNewVariable($node->class)
670
+			. '(' . $this->pMaybeMultiline($node->args) . ')';
671
+	}
672
+
673
+	protected function pExpr_Clone(Expr\Clone_ $node) {
674
+		return 'clone ' . $this->p($node->expr);
675
+	}
676
+
677
+	protected function pExpr_Ternary(Expr\Ternary $node) {
678
+		// a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator.
679
+		// this is okay because the part between ? and : never needs parentheses.
680
+		return $this->pInfixOp(Expr\Ternary::class,
681
+			$node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else
682
+		);
683
+	}
684
+
685
+	protected function pExpr_Exit(Expr\Exit_ $node) {
686
+		$kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE);
687
+		return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die')
688
+			 . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : '');
689
+	}
690
+
691
+	protected function pExpr_Throw(Expr\Throw_ $node) {
692
+		return 'throw ' . $this->p($node->expr);
693
+	}
694
+
695
+	protected function pExpr_Yield(Expr\Yield_ $node) {
696
+		if ($node->value === null) {
697
+			return 'yield';
698
+		} else {
699
+			// this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary
700
+			return '(yield '
701
+				 . ($node->key !== null ? $this->p($node->key) . ' => ' : '')
702
+				 . $this->p($node->value)
703
+				 . ')';
704
+		}
705
+	}
706
+
707
+	// Declarations
708
+
709
+	protected function pStmt_Namespace(Stmt\Namespace_ $node) {
710
+		if ($this->canUseSemicolonNamespaces) {
711
+			return 'namespace ' . $this->p($node->name) . ';'
712
+				 . $this->nl . $this->pStmts($node->stmts, false);
713
+		} else {
714
+			return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '')
715
+				 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
716
+		}
717
+	}
718
+
719
+	protected function pStmt_Use(Stmt\Use_ $node) {
720
+		return 'use ' . $this->pUseType($node->type)
721
+			 . $this->pCommaSeparated($node->uses) . ';';
722
+	}
723
+
724
+	protected function pStmt_GroupUse(Stmt\GroupUse $node) {
725
+		return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix)
726
+			 . '\{' . $this->pCommaSeparated($node->uses) . '};';
727
+	}
728
+
729
+	protected function pStmt_UseUse(Stmt\UseUse $node) {
730
+		return $this->pUseType($node->type) . $this->p($node->name)
731
+			 . (null !== $node->alias ? ' as ' . $node->alias : '');
732
+	}
733
+
734
+	protected function pUseType($type) {
735
+		return $type === Stmt\Use_::TYPE_FUNCTION ? 'function '
736
+			: ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : '');
737
+	}
738
+
739
+	protected function pStmt_Interface(Stmt\Interface_ $node) {
740
+		return $this->pAttrGroups($node->attrGroups)
741
+			 . 'interface ' . $node->name
742
+			 . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '')
743
+			 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
744
+	}
745
+
746
+	protected function pStmt_Enum(Stmt\Enum_ $node) {
747
+		return $this->pAttrGroups($node->attrGroups)
748
+			 . 'enum ' . $node->name
749
+			 . ($node->scalarType ? " : $node->scalarType" : '')
750
+			 . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
751
+			 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
752
+	}
753
+
754
+	protected function pStmt_Class(Stmt\Class_ $node) {
755
+		return $this->pClassCommon($node, ' ' . $node->name);
756
+	}
757
+
758
+	protected function pStmt_Trait(Stmt\Trait_ $node) {
759
+		return $this->pAttrGroups($node->attrGroups)
760
+			 . 'trait ' . $node->name
761
+			 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
762
+	}
763
+
764
+	protected function pStmt_EnumCase(Stmt\EnumCase $node) {
765
+		return $this->pAttrGroups($node->attrGroups)
766
+			 . 'case ' . $node->name
767
+			 . ($node->expr ? ' = ' . $this->p($node->expr) : '')
768
+			 . ';';
769
+	}
770
+
771
+	protected function pStmt_TraitUse(Stmt\TraitUse $node) {
772
+		return 'use ' . $this->pCommaSeparated($node->traits)
773
+			 . (empty($node->adaptations)
774
+				? ';'
775
+				: ' {' . $this->pStmts($node->adaptations) . $this->nl . '}');
776
+	}
777
+
778
+	protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) {
779
+		return $this->p($node->trait) . '::' . $node->method
780
+			 . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
781
+	}
782
+
783
+	protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) {
784
+		return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
785
+			 . $node->method . ' as'
786
+			 . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
787
+			 . (null !== $node->newName     ? ' ' . $node->newName                        : '')
788
+			 . ';';
789
+	}
790
+
791
+	protected function pStmt_Property(Stmt\Property $node) {
792
+		return $this->pAttrGroups($node->attrGroups)
793
+			. (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags))
794
+			. ($node->type ? $this->p($node->type) . ' ' : '')
795
+			. $this->pCommaSeparated($node->props) . ';';
796
+	}
797
+
798
+	protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) {
799
+		return '$' . $node->name
800
+			 . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
801
+	}
802
+
803
+	protected function pStmt_ClassMethod(Stmt\ClassMethod $node) {
804
+		return $this->pAttrGroups($node->attrGroups)
805
+			 . $this->pModifiers($node->flags)
806
+			 . 'function ' . ($node->byRef ? '&' : '') . $node->name
807
+			 . '(' . $this->pMaybeMultiline($node->params) . ')'
808
+			 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
809
+			 . (null !== $node->stmts
810
+				? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'
811
+				: ';');
812
+	}
813
+
814
+	protected function pStmt_ClassConst(Stmt\ClassConst $node) {
815
+		return $this->pAttrGroups($node->attrGroups)
816
+			 . $this->pModifiers($node->flags)
817
+			 . 'const '
818
+			 . (null !== $node->type ? $this->p($node->type) . ' ' : '')
819
+			 . $this->pCommaSeparated($node->consts) . ';';
820
+	}
821
+
822
+	protected function pStmt_Function(Stmt\Function_ $node) {
823
+		return $this->pAttrGroups($node->attrGroups)
824
+			 . 'function ' . ($node->byRef ? '&' : '') . $node->name
825
+			 . '(' . $this->pCommaSeparated($node->params) . ')'
826
+			 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
827
+			 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
828
+	}
829
+
830
+	protected function pStmt_Const(Stmt\Const_ $node) {
831
+		return 'const ' . $this->pCommaSeparated($node->consts) . ';';
832
+	}
833
+
834
+	protected function pStmt_Declare(Stmt\Declare_ $node) {
835
+		return 'declare (' . $this->pCommaSeparated($node->declares) . ')'
836
+			 . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';');
837
+	}
838
+
839
+	protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) {
840
+		return $node->key . '=' . $this->p($node->value);
841
+	}
842
+
843
+	// Control flow
844
+
845
+	protected function pStmt_If(Stmt\If_ $node) {
846
+		return 'if (' . $this->p($node->cond) . ') {'
847
+			 . $this->pStmts($node->stmts) . $this->nl . '}'
848
+			 . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '')
849
+			 . (null !== $node->else ? ' ' . $this->p($node->else) : '');
850
+	}
851
+
852
+	protected function pStmt_ElseIf(Stmt\ElseIf_ $node) {
853
+		return 'elseif (' . $this->p($node->cond) . ') {'
854
+			 . $this->pStmts($node->stmts) . $this->nl . '}';
855
+	}
856
+
857
+	protected function pStmt_Else(Stmt\Else_ $node) {
858
+		return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}';
859
+	}
860
+
861
+	protected function pStmt_For(Stmt\For_ $node) {
862
+		return 'for ('
863
+			 . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '')
864
+			 . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '')
865
+			 . $this->pCommaSeparated($node->loop)
866
+			 . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
867
+	}
868
+
869
+	protected function pStmt_Foreach(Stmt\Foreach_ $node) {
870
+		return 'foreach (' . $this->p($node->expr) . ' as '
871
+			 . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '')
872
+			 . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {'
873
+			 . $this->pStmts($node->stmts) . $this->nl . '}';
874
+	}
875
+
876
+	protected function pStmt_While(Stmt\While_ $node) {
877
+		return 'while (' . $this->p($node->cond) . ') {'
878
+			 . $this->pStmts($node->stmts) . $this->nl . '}';
879
+	}
880
+
881
+	protected function pStmt_Do(Stmt\Do_ $node) {
882
+		return 'do {' . $this->pStmts($node->stmts) . $this->nl
883
+			 . '} while (' . $this->p($node->cond) . ');';
884
+	}
885
+
886
+	protected function pStmt_Switch(Stmt\Switch_ $node) {
887
+		return 'switch (' . $this->p($node->cond) . ') {'
888
+			 . $this->pStmts($node->cases) . $this->nl . '}';
889
+	}
890
+
891
+	protected function pStmt_Case(Stmt\Case_ $node) {
892
+		return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
893
+			 . $this->pStmts($node->stmts);
894
+	}
895
+
896
+	protected function pStmt_TryCatch(Stmt\TryCatch $node) {
897
+		return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}'
898
+			 . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '')
899
+			 . ($node->finally !== null ? ' ' . $this->p($node->finally) : '');
900
+	}
901
+
902
+	protected function pStmt_Catch(Stmt\Catch_ $node) {
903
+		return 'catch (' . $this->pImplode($node->types, '|')
904
+			 . ($node->var !== null ? ' ' . $this->p($node->var) : '')
905
+			 . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
906
+	}
907
+
908
+	protected function pStmt_Finally(Stmt\Finally_ $node) {
909
+		return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}';
910
+	}
911
+
912
+	protected function pStmt_Break(Stmt\Break_ $node) {
913
+		return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
914
+	}
915
+
916
+	protected function pStmt_Continue(Stmt\Continue_ $node) {
917
+		return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
918
+	}
919
+
920
+	protected function pStmt_Return(Stmt\Return_ $node) {
921
+		return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
922
+	}
923
+
924
+	protected function pStmt_Throw(Stmt\Throw_ $node) {
925
+		return 'throw ' . $this->p($node->expr) . ';';
926
+	}
927
+
928
+	protected function pStmt_Label(Stmt\Label $node) {
929
+		return $node->name . ':';
930
+	}
931
+
932
+	protected function pStmt_Goto(Stmt\Goto_ $node) {
933
+		return 'goto ' . $node->name . ';';
934
+	}
935
+
936
+	// Other
937
+
938
+	protected function pStmt_Expression(Stmt\Expression $node) {
939
+		return $this->p($node->expr) . ';';
940
+	}
941
+
942
+	protected function pStmt_Echo(Stmt\Echo_ $node) {
943
+		return 'echo ' . $this->pCommaSeparated($node->exprs) . ';';
944
+	}
945
+
946
+	protected function pStmt_Static(Stmt\Static_ $node) {
947
+		return 'static ' . $this->pCommaSeparated($node->vars) . ';';
948
+	}
949
+
950
+	protected function pStmt_Global(Stmt\Global_ $node) {
951
+		return 'global ' . $this->pCommaSeparated($node->vars) . ';';
952
+	}
953
+
954
+	protected function pStmt_StaticVar(Stmt\StaticVar $node) {
955
+		return $this->p($node->var)
956
+			 . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
957
+	}
958
+
959
+	protected function pStmt_Unset(Stmt\Unset_ $node) {
960
+		return 'unset(' . $this->pCommaSeparated($node->vars) . ');';
961
+	}
962
+
963
+	protected function pStmt_InlineHTML(Stmt\InlineHTML $node) {
964
+		$newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : '';
965
+		return '?>' . $newline . $node->value . '<?php ';
966
+	}
967
+
968
+	protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) {
969
+		return '__halt_compiler();' . $node->remaining;
970
+	}
971
+
972
+	protected function pStmt_Nop(Stmt\Nop $node) {
973
+		return '';
974
+	}
975
+
976
+	// Helpers
977
+
978
+	protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) {
979
+		return $this->pAttrGroups($node->attrGroups, $node->name === null)
980
+			. $this->pModifiers($node->flags)
981
+			. 'class' . $afterClassToken
982
+			. (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '')
983
+			. (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
984
+			. $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
985
+	}
986
+
987
+	protected function pObjectProperty($node) {
988
+		if ($node instanceof Expr) {
989
+			return '{' . $this->p($node) . '}';
990
+		} else {
991
+			return $node;
992
+		}
993
+	}
994
+
995
+	protected function pEncapsList(array $encapsList, $quote) {
996
+		$return = '';
997
+		foreach ($encapsList as $element) {
998
+			if ($element instanceof Scalar\EncapsedStringPart) {
999
+				$return .= $this->escapeString($element->value, $quote);
1000
+			} else {
1001
+				$return .= '{' . $this->p($element) . '}';
1002
+			}
1003
+		}
1004
+
1005
+		return $return;
1006
+	}
1007
+
1008
+	protected function pSingleQuotedString(string $string) {
1009
+		return '\'' . addcslashes($string, '\'\\') . '\'';
1010
+	}
1011
+
1012
+	protected function escapeString($string, $quote) {
1013
+		if (null === $quote) {
1014
+			// For doc strings, don't escape newlines
1015
+			$escaped = addcslashes($string, "\t\f\v$\\");
1016
+		} else {
1017
+			$escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\");
1018
+		}
1019
+
1020
+		// Escape control characters and non-UTF-8 characters.
1021
+		// Regex based on https://stackoverflow.com/a/11709412/385378.
1022
+		$regex = '/(
1023 1023
               [\x00-\x08\x0E-\x1F] # Control characters
1024 1024
             | [\xC0-\xC1] # Invalid UTF-8 Bytes
1025 1025
             | [\xF5-\xFF] # Invalid UTF-8 Bytes
@@ -1034,93 +1034,93 @@  discard block
 block discarded – undo
1034 1034
             | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
1035 1035
             | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
1036 1036
         )/x';
1037
-        return preg_replace_callback($regex, function ($matches) {
1038
-            assert(strlen($matches[0]) === 1);
1039
-            $hex = dechex(ord($matches[0]));;
1040
-            return '\\x' . str_pad($hex, 2, '0', \STR_PAD_LEFT);
1041
-        }, $escaped);
1042
-    }
1043
-
1044
-    protected function containsEndLabel($string, $label, $atStart = true, $atEnd = true) {
1045
-        $start = $atStart ? '(?:^|[\r\n])' : '[\r\n]';
1046
-        $end = $atEnd ? '(?:$|[;\r\n])' : '[;\r\n]';
1047
-        return false !== strpos($string, $label)
1048
-            && preg_match('/' . $start . $label . $end . '/', $string);
1049
-    }
1050
-
1051
-    protected function encapsedContainsEndLabel(array $parts, $label) {
1052
-        foreach ($parts as $i => $part) {
1053
-            $atStart = $i === 0;
1054
-            $atEnd = $i === count($parts) - 1;
1055
-            if ($part instanceof Scalar\EncapsedStringPart
1056
-                && $this->containsEndLabel($part->value, $label, $atStart, $atEnd)
1057
-            ) {
1058
-                return true;
1059
-            }
1060
-        }
1061
-        return false;
1062
-    }
1063
-
1064
-    protected function pDereferenceLhs(Node $node) {
1065
-        if (!$this->dereferenceLhsRequiresParens($node)) {
1066
-            return $this->p($node);
1067
-        } else  {
1068
-            return '(' . $this->p($node) . ')';
1069
-        }
1070
-    }
1071
-
1072
-    protected function pStaticDereferenceLhs(Node $node) {
1073
-        if (!$this->staticDereferenceLhsRequiresParens($node)) {
1074
-            return $this->p($node);
1075
-        } else {
1076
-            return '(' . $this->p($node) . ')';
1077
-        }
1078
-    }
1079
-
1080
-    protected function pCallLhs(Node $node) {
1081
-        if (!$this->callLhsRequiresParens($node)) {
1082
-            return $this->p($node);
1083
-        } else  {
1084
-            return '(' . $this->p($node) . ')';
1085
-        }
1086
-    }
1087
-
1088
-    protected function pNewVariable(Node $node): string {
1089
-        if (!$this->newOperandRequiresParens($node)) {
1090
-            return $this->p($node);
1091
-        } else {
1092
-            return '(' . $this->p($node) . ')';
1093
-        }
1094
-    }
1095
-
1096
-    /**
1097
-     * @param Node[] $nodes
1098
-     * @return bool
1099
-     */
1100
-    protected function hasNodeWithComments(array $nodes) {
1101
-        foreach ($nodes as $node) {
1102
-            if ($node && $node->getComments()) {
1103
-                return true;
1104
-            }
1105
-        }
1106
-        return false;
1107
-    }
1108
-
1109
-    protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) {
1110
-        if (!$this->hasNodeWithComments($nodes)) {
1111
-            return $this->pCommaSeparated($nodes);
1112
-        } else {
1113
-            return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl;
1114
-        }
1115
-    }
1116
-
1117
-    protected function pAttrGroups(array $nodes, bool $inline = false): string {
1118
-        $result = '';
1119
-        $sep = $inline ? ' ' : $this->nl;
1120
-        foreach ($nodes as $node) {
1121
-            $result .= $this->p($node) . $sep;
1122
-        }
1123
-
1124
-        return $result;
1125
-    }
1037
+		return preg_replace_callback($regex, function ($matches) {
1038
+			assert(strlen($matches[0]) === 1);
1039
+			$hex = dechex(ord($matches[0]));;
1040
+			return '\\x' . str_pad($hex, 2, '0', \STR_PAD_LEFT);
1041
+		}, $escaped);
1042
+	}
1043
+
1044
+	protected function containsEndLabel($string, $label, $atStart = true, $atEnd = true) {
1045
+		$start = $atStart ? '(?:^|[\r\n])' : '[\r\n]';
1046
+		$end = $atEnd ? '(?:$|[;\r\n])' : '[;\r\n]';
1047
+		return false !== strpos($string, $label)
1048
+			&& preg_match('/' . $start . $label . $end . '/', $string);
1049
+	}
1050
+
1051
+	protected function encapsedContainsEndLabel(array $parts, $label) {
1052
+		foreach ($parts as $i => $part) {
1053
+			$atStart = $i === 0;
1054
+			$atEnd = $i === count($parts) - 1;
1055
+			if ($part instanceof Scalar\EncapsedStringPart
1056
+				&& $this->containsEndLabel($part->value, $label, $atStart, $atEnd)
1057
+			) {
1058
+				return true;
1059
+			}
1060
+		}
1061
+		return false;
1062
+	}
1063
+
1064
+	protected function pDereferenceLhs(Node $node) {
1065
+		if (!$this->dereferenceLhsRequiresParens($node)) {
1066
+			return $this->p($node);
1067
+		} else  {
1068
+			return '(' . $this->p($node) . ')';
1069
+		}
1070
+	}
1071
+
1072
+	protected function pStaticDereferenceLhs(Node $node) {
1073
+		if (!$this->staticDereferenceLhsRequiresParens($node)) {
1074
+			return $this->p($node);
1075
+		} else {
1076
+			return '(' . $this->p($node) . ')';
1077
+		}
1078
+	}
1079
+
1080
+	protected function pCallLhs(Node $node) {
1081
+		if (!$this->callLhsRequiresParens($node)) {
1082
+			return $this->p($node);
1083
+		} else  {
1084
+			return '(' . $this->p($node) . ')';
1085
+		}
1086
+	}
1087
+
1088
+	protected function pNewVariable(Node $node): string {
1089
+		if (!$this->newOperandRequiresParens($node)) {
1090
+			return $this->p($node);
1091
+		} else {
1092
+			return '(' . $this->p($node) . ')';
1093
+		}
1094
+	}
1095
+
1096
+	/**
1097
+	 * @param Node[] $nodes
1098
+	 * @return bool
1099
+	 */
1100
+	protected function hasNodeWithComments(array $nodes) {
1101
+		foreach ($nodes as $node) {
1102
+			if ($node && $node->getComments()) {
1103
+				return true;
1104
+			}
1105
+		}
1106
+		return false;
1107
+	}
1108
+
1109
+	protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) {
1110
+		if (!$this->hasNodeWithComments($nodes)) {
1111
+			return $this->pCommaSeparated($nodes);
1112
+		} else {
1113
+			return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl;
1114
+		}
1115
+	}
1116
+
1117
+	protected function pAttrGroups(array $nodes, bool $inline = false): string {
1118
+		$result = '';
1119
+		$sep = $inline ? ' ' : $this->nl;
1120
+		foreach ($nodes as $node) {
1121
+			$result .= $this->p($node) . $sep;
1122
+		}
1123
+
1124
+		return $result;
1125
+	}
1126 1126
 }
Please login to merge, or discard this patch.
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -20,16 +20,16 @@  discard block
 block discarded – undo
20 20
     protected function pParam(Node\Param $node) {
21 21
         return $this->pAttrGroups($node->attrGroups, true)
22 22
              . $this->pModifiers($node->flags)
23
-             . ($node->type ? $this->p($node->type) . ' ' : '')
23
+             . ($node->type ? $this->p($node->type).' ' : '')
24 24
              . ($node->byRef ? '&' : '')
25 25
              . ($node->variadic ? '...' : '')
26 26
              . $this->p($node->var)
27
-             . ($node->default ? ' = ' . $this->p($node->default) : '');
27
+             . ($node->default ? ' = '.$this->p($node->default) : '');
28 28
     }
29 29
 
30 30
     protected function pArg(Node\Arg $node) {
31
-        return ($node->name ? $node->name->toString() . ': ' : '')
32
-             . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '')
31
+        return ($node->name ? $node->name->toString().': ' : '')
32
+             . ($node->byRef ? '&' : '').($node->unpack ? '...' : '')
33 33
              . $this->p($node->value);
34 34
     }
35 35
 
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
     }
39 39
 
40 40
     protected function pConst(Node\Const_ $node) {
41
-        return $node->name . ' = ' . $this->p($node->value);
41
+        return $node->name.' = '.$this->p($node->value);
42 42
     }
43 43
 
44 44
     protected function pNullableType(Node\NullableType $node) {
45
-        return '?' . $this->p($node->type);
45
+        return '?'.$this->p($node->type);
46 46
     }
47 47
 
48 48
     protected function pUnionType(Node\UnionType $node) {
49 49
         $types = [];
50 50
         foreach ($node->types as $typeNode) {
51 51
             if ($typeNode instanceof Node\IntersectionType) {
52
-                $types[] = '('. $this->p($typeNode) . ')';
52
+                $types[] = '('.$this->p($typeNode).')';
53 53
                 continue;
54 54
             }
55 55
             $types[] = $this->p($typeNode);
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
     }
67 67
 
68 68
     protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) {
69
-        return '$' . $node->name;
69
+        return '$'.$node->name;
70 70
     }
71 71
 
72 72
     protected function pAttribute(Node\Attribute $node) {
73 73
         return $this->p($node->name)
74
-             . ($node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : '');
74
+             . ($node->args ? '('.$this->pCommaSeparated($node->args).')' : '');
75 75
     }
76 76
 
77 77
     protected function pAttributeGroup(Node\AttributeGroup $node) {
78
-        return '#[' . $this->pCommaSeparated($node->attrs) . ']';
78
+        return '#['.$this->pCommaSeparated($node->attrs).']';
79 79
     }
80 80
 
81 81
     // Names
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     protected function pName_FullyQualified(Name\FullyQualified $node) {
88
-        return '\\' . implode('\\', $node->parts);
88
+        return '\\'.implode('\\', $node->parts);
89 89
     }
90 90
 
91 91
     protected function pName_Relative(Name\Relative $node) {
92
-        return 'namespace\\' . implode('\\', $node->parts);
92
+        return 'namespace\\'.implode('\\', $node->parts);
93 93
     }
94 94
 
95 95
     // Magic Constants
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                 $label = $node->getAttribute('docLabel');
136 136
                 if ($label && !$this->containsEndLabel($node->value, $label)) {
137 137
                     if ($node->value === '') {
138
-                        return "<<<'$label'\n$label" . $this->docStringEndToken;
138
+                        return "<<<'$label'\n$label".$this->docStringEndToken;
139 139
                     }
140 140
 
141 141
                     return "<<<'$label'\n$node->value\n$label"
@@ -148,16 +148,16 @@  discard block
 block discarded – undo
148 148
                 $label = $node->getAttribute('docLabel');
149 149
                 if ($label && !$this->containsEndLabel($node->value, $label)) {
150 150
                     if ($node->value === '') {
151
-                        return "<<<$label\n$label" . $this->docStringEndToken;
151
+                        return "<<<$label\n$label".$this->docStringEndToken;
152 152
                     }
153 153
 
154 154
                     $escaped = $this->escapeString($node->value, null);
155
-                    return "<<<$label\n" . $escaped . "\n$label"
155
+                    return "<<<$label\n".$escaped."\n$label"
156 156
                          . $this->docStringEndToken;
157 157
                 }
158 158
             /* break missing intentionally */
159 159
             case Scalar\String_::KIND_DOUBLE_QUOTED:
160
-                return '"' . $this->escapeString($node->value, '"') . '"';
160
+                return '"'.$this->escapeString($node->value, '"').'"';
161 161
         }
162 162
         throw new \Exception('Invalid string kind');
163 163
     }
@@ -170,26 +170,26 @@  discard block
 block discarded – undo
170 170
                     && $node->parts[0] instanceof Scalar\EncapsedStringPart
171 171
                     && $node->parts[0]->value === ''
172 172
                 ) {
173
-                    return "<<<$label\n$label" . $this->docStringEndToken;
173
+                    return "<<<$label\n$label".$this->docStringEndToken;
174 174
                 }
175 175
 
176
-                return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label"
176
+                return "<<<$label\n".$this->pEncapsList($node->parts, null)."\n$label"
177 177
                      . $this->docStringEndToken;
178 178
             }
179 179
         }
180
-        return '"' . $this->pEncapsList($node->parts, '"') . '"';
180
+        return '"'.$this->pEncapsList($node->parts, '"').'"';
181 181
     }
182 182
 
183 183
     protected function pScalar_LNumber(Scalar\LNumber $node) {
184 184
         if ($node->value === -\PHP_INT_MAX-1) {
185 185
             // PHP_INT_MIN cannot be represented as a literal,
186 186
             // because the sign is not part of the literal
187
-            return '(-' . \PHP_INT_MAX . '-1)';
187
+            return '(-'.\PHP_INT_MAX.'-1)';
188 188
         }
189 189
 
190 190
         $kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC);
191 191
         if (Scalar\LNumber::KIND_DEC === $kind) {
192
-            return (string) $node->value;
192
+            return (string)$node->value;
193 193
         }
194 194
 
195 195
         if ($node->value < 0) {
@@ -197,15 +197,15 @@  discard block
 block discarded – undo
197 197
             $str = (string) -$node->value;
198 198
         } else {
199 199
             $sign = '';
200
-            $str = (string) $node->value;
200
+            $str = (string)$node->value;
201 201
         }
202 202
         switch ($kind) {
203 203
             case Scalar\LNumber::KIND_BIN:
204
-                return $sign . '0b' . base_convert($str, 10, 2);
204
+                return $sign.'0b'.base_convert($str, 10, 2);
205 205
             case Scalar\LNumber::KIND_OCT:
206
-                return $sign . '0' . base_convert($str, 10, 8);
206
+                return $sign.'0'.base_convert($str, 10, 8);
207 207
             case Scalar\LNumber::KIND_HEX:
208
-                return $sign . '0x' . base_convert($str, 10, 16);
208
+                return $sign.'0x'.base_convert($str, 10, 16);
209 209
         }
210 210
         throw new \Exception('Invalid number kind');
211 211
     }
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
         // Try to find a short full-precision representation
225 225
         $stringValue = sprintf('%.16G', $node->value);
226
-        if ($node->value !== (double) $stringValue) {
226
+        if ($node->value !== (double)$stringValue) {
227 227
             $stringValue = sprintf('%.17G', $node->value);
228 228
         }
229 229
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         $stringValue = str_replace(',', '.', $stringValue);
234 234
 
235 235
         // ensure that number is really printed as float
236
-        return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue;
236
+        return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue.'.0' : $stringValue;
237 237
     }
238 238
 
239 239
     protected function pScalar_EncapsedStringPart(Scalar\EncapsedStringPart $node) {
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
433 433
         if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) {
434 434
             // Enforce -(-$expr) instead of --$expr
435
-            return '-(' . $this->p($node->expr) . ')';
435
+            return '-('.$this->p($node->expr).')';
436 436
         }
437 437
         return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr);
438 438
     }
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
441 441
         if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) {
442 442
             // Enforce +(+$expr) instead of ++$expr
443
-            return '+(' . $this->p($node->expr) . ')';
443
+            return '+('.$this->p($node->expr).')';
444 444
         }
445 445
         return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr);
446 446
     }
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         } elseif ($kind === Cast\Double::KIND_REAL) {
489 489
             $cast = '(real)';
490 490
         }
491
-        return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr);
491
+        return $this->pPrefixOp(Cast\Double::class, $cast.' ', $node->expr);
492 492
     }
493 493
 
494 494
     protected function pExpr_Cast_String(Cast\String_ $node) {
@@ -515,39 +515,39 @@  discard block
 block discarded – undo
515 515
 
516 516
     protected function pExpr_FuncCall(Expr\FuncCall $node) {
517 517
         return $this->pCallLhs($node->name)
518
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
518
+             . '('.$this->pMaybeMultiline($node->args).')';
519 519
     }
520 520
 
521 521
     protected function pExpr_MethodCall(Expr\MethodCall $node) {
522
-        return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name)
523
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
522
+        return $this->pDereferenceLhs($node->var).'->'.$this->pObjectProperty($node->name)
523
+             . '('.$this->pMaybeMultiline($node->args).')';
524 524
     }
525 525
 
526 526
     protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node) {
527
-        return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name)
528
-            . '(' . $this->pMaybeMultiline($node->args) . ')';
527
+        return $this->pDereferenceLhs($node->var).'?->'.$this->pObjectProperty($node->name)
528
+            . '('.$this->pMaybeMultiline($node->args).')';
529 529
     }
530 530
 
531 531
     protected function pExpr_StaticCall(Expr\StaticCall $node) {
532
-        return $this->pStaticDereferenceLhs($node->class) . '::'
532
+        return $this->pStaticDereferenceLhs($node->class).'::'
533 533
              . ($node->name instanceof Expr
534 534
                 ? ($node->name instanceof Expr\Variable
535 535
                    ? $this->p($node->name)
536
-                   : '{' . $this->p($node->name) . '}')
536
+                   : '{'.$this->p($node->name).'}')
537 537
                 : $node->name)
538
-             . '(' . $this->pMaybeMultiline($node->args) . ')';
538
+             . '('.$this->pMaybeMultiline($node->args).')';
539 539
     }
540 540
 
541 541
     protected function pExpr_Empty(Expr\Empty_ $node) {
542
-        return 'empty(' . $this->p($node->expr) . ')';
542
+        return 'empty('.$this->p($node->expr).')';
543 543
     }
544 544
 
545 545
     protected function pExpr_Isset(Expr\Isset_ $node) {
546
-        return 'isset(' . $this->pCommaSeparated($node->vars) . ')';
546
+        return 'isset('.$this->pCommaSeparated($node->vars).')';
547 547
     }
548 548
 
549 549
     protected function pExpr_Eval(Expr\Eval_ $node) {
550
-        return 'eval(' . $this->p($node->expr) . ')';
550
+        return 'eval('.$this->p($node->expr).')';
551 551
     }
552 552
 
553 553
     protected function pExpr_Include(Expr\Include_ $node) {
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
             Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once',
559 559
         ];
560 560
 
561
-        return $map[$node->type] . ' ' . $this->p($node->expr);
561
+        return $map[$node->type].' '.$this->p($node->expr);
562 562
     }
563 563
 
564 564
     protected function pExpr_List(Expr\List_ $node) {
565
-        return 'list(' . $this->pCommaSeparated($node->items) . ')';
565
+        return 'list('.$this->pCommaSeparated($node->items).')';
566 566
     }
567 567
 
568 568
     // Other
@@ -573,9 +573,9 @@  discard block
 block discarded – undo
573 573
 
574 574
     protected function pExpr_Variable(Expr\Variable $node) {
575 575
         if ($node->name instanceof Expr) {
576
-            return '${' . $this->p($node->name) . '}';
576
+            return '${'.$this->p($node->name).'}';
577 577
         } else {
578
-            return '$' . $node->name;
578
+            return '$'.$node->name;
579 579
         }
580 580
     }
581 581
 
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
         $syntax = $node->getAttribute('kind',
584 584
             $this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG);
585 585
         if ($syntax === Expr\Array_::KIND_SHORT) {
586
-            return '[' . $this->pMaybeMultiline($node->items, true) . ']';
586
+            return '['.$this->pMaybeMultiline($node->items, true).']';
587 587
         } else {
588
-            return 'array(' . $this->pMaybeMultiline($node->items, true) . ')';
588
+            return 'array('.$this->pMaybeMultiline($node->items, true).')';
589 589
         }
590 590
     }
591 591
 
592 592
     protected function pExpr_ArrayItem(Expr\ArrayItem $node) {
593
-        return (null !== $node->key ? $this->p($node->key) . ' => ' : '')
593
+        return (null !== $node->key ? $this->p($node->key).' => ' : '')
594 594
              . ($node->byRef ? '&' : '')
595 595
              . ($node->unpack ? '...' : '')
596 596
              . $this->p($node->value);
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 
599 599
     protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) {
600 600
         return $this->pDereferenceLhs($node->var)
601
-             . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']';
601
+             . '['.(null !== $node->dim ? $this->p($node->dim) : '').']';
602 602
     }
603 603
 
604 604
     protected function pExpr_ConstFetch(Expr\ConstFetch $node) {
@@ -606,37 +606,37 @@  discard block
 block discarded – undo
606 606
     }
607 607
 
608 608
     protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
609
-        return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name);
609
+        return $this->pStaticDereferenceLhs($node->class).'::'.$this->pObjectProperty($node->name);
610 610
     }
611 611
 
612 612
     protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
613
-        return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name);
613
+        return $this->pDereferenceLhs($node->var).'->'.$this->pObjectProperty($node->name);
614 614
     }
615 615
 
616 616
     protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node) {
617
-        return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name);
617
+        return $this->pDereferenceLhs($node->var).'?->'.$this->pObjectProperty($node->name);
618 618
     }
619 619
 
620 620
     protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
621
-        return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
621
+        return $this->pStaticDereferenceLhs($node->class).'::$'.$this->pObjectProperty($node->name);
622 622
     }
623 623
 
624 624
     protected function pExpr_ShellExec(Expr\ShellExec $node) {
625
-        return '`' . $this->pEncapsList($node->parts, '`') . '`';
625
+        return '`'.$this->pEncapsList($node->parts, '`').'`';
626 626
     }
627 627
 
628 628
     protected function pExpr_Closure(Expr\Closure $node) {
629 629
         return $this->pAttrGroups($node->attrGroups, true)
630 630
              . ($node->static ? 'static ' : '')
631
-             . 'function ' . ($node->byRef ? '&' : '')
632
-             . '(' . $this->pCommaSeparated($node->params) . ')'
633
-             . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '')
634
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
635
-             . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
631
+             . 'function '.($node->byRef ? '&' : '')
632
+             . '('.$this->pCommaSeparated($node->params).')'
633
+             . (!empty($node->uses) ? ' use('.$this->pCommaSeparated($node->uses).')' : '')
634
+             . (null !== $node->returnType ? ' : '.$this->p($node->returnType) : '')
635
+             . ' {'.$this->pStmts($node->stmts).$this->nl.'}';
636 636
     }
637 637
 
638 638
     protected function pExpr_Match(Expr\Match_ $node) {
639
-        return 'match (' . $this->p($node->cond) . ') {'
639
+        return 'match ('.$this->p($node->cond).') {'
640 640
             . $this->pCommaSeparatedMultiline($node->arms, true)
641 641
             . $this->nl
642 642
             . '}';
@@ -644,52 +644,52 @@  discard block
 block discarded – undo
644 644
 
645 645
     protected function pMatchArm(Node\MatchArm $node) {
646 646
         return ($node->conds ? $this->pCommaSeparated($node->conds) : 'default')
647
-            . ' => ' . $this->p($node->body);
647
+            . ' => '.$this->p($node->body);
648 648
     }
649 649
 
650 650
     protected function pExpr_ArrowFunction(Expr\ArrowFunction $node) {
651 651
         return $this->pAttrGroups($node->attrGroups, true)
652 652
             . ($node->static ? 'static ' : '')
653
-            . 'fn' . ($node->byRef ? '&' : '')
654
-            . '(' . $this->pCommaSeparated($node->params) . ')'
655
-            . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
653
+            . 'fn'.($node->byRef ? '&' : '')
654
+            . '('.$this->pCommaSeparated($node->params).')'
655
+            . (null !== $node->returnType ? ': '.$this->p($node->returnType) : '')
656 656
             . ' => '
657 657
             . $this->p($node->expr);
658 658
     }
659 659
 
660 660
     protected function pExpr_ClosureUse(Expr\ClosureUse $node) {
661
-        return ($node->byRef ? '&' : '') . $this->p($node->var);
661
+        return ($node->byRef ? '&' : '').$this->p($node->var);
662 662
     }
663 663
 
664 664
     protected function pExpr_New(Expr\New_ $node) {
665 665
         if ($node->class instanceof Stmt\Class_) {
666
-            $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : '';
667
-            return 'new ' . $this->pClassCommon($node->class, $args);
666
+            $args = $node->args ? '('.$this->pMaybeMultiline($node->args).')' : '';
667
+            return 'new '.$this->pClassCommon($node->class, $args);
668 668
         }
669
-        return 'new ' . $this->pNewVariable($node->class)
670
-            . '(' . $this->pMaybeMultiline($node->args) . ')';
669
+        return 'new '.$this->pNewVariable($node->class)
670
+            . '('.$this->pMaybeMultiline($node->args).')';
671 671
     }
672 672
 
673 673
     protected function pExpr_Clone(Expr\Clone_ $node) {
674
-        return 'clone ' . $this->p($node->expr);
674
+        return 'clone '.$this->p($node->expr);
675 675
     }
676 676
 
677 677
     protected function pExpr_Ternary(Expr\Ternary $node) {
678 678
         // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator.
679 679
         // this is okay because the part between ? and : never needs parentheses.
680 680
         return $this->pInfixOp(Expr\Ternary::class,
681
-            $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else
681
+            $node->cond, ' ?'.(null !== $node->if ? ' '.$this->p($node->if).' ' : '').': ', $node->else
682 682
         );
683 683
     }
684 684
 
685 685
     protected function pExpr_Exit(Expr\Exit_ $node) {
686 686
         $kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE);
687 687
         return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die')
688
-             . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : '');
688
+             . (null !== $node->expr ? '('.$this->p($node->expr).')' : '');
689 689
     }
690 690
 
691 691
     protected function pExpr_Throw(Expr\Throw_ $node) {
692
-        return 'throw ' . $this->p($node->expr);
692
+        return 'throw '.$this->p($node->expr);
693 693
     }
694 694
 
695 695
     protected function pExpr_Yield(Expr\Yield_ $node) {
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
         } else {
699 699
             // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary
700 700
             return '(yield '
701
-                 . ($node->key !== null ? $this->p($node->key) . ' => ' : '')
701
+                 . ($node->key !== null ? $this->p($node->key).' => ' : '')
702 702
                  . $this->p($node->value)
703 703
                  . ')';
704 704
         }
@@ -708,27 +708,27 @@  discard block
 block discarded – undo
708 708
 
709 709
     protected function pStmt_Namespace(Stmt\Namespace_ $node) {
710 710
         if ($this->canUseSemicolonNamespaces) {
711
-            return 'namespace ' . $this->p($node->name) . ';'
712
-                 . $this->nl . $this->pStmts($node->stmts, false);
711
+            return 'namespace '.$this->p($node->name).';'
712
+                 . $this->nl.$this->pStmts($node->stmts, false);
713 713
         } else {
714
-            return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '')
715
-                 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
714
+            return 'namespace'.(null !== $node->name ? ' '.$this->p($node->name) : '')
715
+                 . ' {'.$this->pStmts($node->stmts).$this->nl.'}';
716 716
         }
717 717
     }
718 718
 
719 719
     protected function pStmt_Use(Stmt\Use_ $node) {
720
-        return 'use ' . $this->pUseType($node->type)
721
-             . $this->pCommaSeparated($node->uses) . ';';
720
+        return 'use '.$this->pUseType($node->type)
721
+             . $this->pCommaSeparated($node->uses).';';
722 722
     }
723 723
 
724 724
     protected function pStmt_GroupUse(Stmt\GroupUse $node) {
725
-        return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix)
726
-             . '\{' . $this->pCommaSeparated($node->uses) . '};';
725
+        return 'use '.$this->pUseType($node->type).$this->pName($node->prefix)
726
+             . '\{'.$this->pCommaSeparated($node->uses).'};';
727 727
     }
728 728
 
729 729
     protected function pStmt_UseUse(Stmt\UseUse $node) {
730
-        return $this->pUseType($node->type) . $this->p($node->name)
731
-             . (null !== $node->alias ? ' as ' . $node->alias : '');
730
+        return $this->pUseType($node->type).$this->p($node->name)
731
+             . (null !== $node->alias ? ' as '.$node->alias : '');
732 732
     }
733 733
 
734 734
     protected function pUseType($type) {
@@ -738,76 +738,76 @@  discard block
 block discarded – undo
738 738
 
739 739
     protected function pStmt_Interface(Stmt\Interface_ $node) {
740 740
         return $this->pAttrGroups($node->attrGroups)
741
-             . 'interface ' . $node->name
742
-             . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '')
743
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
741
+             . 'interface '.$node->name
742
+             . (!empty($node->extends) ? ' extends '.$this->pCommaSeparated($node->extends) : '')
743
+             . $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}';
744 744
     }
745 745
 
746 746
     protected function pStmt_Enum(Stmt\Enum_ $node) {
747 747
         return $this->pAttrGroups($node->attrGroups)
748
-             . 'enum ' . $node->name
748
+             . 'enum '.$node->name
749 749
              . ($node->scalarType ? " : $node->scalarType" : '')
750
-             . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
751
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
750
+             . (!empty($node->implements) ? ' implements '.$this->pCommaSeparated($node->implements) : '')
751
+             . $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}';
752 752
     }
753 753
 
754 754
     protected function pStmt_Class(Stmt\Class_ $node) {
755
-        return $this->pClassCommon($node, ' ' . $node->name);
755
+        return $this->pClassCommon($node, ' '.$node->name);
756 756
     }
757 757
 
758 758
     protected function pStmt_Trait(Stmt\Trait_ $node) {
759 759
         return $this->pAttrGroups($node->attrGroups)
760
-             . 'trait ' . $node->name
761
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
760
+             . 'trait '.$node->name
761
+             . $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}';
762 762
     }
763 763
 
764 764
     protected function pStmt_EnumCase(Stmt\EnumCase $node) {
765 765
         return $this->pAttrGroups($node->attrGroups)
766
-             . 'case ' . $node->name
767
-             . ($node->expr ? ' = ' . $this->p($node->expr) : '')
766
+             . 'case '.$node->name
767
+             . ($node->expr ? ' = '.$this->p($node->expr) : '')
768 768
              . ';';
769 769
     }
770 770
 
771 771
     protected function pStmt_TraitUse(Stmt\TraitUse $node) {
772
-        return 'use ' . $this->pCommaSeparated($node->traits)
772
+        return 'use '.$this->pCommaSeparated($node->traits)
773 773
              . (empty($node->adaptations)
774 774
                 ? ';'
775
-                : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}');
775
+                : ' {'.$this->pStmts($node->adaptations).$this->nl.'}');
776 776
     }
777 777
 
778 778
     protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) {
779
-        return $this->p($node->trait) . '::' . $node->method
780
-             . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
779
+        return $this->p($node->trait).'::'.$node->method
780
+             . ' insteadof '.$this->pCommaSeparated($node->insteadof).';';
781 781
     }
782 782
 
783 783
     protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) {
784
-        return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
785
-             . $node->method . ' as'
786
-             . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
787
-             . (null !== $node->newName     ? ' ' . $node->newName                        : '')
784
+        return (null !== $node->trait ? $this->p($node->trait).'::' : '')
785
+             . $node->method.' as'
786
+             . (null !== $node->newModifier ? ' '.rtrim($this->pModifiers($node->newModifier), ' ') : '')
787
+             . (null !== $node->newName ? ' '.$node->newName : '')
788 788
              . ';';
789 789
     }
790 790
 
791 791
     protected function pStmt_Property(Stmt\Property $node) {
792 792
         return $this->pAttrGroups($node->attrGroups)
793 793
             . (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags))
794
-            . ($node->type ? $this->p($node->type) . ' ' : '')
795
-            . $this->pCommaSeparated($node->props) . ';';
794
+            . ($node->type ? $this->p($node->type).' ' : '')
795
+            . $this->pCommaSeparated($node->props).';';
796 796
     }
797 797
 
798 798
     protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) {
799
-        return '$' . $node->name
800
-             . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
799
+        return '$'.$node->name
800
+             . (null !== $node->default ? ' = '.$this->p($node->default) : '');
801 801
     }
802 802
 
803 803
     protected function pStmt_ClassMethod(Stmt\ClassMethod $node) {
804 804
         return $this->pAttrGroups($node->attrGroups)
805 805
              . $this->pModifiers($node->flags)
806
-             . 'function ' . ($node->byRef ? '&' : '') . $node->name
807
-             . '(' . $this->pMaybeMultiline($node->params) . ')'
808
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
806
+             . 'function '.($node->byRef ? '&' : '').$node->name
807
+             . '('.$this->pMaybeMultiline($node->params).')'
808
+             . (null !== $node->returnType ? ' : '.$this->p($node->returnType) : '')
809 809
              . (null !== $node->stmts
810
-                ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'
810
+                ? $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}'
811 811
                 : ';');
812 812
     }
813 813
 
@@ -815,158 +815,158 @@  discard block
 block discarded – undo
815 815
         return $this->pAttrGroups($node->attrGroups)
816 816
              . $this->pModifiers($node->flags)
817 817
              . 'const '
818
-             . (null !== $node->type ? $this->p($node->type) . ' ' : '')
819
-             . $this->pCommaSeparated($node->consts) . ';';
818
+             . (null !== $node->type ? $this->p($node->type).' ' : '')
819
+             . $this->pCommaSeparated($node->consts).';';
820 820
     }
821 821
 
822 822
     protected function pStmt_Function(Stmt\Function_ $node) {
823 823
         return $this->pAttrGroups($node->attrGroups)
824
-             . 'function ' . ($node->byRef ? '&' : '') . $node->name
825
-             . '(' . $this->pCommaSeparated($node->params) . ')'
826
-             . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '')
827
-             . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
824
+             . 'function '.($node->byRef ? '&' : '').$node->name
825
+             . '('.$this->pCommaSeparated($node->params).')'
826
+             . (null !== $node->returnType ? ' : '.$this->p($node->returnType) : '')
827
+             . $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}';
828 828
     }
829 829
 
830 830
     protected function pStmt_Const(Stmt\Const_ $node) {
831
-        return 'const ' . $this->pCommaSeparated($node->consts) . ';';
831
+        return 'const '.$this->pCommaSeparated($node->consts).';';
832 832
     }
833 833
 
834 834
     protected function pStmt_Declare(Stmt\Declare_ $node) {
835
-        return 'declare (' . $this->pCommaSeparated($node->declares) . ')'
836
-             . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';');
835
+        return 'declare ('.$this->pCommaSeparated($node->declares).')'
836
+             . (null !== $node->stmts ? ' {'.$this->pStmts($node->stmts).$this->nl.'}' : ';');
837 837
     }
838 838
 
839 839
     protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) {
840
-        return $node->key . '=' . $this->p($node->value);
840
+        return $node->key.'='.$this->p($node->value);
841 841
     }
842 842
 
843 843
     // Control flow
844 844
 
845 845
     protected function pStmt_If(Stmt\If_ $node) {
846
-        return 'if (' . $this->p($node->cond) . ') {'
847
-             . $this->pStmts($node->stmts) . $this->nl . '}'
848
-             . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '')
849
-             . (null !== $node->else ? ' ' . $this->p($node->else) : '');
846
+        return 'if ('.$this->p($node->cond).') {'
847
+             . $this->pStmts($node->stmts).$this->nl.'}'
848
+             . ($node->elseifs ? ' '.$this->pImplode($node->elseifs, ' ') : '')
849
+             . (null !== $node->else ? ' '.$this->p($node->else) : '');
850 850
     }
851 851
 
852 852
     protected function pStmt_ElseIf(Stmt\ElseIf_ $node) {
853
-        return 'elseif (' . $this->p($node->cond) . ') {'
854
-             . $this->pStmts($node->stmts) . $this->nl . '}';
853
+        return 'elseif ('.$this->p($node->cond).') {'
854
+             . $this->pStmts($node->stmts).$this->nl.'}';
855 855
     }
856 856
 
857 857
     protected function pStmt_Else(Stmt\Else_ $node) {
858
-        return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}';
858
+        return 'else {'.$this->pStmts($node->stmts).$this->nl.'}';
859 859
     }
860 860
 
861 861
     protected function pStmt_For(Stmt\For_ $node) {
862 862
         return 'for ('
863
-             . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '')
864
-             . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '')
863
+             . $this->pCommaSeparated($node->init).';'.(!empty($node->cond) ? ' ' : '')
864
+             . $this->pCommaSeparated($node->cond).';'.(!empty($node->loop) ? ' ' : '')
865 865
              . $this->pCommaSeparated($node->loop)
866
-             . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
866
+             . ') {'.$this->pStmts($node->stmts).$this->nl.'}';
867 867
     }
868 868
 
869 869
     protected function pStmt_Foreach(Stmt\Foreach_ $node) {
870
-        return 'foreach (' . $this->p($node->expr) . ' as '
871
-             . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '')
872
-             . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {'
873
-             . $this->pStmts($node->stmts) . $this->nl . '}';
870
+        return 'foreach ('.$this->p($node->expr).' as '
871
+             . (null !== $node->keyVar ? $this->p($node->keyVar).' => ' : '')
872
+             . ($node->byRef ? '&' : '').$this->p($node->valueVar).') {'
873
+             . $this->pStmts($node->stmts).$this->nl.'}';
874 874
     }
875 875
 
876 876
     protected function pStmt_While(Stmt\While_ $node) {
877
-        return 'while (' . $this->p($node->cond) . ') {'
878
-             . $this->pStmts($node->stmts) . $this->nl . '}';
877
+        return 'while ('.$this->p($node->cond).') {'
878
+             . $this->pStmts($node->stmts).$this->nl.'}';
879 879
     }
880 880
 
881 881
     protected function pStmt_Do(Stmt\Do_ $node) {
882
-        return 'do {' . $this->pStmts($node->stmts) . $this->nl
883
-             . '} while (' . $this->p($node->cond) . ');';
882
+        return 'do {'.$this->pStmts($node->stmts).$this->nl
883
+             . '} while ('.$this->p($node->cond).');';
884 884
     }
885 885
 
886 886
     protected function pStmt_Switch(Stmt\Switch_ $node) {
887
-        return 'switch (' . $this->p($node->cond) . ') {'
888
-             . $this->pStmts($node->cases) . $this->nl . '}';
887
+        return 'switch ('.$this->p($node->cond).') {'
888
+             . $this->pStmts($node->cases).$this->nl.'}';
889 889
     }
890 890
 
891 891
     protected function pStmt_Case(Stmt\Case_ $node) {
892
-        return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
892
+        return (null !== $node->cond ? 'case '.$this->p($node->cond) : 'default').':'
893 893
              . $this->pStmts($node->stmts);
894 894
     }
895 895
 
896 896
     protected function pStmt_TryCatch(Stmt\TryCatch $node) {
897
-        return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}'
898
-             . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '')
899
-             . ($node->finally !== null ? ' ' . $this->p($node->finally) : '');
897
+        return 'try {'.$this->pStmts($node->stmts).$this->nl.'}'
898
+             . ($node->catches ? ' '.$this->pImplode($node->catches, ' ') : '')
899
+             . ($node->finally !== null ? ' '.$this->p($node->finally) : '');
900 900
     }
901 901
 
902 902
     protected function pStmt_Catch(Stmt\Catch_ $node) {
903
-        return 'catch (' . $this->pImplode($node->types, '|')
904
-             . ($node->var !== null ? ' ' . $this->p($node->var) : '')
905
-             . ') {' . $this->pStmts($node->stmts) . $this->nl . '}';
903
+        return 'catch ('.$this->pImplode($node->types, '|')
904
+             . ($node->var !== null ? ' '.$this->p($node->var) : '')
905
+             . ') {'.$this->pStmts($node->stmts).$this->nl.'}';
906 906
     }
907 907
 
908 908
     protected function pStmt_Finally(Stmt\Finally_ $node) {
909
-        return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}';
909
+        return 'finally {'.$this->pStmts($node->stmts).$this->nl.'}';
910 910
     }
911 911
 
912 912
     protected function pStmt_Break(Stmt\Break_ $node) {
913
-        return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
913
+        return 'break'.($node->num !== null ? ' '.$this->p($node->num) : '').';';
914 914
     }
915 915
 
916 916
     protected function pStmt_Continue(Stmt\Continue_ $node) {
917
-        return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
917
+        return 'continue'.($node->num !== null ? ' '.$this->p($node->num) : '').';';
918 918
     }
919 919
 
920 920
     protected function pStmt_Return(Stmt\Return_ $node) {
921
-        return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
921
+        return 'return'.(null !== $node->expr ? ' '.$this->p($node->expr) : '').';';
922 922
     }
923 923
 
924 924
     protected function pStmt_Throw(Stmt\Throw_ $node) {
925
-        return 'throw ' . $this->p($node->expr) . ';';
925
+        return 'throw '.$this->p($node->expr).';';
926 926
     }
927 927
 
928 928
     protected function pStmt_Label(Stmt\Label $node) {
929
-        return $node->name . ':';
929
+        return $node->name.':';
930 930
     }
931 931
 
932 932
     protected function pStmt_Goto(Stmt\Goto_ $node) {
933
-        return 'goto ' . $node->name . ';';
933
+        return 'goto '.$node->name.';';
934 934
     }
935 935
 
936 936
     // Other
937 937
 
938 938
     protected function pStmt_Expression(Stmt\Expression $node) {
939
-        return $this->p($node->expr) . ';';
939
+        return $this->p($node->expr).';';
940 940
     }
941 941
 
942 942
     protected function pStmt_Echo(Stmt\Echo_ $node) {
943
-        return 'echo ' . $this->pCommaSeparated($node->exprs) . ';';
943
+        return 'echo '.$this->pCommaSeparated($node->exprs).';';
944 944
     }
945 945
 
946 946
     protected function pStmt_Static(Stmt\Static_ $node) {
947
-        return 'static ' . $this->pCommaSeparated($node->vars) . ';';
947
+        return 'static '.$this->pCommaSeparated($node->vars).';';
948 948
     }
949 949
 
950 950
     protected function pStmt_Global(Stmt\Global_ $node) {
951
-        return 'global ' . $this->pCommaSeparated($node->vars) . ';';
951
+        return 'global '.$this->pCommaSeparated($node->vars).';';
952 952
     }
953 953
 
954 954
     protected function pStmt_StaticVar(Stmt\StaticVar $node) {
955 955
         return $this->p($node->var)
956
-             . (null !== $node->default ? ' = ' . $this->p($node->default) : '');
956
+             . (null !== $node->default ? ' = '.$this->p($node->default) : '');
957 957
     }
958 958
 
959 959
     protected function pStmt_Unset(Stmt\Unset_ $node) {
960
-        return 'unset(' . $this->pCommaSeparated($node->vars) . ');';
960
+        return 'unset('.$this->pCommaSeparated($node->vars).');';
961 961
     }
962 962
 
963 963
     protected function pStmt_InlineHTML(Stmt\InlineHTML $node) {
964 964
         $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : '';
965
-        return '?>' . $newline . $node->value . '<?php ';
965
+        return '?>'.$newline.$node->value.'<?php ';
966 966
     }
967 967
 
968 968
     protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) {
969
-        return '__halt_compiler();' . $node->remaining;
969
+        return '__halt_compiler();'.$node->remaining;
970 970
     }
971 971
 
972 972
     protected function pStmt_Nop(Stmt\Nop $node) {
@@ -978,15 +978,15 @@  discard block
 block discarded – undo
978 978
     protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) {
979 979
         return $this->pAttrGroups($node->attrGroups, $node->name === null)
980 980
             . $this->pModifiers($node->flags)
981
-            . 'class' . $afterClassToken
982
-            . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '')
983
-            . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '')
984
-            . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
981
+            . 'class'.$afterClassToken
982
+            . (null !== $node->extends ? ' extends '.$this->p($node->extends) : '')
983
+            . (!empty($node->implements) ? ' implements '.$this->pCommaSeparated($node->implements) : '')
984
+            . $this->nl.'{'.$this->pStmts($node->stmts).$this->nl.'}';
985 985
     }
986 986
 
987 987
     protected function pObjectProperty($node) {
988 988
         if ($node instanceof Expr) {
989
-            return '{' . $this->p($node) . '}';
989
+            return '{'.$this->p($node).'}';
990 990
         } else {
991 991
             return $node;
992 992
         }
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
             if ($element instanceof Scalar\EncapsedStringPart) {
999 999
                 $return .= $this->escapeString($element->value, $quote);
1000 1000
             } else {
1001
-                $return .= '{' . $this->p($element) . '}';
1001
+                $return .= '{'.$this->p($element).'}';
1002 1002
             }
1003 1003
         }
1004 1004
 
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
     }
1007 1007
 
1008 1008
     protected function pSingleQuotedString(string $string) {
1009
-        return '\'' . addcslashes($string, '\'\\') . '\'';
1009
+        return '\''.addcslashes($string, '\'\\').'\'';
1010 1010
     }
1011 1011
 
1012 1012
     protected function escapeString($string, $quote) {
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
             // For doc strings, don't escape newlines
1015 1015
             $escaped = addcslashes($string, "\t\f\v$\\");
1016 1016
         } else {
1017
-            $escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\");
1017
+            $escaped = addcslashes($string, "\n\r\t\f\v$".$quote."\\");
1018 1018
         }
1019 1019
 
1020 1020
         // Escape control characters and non-UTF-8 characters.
@@ -1034,10 +1034,10 @@  discard block
 block discarded – undo
1034 1034
             | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
1035 1035
             | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
1036 1036
         )/x';
1037
-        return preg_replace_callback($regex, function ($matches) {
1037
+        return preg_replace_callback($regex, function($matches) {
1038 1038
             assert(strlen($matches[0]) === 1);
1039
-            $hex = dechex(ord($matches[0]));;
1040
-            return '\\x' . str_pad($hex, 2, '0', \STR_PAD_LEFT);
1039
+            $hex = dechex(ord($matches[0])); ;
1040
+            return '\\x'.str_pad($hex, 2, '0', \STR_PAD_LEFT);
1041 1041
         }, $escaped);
1042 1042
     }
1043 1043
 
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
         $start = $atStart ? '(?:^|[\r\n])' : '[\r\n]';
1046 1046
         $end = $atEnd ? '(?:$|[;\r\n])' : '[;\r\n]';
1047 1047
         return false !== strpos($string, $label)
1048
-            && preg_match('/' . $start . $label . $end . '/', $string);
1048
+            && preg_match('/'.$start.$label.$end.'/', $string);
1049 1049
     }
1050 1050
 
1051 1051
     protected function encapsedContainsEndLabel(array $parts, $label) {
@@ -1064,8 +1064,8 @@  discard block
 block discarded – undo
1064 1064
     protected function pDereferenceLhs(Node $node) {
1065 1065
         if (!$this->dereferenceLhsRequiresParens($node)) {
1066 1066
             return $this->p($node);
1067
-        } else  {
1068
-            return '(' . $this->p($node) . ')';
1067
+        } else {
1068
+            return '('.$this->p($node).')';
1069 1069
         }
1070 1070
     }
1071 1071
 
@@ -1073,15 +1073,15 @@  discard block
 block discarded – undo
1073 1073
         if (!$this->staticDereferenceLhsRequiresParens($node)) {
1074 1074
             return $this->p($node);
1075 1075
         } else {
1076
-            return '(' . $this->p($node) . ')';
1076
+            return '('.$this->p($node).')';
1077 1077
         }
1078 1078
     }
1079 1079
 
1080 1080
     protected function pCallLhs(Node $node) {
1081 1081
         if (!$this->callLhsRequiresParens($node)) {
1082 1082
             return $this->p($node);
1083
-        } else  {
1084
-            return '(' . $this->p($node) . ')';
1083
+        } else {
1084
+            return '('.$this->p($node).')';
1085 1085
         }
1086 1086
     }
1087 1087
 
@@ -1089,7 +1089,7 @@  discard block
 block discarded – undo
1089 1089
         if (!$this->newOperandRequiresParens($node)) {
1090 1090
             return $this->p($node);
1091 1091
         } else {
1092
-            return '(' . $this->p($node) . ')';
1092
+            return '('.$this->p($node).')';
1093 1093
         }
1094 1094
     }
1095 1095
 
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
         if (!$this->hasNodeWithComments($nodes)) {
1111 1111
             return $this->pCommaSeparated($nodes);
1112 1112
         } else {
1113
-            return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl;
1113
+            return $this->pCommaSeparatedMultiline($nodes, $trailingComma).$this->nl;
1114 1114
         }
1115 1115
     }
1116 1116
 
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
         $result = '';
1119 1119
         $sep = $inline ? ' ' : $this->nl;
1120 1120
         foreach ($nodes as $node) {
1121
-            $result .= $this->p($node) . $sep;
1121
+            $result .= $this->p($node).$sep;
1122 1122
         }
1123 1123
 
1124 1124
         return $result;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@
 block discarded – undo
13 13
 use PhpParser\Node\Stmt;
14 14
 use PhpParser\PrettyPrinterAbstract;
15 15
 
16
-class Standard extends PrettyPrinterAbstract
17
-{
16
+class Standard extends PrettyPrinterAbstract {
18 17
     // Special nodes
19 18
 
20 19
     protected function pParam(Node\Param $node) {
Please login to merge, or discard this patch.