diff --git a/.github/workflows/php-checks.yml b/.github/workflows/php-checks.yml index d3109d3..12e98f3 100644 --- a/.github/workflows/php-checks.yml +++ b/.github/workflows/php-checks.yml @@ -6,11 +6,11 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.2', '8.3', '8.4'] name: PHP ${{ matrix.php-versions }} tests steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -20,10 +20,10 @@ 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@v1 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} diff --git a/.gitignore b/.gitignore index 6b1b412..b9667d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.php-cs-fixer.cache .phpunit.* composer.lock vendor diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..a2c82ce --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +setRules([ + '@PSR12' => true, + '@PHP82Migration' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ); diff --git a/CHANGELOG.md b/CHANGELOG.md index 6972e3c..e835761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 6.0.0 + +### PHP support + +- Dropped support for PHP `8.1` and lower. +- Added support for PHP `8.4`. + ## 5.0.0 ### PHP support diff --git a/README.md b/README.md index 78ab75f..9a62fa3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ object-oriented interface to a variety of hashing methods. ## Requirements -* PHP `8.1`, `8.2` or PHP `8.3` (recommended) +* PHP `8.2`, `8.3` or PHP `8.4` (recommended) ## Installation diff --git a/composer.json b/composer.json index dcd9af9..ef97699 100644 --- a/composer.json +++ b/composer.json @@ -35,11 +35,12 @@ ] }, "require": { - "php": "8.1.* || 8.2.* || 8.3.*" + "php": "8.2 - 8.4" }, "require-dev": { - "phpstan/phpstan": "1.10.46", - "phpunit/phpunit": "10.4.2", - "squizlabs/php_codesniffer": "3.7.2" + "phpstan/phpstan": "2.0.3", + "phpunit/phpunit": "11.5.1", + "squizlabs/php_codesniffer": "3.11.2", + "friendsofphp/php-cs-fixer": "^3.65" } } diff --git a/src/AngryBytes/Hash/HMAC.php b/src/AngryBytes/Hash/HMAC.php index f9f8818..7c118b9 100644 --- a/src/AngryBytes/Hash/HMAC.php +++ b/src/AngryBytes/Hash/HMAC.php @@ -39,6 +39,7 @@ public function hmac(string $sharedSecret, ...$args): string { // Get the data concatenated $data = ''; + /** @var string $arg */ foreach ($args as $arg) { $data .= $arg; } diff --git a/src/AngryBytes/Hash/Hasher/MD5.php b/src/AngryBytes/Hash/Hasher/MD5.php index e77a62b..52cdf6b 100644 --- a/src/AngryBytes/Hash/Hasher/MD5.php +++ b/src/AngryBytes/Hash/Hasher/MD5.php @@ -25,6 +25,7 @@ class MD5 implements HasherInterface public function hash(string $string, array $options = []): string { $salt = $options['salt'] ?? ''; + assert(is_string($salt)); return md5($string . '-' . $salt); } diff --git a/tests/AngryBytes/Hash/Test/BlowfishTest.php b/tests/AngryBytes/Hash/Test/BlowfishTest.php index d233129..883aff8 100644 --- a/tests/AngryBytes/Hash/Test/BlowfishTest.php +++ b/tests/AngryBytes/Hash/Test/BlowfishTest.php @@ -36,11 +36,11 @@ public function testSerialized(): void $hasher = $this->createHasher(); // Complex data - $data = array( - new \stdClass, - array('foo', 'bar'), - 12345 - ); + $data = [ + new \stdClass(), + ['foo', 'bar'], + 12345, + ]; $this->assertEquals( '$2y$15$aa5c57dda7634fc90a92duDv2OoNSn8R.p3.GSoaEZd6/vdiiq9lG', $hasher->hash($data) @@ -80,11 +80,11 @@ public function testObjectVerify(): void $hasher = $this->createHasher(); // Complex data - $data = array( - new \stdClass, - array('foo', 'bar'), - 12345 - ); + $data = [ + new \stdClass(), + ['foo', 'bar'], + 12345, + ]; $this->assertTrue( $hasher->verify($data, '$2y$15$aa5c57dda7634fc90a92duDv2OoNSn8R.p3.GSoaEZd6/vdiiq9lG') @@ -188,7 +188,7 @@ public function testSalt(): void private function createHasher(): Hash { return new Hash( - new BlowfishHasher, + new BlowfishHasher(), '909b96914de6866224f70f52a13e9fa6' ); } diff --git a/tests/AngryBytes/Hash/Test/HashLibTest.php b/tests/AngryBytes/Hash/Test/HashLibTest.php index 4c68a72..7724890 100644 --- a/tests/AngryBytes/Hash/Test/HashLibTest.php +++ b/tests/AngryBytes/Hash/Test/HashLibTest.php @@ -17,11 +17,11 @@ class HashLibTest extends \PHPUnit\Framework\TestCase public function testValidSalt(): void { new Hash( - new \AngryBytes\Hash\Hasher\MD5 + new \AngryBytes\Hash\Hasher\MD5() ); new Hash( - new \AngryBytes\Hash\Hasher\MD5, + new \AngryBytes\Hash\Hasher\MD5(), str_repeat('a', 20) ); } @@ -34,7 +34,7 @@ public function testSaltTooShort(): void $this->expectException(\InvalidArgumentException::class); new Hash( - new \AngryBytes\Hash\Hasher\MD5, + new \AngryBytes\Hash\Hasher\MD5(), str_repeat('a', 19) ); } @@ -47,7 +47,7 @@ public function testSaltTooLong(): void $this->expectException(\InvalidArgumentException::class); new Hash( - new \AngryBytes\Hash\Hasher\MD5, + new \AngryBytes\Hash\Hasher\MD5(), str_repeat('a', CRYPT_SALT_LENGTH + 1) ); } diff --git a/tests/AngryBytes/Hash/Test/MD5Test.php b/tests/AngryBytes/Hash/Test/MD5Test.php index ec8addd..0ebac14 100644 --- a/tests/AngryBytes/Hash/Test/MD5Test.php +++ b/tests/AngryBytes/Hash/Test/MD5Test.php @@ -35,7 +35,7 @@ public function testHashObject(): void { $hasher = $this->createHasher(); - $obj = new \stdClass; + $obj = new \stdClass(); $obj->foo = 'bar'; $this->assertEquals( @@ -74,7 +74,7 @@ public function testVerifyHashObject(): void { $hasher = $this->createHasher(); - $obj = new \stdClass; + $obj = new \stdClass(); $obj->foo = 'bar'; $this->assertTrue( @@ -94,7 +94,7 @@ public function testVerifyHashObject(): void private function createHasher(): Hash { return new Hash( - new MD5Hasher, + new MD5Hasher(), '909b96914de6866224f70f52a13e9fa6' ); } diff --git a/tests/AngryBytes/Hash/Test/PasswordTest.php b/tests/AngryBytes/Hash/Test/PasswordTest.php index 6601733..ff0ae1e 100644 --- a/tests/AngryBytes/Hash/Test/PasswordTest.php +++ b/tests/AngryBytes/Hash/Test/PasswordTest.php @@ -98,7 +98,7 @@ public function testCostTooHigh(): void private function createHasher(): Hash { return new Hash( - new PasswordHasher + new PasswordHasher() ); } }