Tokenizer/PHP: add tests for tokenization of yield and yield from + minor bug fix #645
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Tokenizer/PHP: add tests for tokenization of yield and yield from
.. to document and safeguard the existing behaviour.
Includes skipping one particular assertion on PHP 5.4.
This assertion would fail on PHP 5.4 with PHPUnit 4 as PHPUnit polyfills the
T_YIELD
token too, but with a different value, which causes the token 'type' to be set toUNKNOWN
.This issue only occurs when running the tests, not when running PHPCS outside of a test situation, so this is not a real problem when running PHPCS on PHP 5.4.
For reference: the PHPUnit polyfilled token is declared in the PHP_CodeCoverage_Report_HTML_Renderer_File class in vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/HTML/Renderer/File.php
Tokenizer/PHP: simplify the "yield"/"yield from" polyfill code
By moving the check a
T_STRING
"yield" keyword up and always adjusting the token in the original token stream, we can remove a lot of duplicate code.Tokenizer/PHP: bug fix - "yield" vs function return by ref (PHP 5.4)
On PHP 5.4, where PHP doesn't natively have the
T_YIELD
token yet, ayield
function name for a function declared to return by reference would be tokenized asT_YIELD
, instead ofT_STRING
due to theT_YIELD
polyfill happening after the context sensitive keyword check has already run.By moving the check for a
T_STRING
"yield" keyword up to above the check for context sensitive keywords, this bug is fixed.Includes additional test.
Suggested changelog entry
Fixed bug: on PHP 5.4, if
yield
was used as the declaration name for a function declared to return by reference, the function name would incorrectly be tokenized asT_YIELD
instead ofT_STRING
.