Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.3] ErrorSuppressionFixer - support PHP 7.3 #4202

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i;m really sad to see this change over and over again :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah :( it's similar to checking for leading \ in functions/classes

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"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