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

New Utils\Orthography class #59

Merged
merged 2 commits into from Jan 23, 2020
Merged

New Utils\Orthography class #59

merged 2 commits into from Jan 23, 2020

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 23, 2020

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 of isFirstCharLowercase().

  • isFirstCharCapitalized() will return true for capital letters and letters which don't have a concept of capitalization. It will return false for lowercase letters and non-letters.
  • isFirstCharLowercase() will return true for lowercase letters only. It will return false 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.

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 of `isFirstCharLowercase()`.
- `isFirstCharCapitalized()` will return `true` for capital letters and letters which don't have a concept of capitalization. It will return `false` for lowercase letters and non-letters.
- `isFirstCharLowercase()` will return `true` for lowercase letters only. It will return `false` for all other characters, including non-letters.

Includes dedicated unit tests.
…bility 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.
@jrfnl jrfnl added this to the 1.0.0 milestone Jan 23, 2020
@jrfnl jrfnl merged commit e951d54 into develop Jan 23, 2020
@jrfnl jrfnl deleted the feature/new-orthography-class branch January 23, 2020 04:28
@jrfnl jrfnl modified the milestones: 1.0.0, 1.0.0-alpha1 May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant