| 
 | 1 | +<?php  | 
 | 2 | + | 
 | 3 | +/* testDeclareParenthesesOwner */  | 
 | 4 | +declare(strict_types=1/* testDeclareParenthesesCloser */);  | 
 | 5 | + | 
 | 6 | +/* testIfParenthesesOwner */  | 
 | 7 | +if ($a /* testIfParenthesesCloser */) {  | 
 | 8 | +/* testElseIfParenthesesOwner */  | 
 | 9 | +} elseif ($b /* testElseIfParenthesesCloser */) {  | 
 | 10 | +}  | 
 | 11 | + | 
 | 12 | +/* testForParenthesesOwner */  | 
 | 13 | +for ($a = 1; $a < $b; $a++ /* testForParenthesesCloser */) {}  | 
 | 14 | + | 
 | 15 | +/* testForeachParenthesesOwnerPlain */  | 
 | 16 | +foreach ($array as $k => $v /* testForeachParenthesesCloserPlain */) {}  | 
 | 17 | + | 
 | 18 | +/* testForeachParenthesesOwnerWithNestedArray */  | 
 | 19 | +foreach /*comment*/ (  | 
 | 20 | +    /* testArrayParenthesesOwner */  | 
 | 21 | +    array('a', 'b'/* testArrayParenthesesCloser */ ) as $k => $v  | 
 | 22 | +/* testForeachParenthesesCloserWithNestedArray */  | 
 | 23 | +) {}  | 
 | 24 | + | 
 | 25 | +/* testForeachParenthesesOwnerWithNestedList */  | 
 | 26 | +foreach (  | 
 | 27 | +    /* testListParenthesesOwner */  | 
 | 28 | +    $array as list($a, $b/* testListParenthesesCloser */)  | 
 | 29 | +/* testForeachParenthesesCloserWithNestedList */  | 
 | 30 | +) {}  | 
 | 31 | + | 
 | 32 | +/* testSwitchParenthesesOwner */  | 
 | 33 | +switch ($foo/* testSwitchParenthesesCloser */) {  | 
 | 34 | +    case '1';  | 
 | 35 | +        break;  | 
 | 36 | +}  | 
 | 37 | + | 
 | 38 | +/* testWhileParenthesesOwner */  | 
 | 39 | +while( $bar /* testWhileParenthesesCloser */) {}  | 
 | 40 | + | 
 | 41 | +do {  | 
 | 42 | +    something();  | 
 | 43 | +/* testDoWhileParenthesesOwner */  | 
 | 44 | +} while   (true/* testDoWhileParenthesesCloser */);  | 
 | 45 | + | 
 | 46 | +try {  | 
 | 47 | +/* testCatchParenthesesOwner */  | 
 | 48 | +} catch (MyException | OtherException $e /* testCatchParenthesesCloser */) {  | 
 | 49 | +}  | 
 | 50 | + | 
 | 51 | +/* testMatchParenthesesOwner */  | 
 | 52 | +$m = match ($baz/* testMatchParenthesesCloser */) {  | 
 | 53 | +    default => 10,  | 
 | 54 | +};  | 
 | 55 | + | 
 | 56 | +/* testFunctionParenthesesOwner */  | 
 | 57 | +function name($a, $b/* testFunctionParenthesesCloser */) {}  | 
 | 58 | + | 
 | 59 | +/* testFunctionParenthesesOwnerReturnByRef */  | 
 | 60 | +function &returnByRef ($a, $b/* testFunctionParenthesesCloserReturnByRef */) {}  | 
 | 61 | + | 
 | 62 | +class ReservedKeyword {  | 
 | 63 | +    /* testFunctionParenthesesOwnerKeywordName */  | 
 | 64 | +    public function match($a, $b/* testFunctionParenthesesCloserKeywordName */) {}  | 
 | 65 | +}  | 
 | 66 | + | 
 | 67 | +/* testClosureParenthesesOwner */  | 
 | 68 | +$cl = function($a, $b/* testClosureParenthesesCloser */) {};  | 
 | 69 | + | 
 | 70 | +/* testAnonClassParenthesesOwner */  | 
 | 71 | +$anon = new class($a, $b/* testAnonClassParenthesesCloser */) {};  | 
 | 72 | + | 
 | 73 | +/* testAnonClassNoParentheses */  | 
 | 74 | +$anon = new class {  | 
 | 75 | +    const FOO = 1;  | 
 | 76 | +};  | 
 | 77 | + | 
 | 78 | +// This snippet belongs with the testAnonClassNoParentheses case. Making sure these parentheses are not set for the anon class.  | 
 | 79 | +$a = ($b + 10);  | 
 | 80 | + | 
 | 81 | +/* testArbitraryParenthesesOpener */  | 
 | 82 | +$a = ($b + $c/* testArbitraryParenthesesCloser */);  | 
 | 83 | + | 
 | 84 | +/* testFunctionCallParenthesesOpener */  | 
 | 85 | +do_something($b + $c, $d, false /* testFunctionCallParenthesesCloser */);  | 
 | 86 | + | 
 | 87 | +/* testIssetParenthesesOpener */  | 
 | 88 | +$set = isset($b, $c/* testIssetParenthesesCloser */);  | 
 | 89 | + | 
 | 90 | +/* testEmptyParenthesesOpener */  | 
 | 91 | +$empty = empty($b /* testEmptyParenthesesCloser */);  | 
 | 92 | + | 
 | 93 | +/* testUnsetParenthesesOpener */  | 
 | 94 | +unset ($b, $c /* testUnsetParenthesesCloser */);  | 
 | 95 | + | 
 | 96 | +/* testEvalParenthesesOpener */  | 
 | 97 | +$eval = eval("\$str = \"$str\";"/* testEvalParenthesesCloser */);  | 
 | 98 | + | 
 | 99 | +/* testExitParenthesesOpener */  | 
 | 100 | +exit ( 101 /* testExitParenthesesCloser */);  | 
 | 101 | + | 
 | 102 | +/* testDieParenthesesOpener */  | 
 | 103 | +die ('oopsie' /* testDieParenthesesCloser */);  | 
 | 104 | + | 
 | 105 | + | 
 | 106 | +/*  | 
 | 107 | + * All together now, let's make things a little more interesting....  | 
 | 108 | + */  | 
 | 109 | + | 
 | 110 | +/* testNestedOuterIfParenthesesOwner */  | 
 | 111 | +if (  | 
 | 112 | +    /* testNestedFunctionCallAParenthesesOpener */  | 
 | 113 | +    array_map(  | 
 | 114 | +        /* testNestedClosureParenthesesOwner */  | 
 | 115 | +        function ($a, $b /* testNestedClosureParenthesesCloser */) /* testNestedClosureUseParenthesesOpener */  | 
 | 116 | +            use (&$c /* testNestedClosureUseParenthesesCloser */)  | 
 | 117 | +        {  | 
 | 118 | +            /* testNestedForeachParenthesesOwner */  | 
 | 119 | +            foreach (  | 
 | 120 | +                /* testNestedFunctionCallBParenthesesOpener */  | 
 | 121 | +                array_keys(  | 
 | 122 | +                    /* testNestedFunctionCallCParenthesesOpener */  | 
 | 123 | +                    function_call(  | 
 | 124 | +                        /* testNestedArrayAParenthesesOwner */  | 
 | 125 | +                        array(10, 20/* testNestedArrayAParenthesesCloser */)  | 
 | 126 | +                    /* testNestedFunctionCallCParenthesesCloser */  | 
 | 127 | +                    )  | 
 | 128 | +                /* testNestedFunctionCallBParenthesesCloser */  | 
 | 129 | +                )  | 
 | 130 | +                as  | 
 | 131 | +                $v  | 
 | 132 | +            /* testNestedForeachParenthesesCloser */  | 
 | 133 | +            ) {}  | 
 | 134 | +        },  | 
 | 135 | +        /* testNestedArrayBParenthesesOwner */  | 
 | 136 | +        array(  | 
 | 137 | +            /* testNestedListParenthesesOwner */  | 
 | 138 | +            'keyA' => list($a, $b/* testNestedListParenthesesCloser */) = $array,  | 
 | 139 | +            /* testNestedAnonClassParenthesesOwner */  | 
 | 140 | +            'keyB' => new class($foo/* testNestedAnonClassParenthesesCloser */) {},  | 
 | 141 | +        /* testNestedArrayBParenthesesCloser */  | 
 | 142 | +        )  | 
 | 143 | +    /* testNestedFunctionCallAParenthesesCloser */  | 
 | 144 | +    )  | 
 | 145 | +/* testNestedOuterIfParenthesesCloser */  | 
 | 146 | +) {}  | 
0 commit comments