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.
New Utils\Orthography class
This class adds three new utility methods for dealing with the contents of arbitrary text strings:
isFirstCharCapitalized()
- to check whether the first character of an arbitrary text string is a capital letter. Returns boolean.isFirstCharLowercase()
- to check whether the first character of an arbitrary text string is a lowercase letter. Returns boolean.isLastCharPunctuation()
- to check whether the last character of an arbitrary text string is a punctuation character. By default, the full stop, question mark and exclamation mark are accepted as valid punctuation, but this can easily be changed by passing the$allowedChars
parameter. Returns boolean.Ref: https://www.thepunctuationguide.com/terminal-points.html
It also adds a
TERMINAL_POINTS
class constant containing the default allowed punctuation characters.That way, sniffs have access to that information to display it in error messages, if so desired.
Important note: The return of
isFirstCharCapitalized()
is not the direct opposite of the output ofisFirstCharLowercase()
.isFirstCharCapitalized()
will returntrue
for capital letters and letters which don't have a concept of capitalization. It will returnfalse
for lowercase letters and non-letters.isFirstCharLowercase()
will returntrue
for lowercase letters only. It will returnfalse
for all other characters, including non-letters.Includes dedicated unit tests.
Orthography::isLastCharPunctuation(): PHP/PHPCS cross-version compatibility fix
The default charset for the PHP iconv extension changed in PHP 5.6 from ISO-8859-1 to UTF-8.
The default charset used by PHPCS changed with PHPCS 3.0.0 from ISO-8859-1 to UTF-8.
For consistent results, retrieve the charset as used by PHPCS and pass it to the iconv functions.