From 14c29880a99564b5369ebb33cf0a8239e0b23e5f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 5 Dec 2021 03:03:23 +0100 Subject: [PATCH] Bring back support for PHP 5.3 As Parallel Lint supports PHP 5.3 again since [PR 51](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/51), it would be helpful for the Highlighter repo to also support PHP 5.3. This restores the PHP 5.3 minimum version along the same lines as before the version drop in 02b6aa6ea32b14fc15285b17babc3f10857bfb96 The PHP 5.3.2 minimum is in-line with the PHP Console Color minimum version for PHP 5.3. Includes: * Enabling a build against PHP 5.3 in the GH Actions workflow. * Adjusting the `testVersion` for the PHPCompatibility checks to `5.3-` (5.3 and higher). --- .github/workflows/test.yml | 7 ++++++- composer.json | 4 ++-- phpcs.xml.dist | 2 +- src/Highlighter.php | 7 ++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7be78b0..e0d3c40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] experimental: [false] include: @@ -40,6 +40,11 @@ jobs: coverage: none tools: cs2pr + # Remove the PHPCS standard 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 php-parallel-lint/php-code-style --no-update --no-interaction + # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - normal diff --git a/composer.json b/composer.json index dbd1fb2..269855d 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "psr-4": {"PHP_Parallel_Lint\\PhpConsoleHighlighter\\Test\\": "tests/"} }, "require": { - "php": ">=5.4.0", + "php": ">=5.3.2", "ext-tokenizer": "*", - "php-parallel-lint/php-console-color": "^1.0" + "php-parallel-lint/php-console-color": "^1.0.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4decb09..00d266e 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -36,7 +36,7 @@ --> - + diff --git a/src/Highlighter.php b/src/Highlighter.php index 4ca7750..f284bbb 100644 --- a/src/Highlighter.php +++ b/src/Highlighter.php @@ -46,7 +46,6 @@ class Highlighter T_FUNC_C => T_FUNC_C, T_METHOD_C => T_METHOD_C, T_NS_C => T_NS_C, - T_TRAIT_C => T_TRAIT_C, ); /** @var array */ @@ -214,6 +213,12 @@ private function getTokenType($arrayToken) // phpcs:disable PHPCompatibility.Constants.NewConstants -- The new token constants are only used when defined. + // 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 (