Skip to content

Commit

Permalink
ErrorSuppressionFixer - support PHP 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Jan 1, 2019
1 parent 26f360b commit e7aa9fc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ private function isDeprecationErrorCall(Tokens $tokens, $index)
return false;
}

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

return $tokens[$tokens->getPrevMeaningfulToken($end)]->equals([T_STRING, 'E_USER_DEPRECATED']);
$prevIndex = $tokens->getPrevMeaningfulToken($endBraceIndex);
if ($tokens[$prevIndex]->equals(',')) {
$prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
}

return $tokens[$prevIndex]->equals([T_STRING, 'E_USER_DEPRECATED']);
}
}
11 changes: 11 additions & 0 deletions tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,15 @@ public function provideFixCases()
],
];
}

/**
* @requires PHP 7.3
*/
public function testFix73()
{
$this->doTest(
'<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );',
'<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ public function provideFixCases()
],
];
}

/**
* @requires PHP 7.3
*/
public function testFix73()
{
$this->doTest(
'<?php @trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );',
'<?php trigger_error("This is a deprecation warning.", E_USER_DEPRECATED, );'
);
}
}
3 changes: 2 additions & 1 deletion tests/Fixtures/Integration/misc/PHP7_3.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ PHP 7.3 test.
"multiline_whitespace_before_semicolons": true,
"native_function_invocation": {"include": ["get_class"]},
"php_unit_test_case_static_method_calls": {"call_type": "this"},
"silenced_deprecation_error": true,
"strict_param": true
}
--REQUIREMENTS--
Expand Down Expand Up @@ -56,6 +55,7 @@ final class MyTest extends \PHPUnit_Framework_TestCase
random_int($a, $b, ); // `random_api_migration` rule
$foo = (int) $foo; // `set_type_to_cast` rule
in_array($b, $c, true, ); // `strict_param` rule
@trigger_error('Warning.', E_USER_DEPRECATED, ); // `error_suppression` rule
foo(null === $a, ); // `yoda_style` rule

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

0 comments on commit e7aa9fc

Please sign in to comment.