Skip to content

Commit 6b151cf

Browse files
committed
Bring back support for PHP 5.3
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
1 parent 57a0bcb commit 6b151cf

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.github/workflows/test.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
15+
php: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
1616
experimental: [false]
1717

1818
include:
@@ -34,6 +34,11 @@ jobs:
3434
coverage: none
3535
tools: cs2pr
3636

37+
# Remove PHPCS as it has a minimum PHP requirements of PHP 5.4 and would block install on PHP 5.3.
38+
- name: 'Composer: remove PHPCS'
39+
if: ${{ matrix.php < 5.4 }}
40+
run: composer remove --dev squizlabs/php_codesniffer --no-update
41+
3742
# Install dependencies and handle caching in one go.
3843
# @link https://github.com/marketplace/actions/install-composer-dependencies
3944
- name: Install Composer dependencies - normal

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"psr-4": {"JakubOnderka\\PhpConsoleHighlighter\\": "src/"}
1515
},
1616
"require": {
17-
"php": ">=5.4.0",
17+
"php": ">=5.3.0",
1818
"ext-tokenizer": "*",
1919
"php-parallel-lint/php-console-color": "^1.0"
2020
},

src/Highlighter.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ private function getTokenType($arrayToken)
168168
case T_LINE:
169169
case T_CLASS_C:
170170
case T_FUNC_C:
171-
case T_TRAIT_C:
172171
return self::TOKEN_DEFAULT;
173172

174173
case T_COMMENT:
@@ -183,6 +182,12 @@ private function getTokenType($arrayToken)
183182
return self::TOKEN_HTML;
184183
}
185184

185+
// Traits didn't exist in PHP 5.3 yet, so the trait magic constant needs special casing for PHP >= 5.4.
186+
// __TRAIT__ will tokenize as T_STRING in PHP 5.3, so, the end result will be the same cross-version.
187+
if (defined('T_TRAIT_C') && $arrayToken[0] === T_TRAIT_C) {
188+
return self::TOKEN_DEFAULT;
189+
}
190+
186191
// Handle PHP >= 8.0 namespaced name tokens.
187192
// https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.tokenizer
188193
if (defined('T_NAME_QUALIFIED') && $arrayToken[0] === T_NAME_QUALIFIED) {

0 commit comments

Comments
 (0)