From b8dfc6ab2dd4f7f28a6452fffa53dc9ca00b48e1 Mon Sep 17 00:00:00 2001 From: Jakub Skrzeczek Date: Fri, 14 Apr 2023 11:41:18 +0200 Subject: [PATCH 1/2] Remove support for old PHP versions and update composer dependecies - Versions of PHP with currently active support per https://www.php.net/supported-versions.php are only 8.1 and 8.2 - Update matrix with PHP versions for CI workflow - Dropping support for PHP 5.x means that paragonie/random_compat dependency can be removed - Minimum required versions of composer dependencies were bumped up to current versions --- .github/workflows/php.yml | 2 +- composer.json | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9b7269d..6312c47 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-latest', 'macos-latest'] - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['8.1', '8.2'] phpunit-versions: ['latest'] steps: diff --git a/composer.json b/composer.json index f4f0eb1..8a4a96c 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,11 @@ } ], "require": { - "php": "~5.6|~7.0|~8.0", - "paragonie/random_compat": ">=2.0" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit" : ">=5.6", - "squizlabs/php_codesniffer": "^2.3" + "phpunit/phpunit" : ">=10.0", + "squizlabs/php_codesniffer": "^3.7" }, "archive": { "exclude": [ From 07b4ff20d57d2c742c14f54a54746e7d8e349699 Mon Sep 17 00:00:00 2001 From: Jakub Skrzeczek Date: Sat, 15 Apr 2023 19:42:50 +0200 Subject: [PATCH 2/2] Use native PHP data types --- src/Client.php | 34 ++++++++++---------------------- src/Core.php | 9 ++++++--- src/CoreInterface.php | 12 +++++------ src/Generator.php | 4 ++-- src/GeneratorInterface.php | 7 ++----- tests/ClientTest.php | 15 +++++--------- tests/CoreTest.php | 10 +++------- tests/GeneratorTest.php | 9 +++------ tests/Support/DummyGenerator.php | 4 ++-- 9 files changed, 39 insertions(+), 65 deletions(-) diff --git a/src/Client.php b/src/Client.php index cb6aea2..261e070 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,4 +1,4 @@ -size = $size > 0 ? $size : 21; $this->generator = $generator ?: new Generator(); @@ -47,11 +45,9 @@ public function __construct($size = 21, GeneratorInterface $generator = null) /** * Generate nanoid via optional modes * - * @param integer $size * @param integer $mode Client::MODE_NORMAL|Client::MODE_DYNAMIC - * @return string */ - public function generateId($size = 0, $mode = self::MODE_NORMAL) + public function generateId(int $size = 0, int $mode = self::MODE_NORMAL): string { $size = $size > 0 ? $size : $this->size; switch ($mode) { @@ -67,12 +63,9 @@ public function generateId($size = 0, $mode = self::MODE_NORMAL) * you have been implements your custom GeneratorInterface as correctly. * Otherwise use the build-in default random bytes generator * - * @param GeneratorInterface $generator - * @param integer $size * @param string $alphabet default CoreInterface::SAFE_SYMBOLS - * @return string */ - public function formattedId($alphabet, $size = 0, GeneratorInterface $generator = null) + public function formattedId(string $alphabet, int $size = 0, GeneratorInterface $generator = null): string { $alphabet = $alphabet ?: CoreInterface::SAFE_SYMBOLS; $size = $size > 0 ? $size : $this->size; @@ -84,14 +77,9 @@ public function formattedId($alphabet, $size = 0, GeneratorInterface $generator /** * Backwards-compatible method name. * - * @param string $alphabet - * @param integer $size - * @param GeneratorInterface $generator - * - * @return string * @since 1.0.0 */ - public function formatedId($alphabet, $size = 0, GeneratorInterface $generator = null) + public function formatedId(string $alphabet, int $size = 0, GeneratorInterface $generator = null): string { $size = $size > 0 ? $size : $this->size; @@ -104,10 +92,8 @@ public function formatedId($alphabet, $size = 0, GeneratorInterface $generator = * as UUID v4. * * @see https://github.com/ai/nanoid/blob/master/non-secure/index.js#L19 - * @param integer $size - * @return string */ - private function normalRandom($size) + private function normalRandom(int $size): string { $id = ''; while (1 <= $size--) { diff --git a/src/Core.php b/src/Core.php index c0a4891..52f094d 100644 --- a/src/Core.php +++ b/src/Core.php @@ -1,4 +1,4 @@ -generateId($size); @@ -29,9 +28,8 @@ public function testGenerateId(Client $client) /** * @group passed * @dataProvider clientProvider - * @param Client $client */ - public function testFormattedId(Client $client) + public function testFormattedId(Client $client): void { $size = 10; $alphabet = '0123456789abcdefghi'; @@ -47,9 +45,8 @@ public function testFormattedId(Client $client) /** * @group passed * @dataProvider clientProvider - * @param Client $client */ - public function testFormatedId(Client $client) + public function testFormatedId(Client $client): void { $size = 10; $alphabet = '0123456789abcdefghi'; @@ -64,10 +61,8 @@ public function testFormatedId(Client $client) /** * Client Provider - * - * @return mixed */ - public function clientProvider() + public static function clientProvider(): array { return [ [new Client()] diff --git a/tests/CoreTest.php b/tests/CoreTest.php index 8bba9d6..bc85134 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -1,4 +1,4 @@ -random($size); @@ -22,10 +21,8 @@ public function testRandom(GeneratorInterface $generator) /** * Generator Provider - * - * @return mixed */ - public function generatorProvider() + public static function generatorProvider(): array { return [ [new Generator()] diff --git a/tests/Support/DummyGenerator.php b/tests/Support/DummyGenerator.php index 512a1d2..c33f57f 100644 --- a/tests/Support/DummyGenerator.php +++ b/tests/Support/DummyGenerator.php @@ -1,4 +1,4 @@ -