Skip to content

Commit

Permalink
Bring back support for PHP 5.3
Browse files Browse the repository at this point in the history
As Parallel Lint supports PHP 5.3 again since [PR 51](php-parallel-lint/PHP-Parallel-Lint#51), it would be helpful for the Highlighter repo to also support PHP 5.3.

This restores the PHP 5.3 minimum version to the same as before the version drop in 02b6aa6
  • Loading branch information
jrfnl committed Dec 5, 2021
1 parent 57a0bcb commit 6b151cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
php: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
experimental: [false]

include:
Expand All @@ -34,6 +34,11 @@ jobs:
coverage: none
tools: cs2pr

# Remove PHPCS as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
- name: 'Composer: remove PHPCS'
if: ${{ matrix.php < 5.4 }}
run: composer remove --dev squizlabs/php_codesniffer --no-update

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies - normal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"psr-4": {"JakubOnderka\\PhpConsoleHighlighter\\": "src/"}
},
"require": {
"php": ">=5.4.0",
"php": ">=5.3.0",
"ext-tokenizer": "*",
"php-parallel-lint/php-console-color": "^1.0"
},
Expand Down
7 changes: 6 additions & 1 deletion src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ private function getTokenType($arrayToken)
case T_LINE:
case T_CLASS_C:
case T_FUNC_C:
case T_TRAIT_C:
return self::TOKEN_DEFAULT;

case T_COMMENT:
Expand All @@ -183,6 +182,12 @@ private function getTokenType($arrayToken)
return self::TOKEN_HTML;
}

// Traits didn't exist in PHP 5.3 yet, so the trait magic constant needs special casing for PHP >= 5.4.
// __TRAIT__ will tokenize as T_STRING in PHP 5.3, so, the end result will be the same cross-version.
if (defined('T_TRAIT_C') && $arrayToken[0] === T_TRAIT_C) {
return self::TOKEN_DEFAULT;
}

// Handle PHP >= 8.0 namespaced name tokens.
// https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.tokenizer
if (defined('T_NAME_QUALIFIED') && $arrayToken[0] === T_NAME_QUALIFIED) {
Expand Down

0 comments on commit 6b151cf

Please sign in to comment.