From ab589dbff2bf21158da0df36e08434ffc5267003 Mon Sep 17 00:00:00 2001 From: nojimage Date: Tue, 2 Dec 2025 20:22:18 +0900 Subject: [PATCH 1/5] refactor: update parameter types to nullable for better compatibility with PHP 8.4 --- lib/Twitter/Text/Configuration.php | 4 ++-- lib/Twitter/Text/HitHighlighter.php | 10 ++++------ lib/Twitter/Text/Parser.php | 10 +++++----- lib/Twitter/Text/Validator.php | 26 ++++++++++++-------------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/Twitter/Text/Configuration.php b/lib/Twitter/Text/Configuration.php index 15fa87a..20c1b84 100644 --- a/lib/Twitter/Text/Configuration.php +++ b/lib/Twitter/Text/Configuration.php @@ -120,9 +120,9 @@ class Configuration /** * construct * - * @param array $config + * @param array|null $config */ - public function __construct(array $config = null) + public function __construct(?array $config = null) { if ($config === null) { $config = static::$v3Config; diff --git a/lib/Twitter/Text/HitHighlighter.php b/lib/Twitter/Text/HitHighlighter.php index 0a9419f..e676bda 100644 --- a/lib/Twitter/Text/HitHighlighter.php +++ b/lib/Twitter/Text/HitHighlighter.php @@ -106,13 +106,11 @@ public function setTag($v) /** * Hit highlights the tweet. * - * @param string $tweet The tweet to be hit highlighted. - * @param array $hits An array containing the start and end index pairs - * for the highlighting. - * - * @return string The hit highlighted tweet. + * @param string|null $tweet The tweet to be hit highlighted. + * @param array|null $hits An array containing the start and end index pairs for the highlighting. + * @return string The hit highlighted tweet. */ - public function highlight($tweet = null, array $hits = null) + public function highlight($tweet = null, ?array $hits = null) { if ($tweet === null) { $tweet = $this->tweet; diff --git a/lib/Twitter/Text/Parser.php b/lib/Twitter/Text/Parser.php index 43fd851..08de227 100644 --- a/lib/Twitter/Text/Parser.php +++ b/lib/Twitter/Text/Parser.php @@ -27,10 +27,10 @@ class Parser /** * Create a Parser * - * @param Configuration $config - * @return Parser + * @param Configuration|null $config + * @return self */ - public static function create(Configuration $config = null) + public static function create(?Configuration $config = null) { return new self($config); } @@ -38,9 +38,9 @@ public static function create(Configuration $config = null) /** * construct * - * @param Configuration $config + * @param Configuration|null $config */ - public function __construct(Configuration $config = null) + public function __construct(?Configuration $config = null) { if ($config === null) { $config = new Configuration(); diff --git a/lib/Twitter/Text/Validator.php b/lib/Twitter/Text/Validator.php index 50dea27..5e9e6df 100644 --- a/lib/Twitter/Text/Validator.php +++ b/lib/Twitter/Text/Validator.php @@ -40,13 +40,11 @@ class Validator /** * Provides fluent method chaining. * - * @param Configuration $config A Twitter Text Configuration - * + * @param Configuration|null $config A Twitter Text Configuration + * @return self * @see __construct() - * - * @return Validator */ - public static function create(Configuration $config = null) + public static function create(?Configuration $config = null) { return new self($config); } @@ -54,9 +52,9 @@ public static function create(Configuration $config = null) /** * Reads in a tweet to be parsed and validates it. * - * @param Configuration $config A Twitter Text Configuration + * @param Configuration|null $config A Twitter Text Configuration */ - public function __construct(Configuration $config = null) + public function __construct(?Configuration $config = null) { $this->setConfiguration($config); $this->extractor = Extractor::create(); @@ -71,7 +69,7 @@ public function __construct(Configuration $config = null) * @return Validator * @throws \InvalidArgumentException */ - public function setConfiguration(Configuration $config = null) + public function setConfiguration(?Configuration $config = null) { if ($config === null) { // default use v2 config @@ -98,12 +96,12 @@ public function getConfiguration() /** * Check whether a tweet is valid. * - * @param string $tweet The tweet to validate. - * @param Configuration $config using configuration + * @param string $tweet The tweet to validate. + * @param Configuration|null $config using configuration * @return boolean Whether the tweet is valid. * @deprecated instead use \Twitter\Text\Parser::parseText() */ - public function isValidTweetText($tweet, Configuration $config = null) + public function isValidTweetText($tweet, ?Configuration $config = null) { return $this->parseTweet($tweet, $config)->valid; @@ -212,11 +210,11 @@ public function isValidURL($url, $unicode_domains = true, $require_protocol = tr * Determines the length of a tweet. Takes shortening of URLs into account. * * @param string $tweet The tweet to validate. - * @param Configuration $config using configuration + * @param Configuration|null $config using configuration * @return int the length of a tweet. * @deprecated instead use \Twitter\Text\Parser::parseTweet() */ - public function getTweetLength($tweet, Configuration $config = null) + public function getTweetLength($tweet, ?Configuration $config = null) { return $this->parseTweet($tweet, $config)->weightedLength; } @@ -247,7 +245,7 @@ protected static function isValidMatch($string, $pattern, $optional = false) * @param Configuration|null $config using configuration * @return ParseResults */ - private function parseTweet($tweet, Configuration $config = null) + private function parseTweet($tweet, ?Configuration $config = null) { if ($config === null) { $config = $this->config; From 3e09d01a0df5a8c7e7a296f985c52617f6d02eeb Mon Sep 17 00:00:00 2001 From: nojimage Date: Tue, 2 Dec 2025 20:24:31 +0900 Subject: [PATCH 2/5] fix: adjust error reporting and update symfony/yaml and twitter/twitter-text dependencies for compatibility --- composer.json | 4 ++-- tests/bootstrap.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 77df4f5..cc92893 100644 --- a/composer.json +++ b/composer.json @@ -47,9 +47,9 @@ }, "require-dev": { "ext-json": "*", - "symfony/yaml": "^5.0.0", + "symfony/yaml": "^5.0|^6.0|^7.0", "phpunit/phpunit": "^9.5", - "twitter/twitter-text": "^3.0.0" + "twitter/twitter-text": "^3.1.0" }, "autoload": { "psr-0": { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index aebd798..ddb2c4a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,7 @@ Date: Tue, 2 Dec 2025 20:25:18 +0900 Subject: [PATCH 3/5] ci: update CI configuration for PHP 8.4 support and improve caching --- .github/workflows/ci.yml | 53 +++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8dea3a..5072988 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,29 +10,27 @@ on: - '*' schedule: - cron: "0 7 1 * *" - branches: - - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: testsuite: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1', '8.2'] - coverage: ['no'] - test-tld: ['no'] + php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] include: - - php-version: '8.2' - coverage: 'coverage' - test-tld: 'no' - - php-version: '8.2' - coverage: 'no' - test-tld: 'test-tld' + - php-version: '8.4' + coverage: true + - php-version: '8.4' + test-tld: true steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -43,47 +41,46 @@ jobs: - name: Get composer cache directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install dependencies - run: composer install --prefer-dist - - - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '8.1' || matrix.php-version == '8.2' - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + run: composer install --prefer-dist --no-progress - name: Run PHPUnit run: | - if [[ ${{ matrix.coverage }} == 'coverage' ]]; then + if [[ "${{ matrix.coverage }}" == "true" ]]; then vendor/bin/phpunit --exclude-group deprecated,tld --stderr --verbose --coverage-clover=coverage.xml - elif [[ ${{ matrix.test-tld }} == 'test-tld' ]]; then + elif [[ "${{ matrix.test-tld }}" == "true" ]]; then vendor/bin/phpunit --group tld --stderr else vendor/bin/phpunit --exclude-group deprecated,tld --stderr fi - name: Submit code coverage - if: matrix.coverage == 'coverage' - uses: codecov/codecov-action@v1 + if: matrix.coverage + uses: codecov/codecov-action@v5 + with: + files: coverage.xml + fail_ci_if_error: false codestyle: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' - extensions: mbstring, intl, apcu + php-version: '8.4' + extensions: mbstring, intl coverage: none tools: cs2pr, phpcs From 7d093d446e9f219af125714a4526246d505d4be2 Mon Sep 17 00:00:00 2001 From: nojimage Date: Tue, 2 Dec 2025 20:42:40 +0900 Subject: [PATCH 4/5] ci: add PHP 8.5 to test matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5072988..d56d66f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] include: - php-version: '8.4' coverage: true From 73c34a658c4d1b3ae4722840ceccb8c8a095b5b5 Mon Sep 17 00:00:00 2001 From: nojimage Date: Tue, 2 Dec 2025 20:43:06 +0900 Subject: [PATCH 5/5] refactor: update return types in docblocks to use 'self' for better clarity --- lib/Twitter/Text/Autolink.php | 8 ++++---- lib/Twitter/Text/Configuration.php | 8 ++++---- lib/Twitter/Text/Extractor.php | 2 +- lib/Twitter/Text/HitHighlighter.php | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Twitter/Text/Autolink.php b/lib/Twitter/Text/Autolink.php index 467155e..4a7c4b2 100644 --- a/lib/Twitter/Text/Autolink.php +++ b/lib/Twitter/Text/Autolink.php @@ -162,7 +162,7 @@ class Autolink * * @see __construct() * - * @return Autolink + * @return static */ public static function create($tweet = null, $full_encode = false) { @@ -177,9 +177,9 @@ public static function create($tweet = null, $full_encode = false) * * @see htmlspecialchars() * - * @param string $tweet [deprecated] The tweet to be converted. - * @param bool $escape [deprecated] Whether to escape the tweet (default: true). - * @param bool $full_encode [deprecated] Whether to encode all special characters. + * @param string|null $tweet [deprecated] The tweet to be converted. + * @param bool $escape [deprecated] Whether to escape the tweet (default: true). + * @param bool $full_encode [deprecated] Whether to encode all special characters. */ public function __construct($tweet = null, $escape = true, $full_encode = false) { diff --git a/lib/Twitter/Text/Configuration.php b/lib/Twitter/Text/Configuration.php index 20c1b84..6c15bcb 100644 --- a/lib/Twitter/Text/Configuration.php +++ b/lib/Twitter/Text/Configuration.php @@ -156,17 +156,17 @@ public function toArray() * Create configuration from json string * * @param string $json as configuration - * @return Configuration + * @return self */ public static function fromJson($json) { - return new Configuration(json_decode($json, true)); + return new self(json_decode($json, true)); } /** * Get twitter-text 1.x configuration * - * @return Configuration + * @return self */ public static function v1() { @@ -176,7 +176,7 @@ public static function v1() /** * Get twitter-text 2.x configuration * - * @return Configuration + * @return self */ public static function v2() { diff --git a/lib/Twitter/Text/Extractor.php b/lib/Twitter/Text/Extractor.php index ceaae4b..56afc9d 100644 --- a/lib/Twitter/Text/Extractor.php +++ b/lib/Twitter/Text/Extractor.php @@ -61,7 +61,7 @@ class Extractor * * @see __construct() * - * @return Extractor + * @return self */ public static function create() { diff --git a/lib/Twitter/Text/HitHighlighter.php b/lib/Twitter/Text/HitHighlighter.php index e676bda..fe3ad0e 100644 --- a/lib/Twitter/Text/HitHighlighter.php +++ b/lib/Twitter/Text/HitHighlighter.php @@ -49,7 +49,7 @@ class HitHighlighter * * @see __construct() * - * @return HitHighlighter + * @return self */ public static function create($tweet = null, $full_encode = false) { @@ -63,9 +63,9 @@ public static function create($tweet = null, $full_encode = false) * * @see htmlspecialchars() * - * @param string $tweet [deprecated] The tweet to be hit highlighted. - * @param bool $escape [deprecated] Whether to escape the tweet (default: true). - * @param bool $full_encode [deprecated] Whether to encode all special characters. + * @param string|null $tweet [deprecated] The tweet to be hit highlighted. + * @param bool $escape [deprecated] Whether to escape the tweet (default: true). + * @param bool $full_encode [deprecated] Whether to encode all special characters. */ public function __construct($tweet = null, $escape = true, $full_encode = false) {