Skip to content

Commit e7aa9fc

Browse files
committed
ErrorSuppressionFixer - support PHP 7.3
1 parent 26f360b commit e7aa9fc

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ private function isDeprecationErrorCall(Tokens $tokens, $index)
164164
return false;
165165
}
166166

167-
$end = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextTokenOfKind($index, [T_STRING, '(']));
167+
$endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextTokenOfKind($index, [T_STRING, '(']));
168168

169-
return $tokens[$tokens->getPrevMeaningfulToken($end)]->equals([T_STRING, 'E_USER_DEPRECATED']);
169+
$prevIndex = $tokens->getPrevMeaningfulToken($endBraceIndex);
170+
if ($tokens[$prevIndex]->equals(',')) {
171+
$prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
172+
}
173+
174+
return $tokens[$prevIndex]->equals([T_STRING, 'E_USER_DEPRECATED']);
170175
}
171176
}

tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,15 @@ public function provideFixCases()
122122
],
123123
];
124124
}
125+
126+
/**
127+
* @requires PHP 7.3
128+
*/
129+
public function testFix73()
130+
{
131+
$this->doTest(
132+
'<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );',
133+
'<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );'
134+
);
135+
}
125136
}

tests/Fixer/LanguageConstruct/SilencedDeprecationErrorFixerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@ public function provideFixCases()
8181
],
8282
];
8383
}
84+
85+
/**
86+
* @requires PHP 7.3
87+
*/
88+
public function testFix73()
89+
{
90+
$this->doTest(
91+
'<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );',
92+
'<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );'
93+
);
94+
}
8495
}

tests/Fixtures/Integration/misc/PHP7_3.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ PHP 7.3 test.
1111
"multiline_whitespace_before_semicolons": true,
1212
"native_function_invocation": {"include": ["get_class"]},
1313
"php_unit_test_case_static_method_calls": {"call_type": "this"},
14-
"silenced_deprecation_error": true,
1514
"strict_param": true
1615
}
1716
--REQUIREMENTS--
@@ -56,6 +55,7 @@ final class MyTest extends \PHPUnit_Framework_TestCase
5655
random_int($a, $b, ); // `random_api_migration` rule
5756
$foo = (int) $foo; // `set_type_to_cast` rule
5857
in_array($b, $c, true, ); // `strict_param` rule
58+
@trigger_error('Warning.', E_USER_DEPRECATED, ); // `error_suppression` rule
5959
foo(null === $a, ); // `yoda_style` rule
6060

6161
--INPUT--
@@ -96,4 +96,5 @@ final class MyTest extends \PHPUnit_Framework_TestCase
9696
rand($a, $b, ); // `random_api_migration` rule
9797
settype($foo, "integer", ); // `set_type_to_cast` rule
9898
in_array($b, $c, ); // `strict_param` rule
99+
trigger_error('Warning.', E_USER_DEPRECATED, ); // `error_suppression` rule
99100
foo($a === null, ); // `yoda_style` rule

0 commit comments

Comments
 (0)