From f4050781b09cc458fc5024bf8ee10086f2e8bae4 Mon Sep 17 00:00:00 2001 From: ellisgl Date: Wed, 25 Nov 2026 09:20:47 -0600 Subject: [PATCH] Replace Travis CI with GitHub Actions - Run the Codeception unit suite on PHP 8.1-8.5 - Run PHPStan (level 10) and PHP_CodeSniffer (PSR-12) on PHP 8.5 - Remove .travis.yml; Travis no longer runs free builds for open source - Add composer test, phpstan and phpcs scripts - Fix what PHPStan and PHPCS reported: array value types, a mixed type for Is::empty(), two always-true checks in Is::empty() (same results for every input), and two PSR-12 issues - Replace the dead Travis badge with CI, Packagist, PHP and PHPStan badges Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 48 +++++++++++++ .travis.yml | 10 --- README.md | 5 +- composer.json | 15 ++-- composer.lock | 145 ++++++++++++++++++++++++++++++++++++++- phpstan.neon | 4 ++ src/ToolBox/Arrays.php | 19 +++-- src/ToolBox/Is.php | 9 +-- 8 files changed, 225 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..09b6254 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + tests: + name: Tests (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['8.1', '8.2', '8.3', '8.4', '8.5'] + steps: + - uses: actions/checkout@v4 + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - uses: ramsey/composer-install@v3 + with: + dependency-versions: highest + + - run: vendor/bin/codecept run unit + + quality: + name: PHPStan & PSR-12 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.5' + coverage: none + + - uses: ramsey/composer-install@v3 + + - run: composer phpstan + - run: composer phpcs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f22d6e3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -sudo: false -before_script: -- composer self -- composer --version -- composer install -n -language: php -php: - - '7.2' -script: - - php vendor/bin/codecept run unit diff --git a/README.md b/README.md index ed398bd..f6f6980 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # GeekLab-ToolBox -[![Build Status](https://travis-ci.com/ellisgl/GeekLab-ToolBox.svg?branch=release)](https://travis-ci.com/ellisgl/GeekLab-ToolBox) +[![CI](https://github.com/ellisgl/GeekLab-ToolBox/actions/workflows/ci.yml/badge.svg)](https://github.com/ellisgl/GeekLab-ToolBox/actions/workflows/ci.yml) +[![Packagist Version](https://img.shields.io/packagist/v/geeklab/toolbox)](https://packagist.org/packages/geeklab/toolbox) +[![PHP Version](https://img.shields.io/packagist/dependency-v/geeklab/toolbox/php)](https://packagist.org/packages/geeklab/toolbox) +[![PHPStan](https://img.shields.io/badge/PHPStan-level%2010-brightgreen)](https://phpstan.org/) Just some "utility" classes for PHP. diff --git a/composer.json b/composer.json index b02ba4c..5a2b463 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,18 @@ "codeception/codeception": "^5.0", "spatie/phpunit-snapshot-assertions": "^4.2", "digitickets/phpunit-errorhandler": "^4.1", - "codeception/module-asserts": "^3.0" + "codeception/module-asserts": "^3.0", + "phpstan/phpstan": "^2", + "squizlabs/php_codesniffer": "^3" }, - "autoload" : { - "psr-4" : { - "GeekLab\\" : "src" + "autoload": { + "psr-4": { + "GeekLab\\": "src" } + }, + "scripts": { + "test": "codecept run unit", + "phpstan": "phpstan analyse --no-progress", + "phpcs": "phpcs src --standard=PSR12 -n" } } diff --git a/composer.lock b/composer.lock index 9d1c8fe..768989d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "da2e265ec15d5af753e98b13b0b439d7", + "content-hash": "7c68db14f96ab8f9eee4415ae884868b", "packages": [], "packages-dev": [ { @@ -677,6 +677,70 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.3.7", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/90c91c2498849ab8cc4e873864bbf1cb2bf6ea12", + "reference": "90c91c2498849ab8cc4e873864bbf1cb2bf6ea12", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ondřej Mirtes" + }, + { + "name": "Markus Staab" + }, + { + "name": "Vincent Langlet" + } + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2026-11-19T10:31:11+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.32", @@ -2369,6 +2433,85 @@ ], "time": "2022-10-10T15:58:50+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.13.6", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "4c378e1a528ea066890fc2397cbdd2f94eb2fc91" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/4c378e1a528ea066890fc2397cbdd2f94eb2fc91", + "reference": "4c378e1a528ea066890fc2397cbdd2f94eb2fc91", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2026-08-06T00:17:32+00:00" + }, { "name": "symfony/console", "version": "v6.4.32", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..9228327 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 10 + paths: + - src diff --git a/src/ToolBox/Arrays.php b/src/ToolBox/Arrays.php index 590e36c..79339bf 100644 --- a/src/ToolBox/Arrays.php +++ b/src/ToolBox/Arrays.php @@ -7,13 +7,12 @@ class Arrays /** * Recursive array_walk, since array_walk_recursive only deal with the outer leafs / nodes. * - * @param array $array - * @param callable $callback + * @param array $array + * @param callable $callback */ public static function explore(array &$array, callable $callback): void { - array_walk($array, static function (&$value, $key) use (&$array, $callback) - { + array_walk($array, static function (&$value, $key) use (&$array, $callback) { if (is_array($value)) { self::explore($value, $callback); } @@ -27,12 +26,12 @@ public static function explore(array &$array, callable $callback): void */ /** - * @param array $array + * @param array $array * @param int | string $oldKey * @param int | string $newKey * @param bool $recursive * - * @return array + * @return array */ public static function renameKey( array $array, @@ -60,7 +59,7 @@ public static function renameKey( /** * Return the first key in an array. * - * @param array $array + * @param array $array * * @return int | string | null */ @@ -74,7 +73,7 @@ public static function firstKey(array $array): int | string | null /** * Return the last key in an array. * - * @param array $array + * @param array $array * * @return int | null | string */ @@ -87,7 +86,7 @@ public static function lastKey(array $array): int | string | null /** * Return the first value in an array * - * @param array $array + * @param array $array * * @return mixed */ @@ -99,7 +98,7 @@ public static function firstValue(array $array): mixed /** * Return the last value in an array * - * @param array $array + * @param array $array * * @return mixed */ diff --git a/src/ToolBox/Is.php b/src/ToolBox/Is.php index b427c14..11b929c 100644 --- a/src/ToolBox/Is.php +++ b/src/ToolBox/Is.php @@ -8,12 +8,13 @@ class Is * Is something empty, 0 and '0' values count as not empty. * http://php.net/manual/en/function.empty.php#78269 * - * @param $something - * @param bool $nullValid Should NULL be considered as not empty? + * @param mixed $something + * @param bool $nullValid Should NULL be considered as not empty? * @return bool */ - public static function empty($something, bool $nullValid = false): bool + public static function empty(mixed $something, bool $nullValid = false): bool { - return (('' === $something || (NULL === $something && !$nullValid)) && 0 !== $something && '0' !== $something); + // Only '' and NULL (unless $nullValid) are empty, so 0 and '0' are never empty. + return '' === $something || (null === $something && !$nullValid); } }