Skip to content

Commit 0d2d8f9

Browse files
committed
FPPP: Support catch without variable
1 parent 244db65 commit 0d2d8f9

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/PhpParser/PrettyPrinterAbstract.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ protected function initializeRemovalMap() {
12201220
'Param->type' => $stripRight,
12211221
'Param->default' => $stripEquals,
12221222
'Stmt_Break->num' => $stripBoth,
1223+
'Stmt_Catch->var' => $stripLeft,
12231224
'Stmt_ClassMethod->returnType' => $stripColon,
12241225
'Stmt_Class->extends' => ['left' => \T_EXTENDS],
12251226
'Expr_PrintableNewAnonClass->extends' => ['left' => \T_EXTENDS],
@@ -1257,6 +1258,7 @@ protected function initializeInsertionMap() {
12571258
'Param->type' => [null, false, null, ' '],
12581259
'Param->default' => [null, false, ' = ', null],
12591260
'Stmt_Break->num' => [\T_BREAK, false, ' ', null],
1261+
'Stmt_Catch->var' => [null, false, ' ', null],
12601262
'Stmt_ClassMethod->returnType' => [')', false, ' : ', null],
12611263
'Stmt_Class->extends' => [null, false, ' extends ', null],
12621264
'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null],

test/code/formatPreservation/insertionOfNullable.test

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,22 @@ $stmts[0]->name = new Node\Name('Foo');
173173
<?php
174174

175175
namespace Foo
176-
{ echo 42; }
176+
{ echo 42; }
177+
-----
178+
<?php
179+
try
180+
{
181+
}
182+
catch (Exception)
183+
{
184+
}
185+
-----
186+
$stmts[0]->catches[0]->var = new Expr\Variable('e');
187+
-----
188+
<?php
189+
try
190+
{
191+
}
192+
catch (Exception $e)
193+
{
194+
}

test/code/formatPreservation/removalViaNull.test

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,22 @@ $stmts[0]->name = null;
191191

192192
namespace
193193
{
194-
}
194+
}
195+
-----
196+
<?php
197+
try
198+
{
199+
}
200+
catch (Exception $e)
201+
{
202+
}
203+
-----
204+
$stmts[0]->catches[0]->var = null;
205+
-----
206+
<?php
207+
try
208+
{
209+
}
210+
catch (Exception)
211+
{
212+
}

0 commit comments

Comments
 (0)