PrecisionAlignment: fix various bugs #1273
Merged
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.
Bug 1 - examine all lines
The PHP open tag may not be the first token in a file - think views starting with inline HTML -.
By starting the loop to examine all lines at the
$stackPtr
, inline HTML lines before the first PHP open tag were not being examined.This fixes that.
Bug 2 - trigger on echo open tag
Files which do not contain a full PHP open tag
<?php
, but do contain short open echo tags<?=
- i.e. views - were not being examined at all.N.B.: this improvement will not work in PHPCS 2.x in combination with PHP 5.3 when the
short_open_tag
ini setting is turned off.I deemed creating a work-around for that specific situation not worth the effort as PHPCS 2.x as well as PHP 5.3 support will be dropped this summer anyway.
Bug 3 - examine inline HTML at end of of file
The new line character is normally tokenized as
T_WHITESPACE
, however, not so when at the end of inline HTML, where it is tokenized as part of theT_INLINE_HTML
token.Bowing out of the sniff when no next token could be found, prevents the last line of inline HTML at the end of a file from being examined.
👉 The PR includes unit tests covered all three bugs.