Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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', '8.5']
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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions lib/Twitter/Text/Autolink.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Autolink
*
* @see __construct()
*
* @return Autolink
* @return static
*/
public static function create($tweet = null, $full_encode = false)
{
Expand All @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions lib/Twitter/Text/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -176,7 +176,7 @@ public static function v1()
/**
* Get twitter-text 2.x configuration
*
* @return Configuration
* @return self
*/
public static function v2()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Twitter/Text/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Extractor
*
* @see __construct()
*
* @return Extractor
* @return self
*/
public static function create()
{
Expand Down
18 changes: 8 additions & 10 deletions lib/Twitter/Text/HitHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HitHighlighter
*
* @see __construct()
*
* @return HitHighlighter
* @return self
*/
public static function create($tweet = null, $full_encode = false)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions lib/Twitter/Text/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ 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);
}

/**
* 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();
Expand Down
26 changes: 12 additions & 14 deletions lib/Twitter/Text/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,21 @@ 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);
}

/**
* 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();
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

# Set up error reporting:
error_reporting(E_ALL | E_STRICT | E_DEPRECATED);
error_reporting(E_ALL | E_DEPRECATED);

# Set default timezone to hide warnings:
date_default_timezone_set('Europe/London');
Expand Down