diff --git a/.gitattributes b/.gitattributes index ece1094..00551f8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,4 +15,3 @@ /makefile export-ignore /phpunit.xml.dist export-ignore /README.md export-ignore -/ruleset.xml.dist export-ignore diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 3e25cd3..c00918e 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -8,12 +8,21 @@ return $config ->setRules([ + '@PHP70Migration' => true, + '@PHP71Migration' => true, + '@PHP73Migration' => true, + '@PHP74Migration' => true, + '@PHP80Migration' => true, + '@PHP81Migration' => true, + '@PHP82Migration' => true, + '@PHP83Migration' => true, '@Symfony' => true, 'concat_space' => ['spacing' => 'one'], 'single_line_throw' => false, 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], - '@PSR12' => true, - 'class_definition' => false, // @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5463 + 'phpdoc_align' => ['align' => 'left'], + 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'match', 'parameters']], + '@PER-CS' => true, ]) ->setFinder($finder) ->setUsingCache(false); diff --git a/composer.json b/composer.json index 28669c7..17f5267 100644 --- a/composer.json +++ b/composer.json @@ -34,9 +34,8 @@ }, "require-dev": { "ext-pcntl": "*", - "friendsofphp/php-cs-fixer": ">=2.0", - "phpunit/phpunit": ">=10.0", - "squizlabs/php_codesniffer": ">=3.0" + "friendsofphp/php-cs-fixer": ">=3.0", + "phpunit/phpunit": ">=10.0" }, "suggest": { "ext-apcu": ">=4.0.0", diff --git a/docker/php.sh b/docker/php.sh index 2c2fc94..96c3762 100755 --- a/docker/php.sh +++ b/docker/php.sh @@ -11,6 +11,7 @@ cd /tmp/cmake-3.29.3 ./configure make make install +cd /var/www # back to work dir pecl install -f couchbase pecl install -f xdebug diff --git a/makefile b/makefile index 9374fa4..05ec2ff 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ SHELL := /bin/bash PHP ?= ADAPTER ?= Apc,Couchbase,Flysystem,Memcached,MemoryStore,MySQL,PostgreSQL,Redis,SQLite GROUP ?= #adapter,buffered,collections,keyvaluestore,psr6,psr16,shard,transactional,stampede -VOLUME_BINDS ?= src,tests,build,.php-cs-fixer.php,phpunit.xml,ruleset.xml +VOLUME_BINDS ?= src,tests,build,.php-cs-fixer.php,phpunit.xml install: wget -q -O - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer @@ -51,6 +51,6 @@ test: format: VOLUMES="" for VOLUME in $$(echo "$(VOLUME_BINDS)" | tr "," "\n"); do VOLUMES="$$VOLUMES -v $$(pwd)/$$VOLUME:/var/www/$$VOLUME"; done;\ - docker-compose run --no-deps $$VOLUMES php sh -c "vendor/bin/php-cs-fixer fix && vendor/bin/phpcbf --standard=ruleset.xml" + docker-compose run --no-deps $$VOLUMES php sh -c "vendor/bin/php-cs-fixer fix" .PHONY: docs diff --git a/src/Adapters/Collections/SQL.php b/src/Adapters/Collections/SQL.php index f21598e..fe24727 100644 --- a/src/Adapters/Collections/SQL.php +++ b/src/Adapters/Collections/SQL.php @@ -32,7 +32,7 @@ public function flush(): bool // deleting key with a prefixed LIKE should be fast, they're indexed $statement = $this->client->prepare( "DELETE FROM $this->table - WHERE k LIKE :key" + WHERE k LIKE :key", ); return $statement->execute([ diff --git a/src/Adapters/Couchbase.php b/src/Adapters/Couchbase.php index c81caf7..a935f9b 100644 --- a/src/Adapters/Couchbase.php +++ b/src/Adapters/Couchbase.php @@ -39,7 +39,7 @@ public function __construct( \Couchbase\Collection $client, \Couchbase\BucketManager|\Couchbase\Management\BucketManager $bucketManager, \Couchbase\Bucket $bucket, - ?int $timeout = null + ?int $timeout = null, ) { $this->collection = $client; $this->bucketManager = $bucketManager; diff --git a/src/Adapters/MemoryStore.php b/src/Adapters/MemoryStore.php index 24e349d..f7d9b2f 100644 --- a/src/Adapters/MemoryStore.php +++ b/src/Adapters/MemoryStore.php @@ -322,7 +322,7 @@ protected function shorthandToBytes(string|int $shorthand): int static function ($match) use ($units): int { return $match[1] * $units[$match[2]]; }, - $shorthand + $shorthand, ); } } diff --git a/src/Adapters/MySQL.php b/src/Adapters/MySQL.php index 65106bd..b16c2ff 100644 --- a/src/Adapters/MySQL.php +++ b/src/Adapters/MySQL.php @@ -23,7 +23,7 @@ public function set(string $key, mixed $value, int $expire = 0): bool $statement = $this->client->prepare( "REPLACE INTO $this->table (k, v, e) - VALUES (:key, :value, :expire)" + VALUES (:key, :value, :expire)", ); $statement->execute([ @@ -64,7 +64,7 @@ public function setMulti(array $items, int $expire = 0): array $statement = $this->client->prepare( "REPLACE INTO $this->table (k, v, e) - VALUES " . implode(',', $query) + VALUES " . implode(',', $query), ); $statement->execute($params); @@ -92,7 +92,7 @@ public function add(string $key, mixed $value, int $expire = 0): bool // MySQL-specific way to ignore insert-on-duplicate errors $statement = $this->client->prepare( "INSERT IGNORE INTO $this->table (k, v, e) - VALUES (:key, :value, :expire)" + VALUES (:key, :value, :expire)", ); $statement->execute([ @@ -117,7 +117,7 @@ protected function init(): void v LONGBLOB, e TIMESTAMP NULL DEFAULT NULL, KEY e (e) - )" + )", ); } } diff --git a/src/Adapters/PostgreSQL.php b/src/Adapters/PostgreSQL.php index 70d4705..26fb167 100644 --- a/src/Adapters/PostgreSQL.php +++ b/src/Adapters/PostgreSQL.php @@ -61,7 +61,7 @@ public function set(string $key, mixed $value, int $expire = 0): bool $statement = $this->client->prepare( "INSERT INTO $this->table (k, v, e) VALUES (:key, :value, :expire) - ON CONFLICT (k) DO UPDATE SET v=EXCLUDED.v, e=EXCLUDED.e" + ON CONFLICT (k) DO UPDATE SET v=EXCLUDED.v, e=EXCLUDED.e", ); $statement->bindParam(':key', $key); @@ -87,7 +87,7 @@ protected function init(): void k VARCHAR NOT NULL PRIMARY KEY, v BYTEA, e TIMESTAMP NULL DEFAULT NULL - )" + )", ); $this->client->exec("CREATE INDEX IF NOT EXISTS e_index ON $this->table (e)"); } diff --git a/src/Adapters/Redis.php b/src/Adapters/Redis.php index 21b7b9b..0208ad3 100644 --- a/src/Adapters/Redis.php +++ b/src/Adapters/Redis.php @@ -479,13 +479,13 @@ public function getCollection(string $name): KeyValueStore $client->pconnect( $this->client->getHost(), $this->client->getPort(), - $this->client->getTimeout() + $this->client->getTimeout(), ); } else { $client->connect( $this->client->getHost(), $this->client->getPort(), - $this->client->getTimeout() + $this->client->getTimeout(), ); } diff --git a/src/Adapters/SQL.php b/src/Adapters/SQL.php index 8f409be..c2e0636 100644 --- a/src/Adapters/SQL.php +++ b/src/Adapters/SQL.php @@ -50,7 +50,7 @@ public function get(string $key, mixed &$token = null): mixed $statement = $this->client->prepare( "SELECT v FROM $this->table - WHERE k = :key AND (e IS NULL OR e > :expire)" + WHERE k = :key AND (e IS NULL OR e > :expire)", ); $statement->execute([ ':key' => $key, @@ -88,7 +88,7 @@ public function getMulti(array $keys, ?array &$tokens = null): array FROM $this->table WHERE k IN (" . implode(',', $quoted) . ') AND - (e IS NULL OR e > :expire)' + (e IS NULL OR e > :expire)', ); $statement->execute([':expire' => date('Y-m-d H:i:s')]); $values = $statement->fetchAll(\PDO::FETCH_ASSOC); @@ -138,7 +138,7 @@ public function delete(string $key): bool { $statement = $this->client->prepare( "DELETE FROM $this->table - WHERE k = :key" + WHERE k = :key", ); $statement->execute([':key' => $key]); @@ -163,7 +163,7 @@ public function deleteMulti(array $keys): array $statement = $this->client->query( "DELETE FROM $this->table - WHERE k IN (" . implode(',', $quoted) . ')' + WHERE k IN (" . implode(',', $quoted) . ')', ); /* @@ -191,7 +191,7 @@ public function add(string $key, mixed $value, int $expire = 0): bool $statement = $this->client->prepare( "INSERT INTO $this->table (k, v, e) - VALUES (:key, :value, :expire)" + VALUES (:key, :value, :expire)", ); $statement->execute([ @@ -213,7 +213,7 @@ public function replace(string $key, mixed $value, int $expire = 0): bool $statement = $this->client->prepare( "UPDATE $this->table SET v = :value, e = :expire - WHERE k = :key" + WHERE k = :key", ); $statement->execute([ @@ -232,7 +232,7 @@ public function replace(string $key, mixed $value, int $expire = 0): bool $statement = $this->client->prepare( "SELECT e FROM $this->table - WHERE k = :key AND v = :value" + WHERE k = :key AND v = :value", ); $statement->execute([ ':key' => $key, @@ -252,7 +252,7 @@ public function cas(mixed $token, string $key, mixed $value, int $expire = 0): b $statement = $this->client->prepare( "UPDATE $this->table SET v = :value, e = :expire - WHERE k = :key AND v = :token" + WHERE k = :key AND v = :token", ); $statement->execute([ @@ -272,7 +272,7 @@ public function cas(mixed $token, string $key, mixed $value, int $expire = 0): b $statement = $this->client->prepare( "SELECT e FROM $this->table - WHERE k = :key AND v = :value AND v = :token" + WHERE k = :key AND v = :value AND v = :token", ); $statement->execute([ ':key' => $key, @@ -310,7 +310,7 @@ public function touch(string $key, int $expire): bool $statement = $this->client->prepare( "UPDATE $this->table SET e = :expire - WHERE k = :key" + WHERE k = :key", ); $statement->execute([ @@ -386,7 +386,7 @@ protected function clearExpired(): void { $statement = $this->client->prepare( "DELETE FROM $this->table - WHERE e < :expire" + WHERE e < :expire", ); $statement->execute([':expire' => date('Y-m-d H:i:s')]); diff --git a/src/Adapters/SQLite.php b/src/Adapters/SQLite.php index 8b4cf31..e48db71 100644 --- a/src/Adapters/SQLite.php +++ b/src/Adapters/SQLite.php @@ -28,7 +28,7 @@ public function setMulti(array $items, int $expire = 0): array $statement = $this->client->prepare( "REPLACE INTO $this->table (k, v, e) - VALUES (:key, :value, :expire)" + VALUES (:key, :value, :expire)", ); $success = []; @@ -57,7 +57,7 @@ public function add(string $key, mixed $value, int $expire = 0): bool // SQLite-specific way to ignore insert-on-duplicate errors $statement = $this->client->prepare( "INSERT OR IGNORE INTO $this->table (k, v, e) - VALUES (:key, :value, :expire)" + VALUES (:key, :value, :expire)", ); $statement->execute([ @@ -82,7 +82,7 @@ protected function init(): void v BLOB, e TIMESTAMP NULL DEFAULT NULL, KEY e - )" + )", ); } } diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php index 0a00ff3..0750cc6 100644 --- a/src/Exception/Exception.php +++ b/src/Exception/Exception.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved * @license LICENSE MIT */ -class Exception extends \Exception -{ -} +class Exception extends \Exception {} diff --git a/src/Exception/InvalidCollection.php b/src/Exception/InvalidCollection.php index b70f60c..8526cca 100644 --- a/src/Exception/InvalidCollection.php +++ b/src/Exception/InvalidCollection.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved * @license LICENSE MIT */ -class InvalidCollection extends Exception -{ -} +class InvalidCollection extends Exception {} diff --git a/src/Exception/InvalidKey.php b/src/Exception/InvalidKey.php index cf1b900..af61cb9 100644 --- a/src/Exception/InvalidKey.php +++ b/src/Exception/InvalidKey.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved * @license LICENSE MIT */ -class InvalidKey extends Exception -{ -} +class InvalidKey extends Exception {} diff --git a/src/Exception/OperationFailed.php b/src/Exception/OperationFailed.php index 6c0a4c5..f312217 100644 --- a/src/Exception/OperationFailed.php +++ b/src/Exception/OperationFailed.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2017, Martin Georgiev. All rights reserved * @license LICENSE MIT */ -class OperationFailed extends Exception -{ -} +class OperationFailed extends Exception {} diff --git a/src/Exception/UnbegunTransaction.php b/src/Exception/UnbegunTransaction.php index 3fde45d..51eb71c 100644 --- a/src/Exception/UnbegunTransaction.php +++ b/src/Exception/UnbegunTransaction.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved * @license LICENSE MIT */ -class UnbegunTransaction extends Exception -{ -} +class UnbegunTransaction extends Exception {} diff --git a/src/Exception/UncommittedTransaction.php b/src/Exception/UncommittedTransaction.php index 182a18b..aa2f1ef 100644 --- a/src/Exception/UncommittedTransaction.php +++ b/src/Exception/UncommittedTransaction.php @@ -9,6 +9,4 @@ * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved * @license LICENSE MIT */ -class UncommittedTransaction extends Exception -{ -} +class UncommittedTransaction extends Exception {} diff --git a/src/KeyValueStore.php b/src/KeyValueStore.php index 118ce6a..a1afe48 100644 --- a/src/KeyValueStore.php +++ b/src/KeyValueStore.php @@ -68,11 +68,11 @@ public function set(string $key, mixed $value, int $expire = 0): bool; * setMulti is preferred over multiple individual set operations as you'll * set them all in 1 request. * - * @param mixed[] $items [key => value] - * @param int $expire Time when item falls out of the cache: - * 0 = permanent (doesn't expires); - * under 2592000 (30 days) = relative time, in seconds from now; - * over 2592000 = absolute time, unix timestamp + * @param mixed[] $items [key => value] + * @param int $expire Time when item falls out of the cache: + * 0 = permanent (doesn't expires); + * under 2592000 (30 days) = relative time, in seconds from now; + * over 2592000 = absolute time, unix timestamp * * @return bool[] */ @@ -134,11 +134,11 @@ public function replace(string $key, mixed $value, int $expire = 0): bool; * what's currently in cache, when a new value has been written to cache * after we've fetched it. If the operation succeeds, true will be returned. * - * @param mixed $token Token received from get() or getMulti() - * @param int $expire Time when item falls out of the cache: - * 0 = permanent (doesn't expires); - * under 2592000 (30 days) = relative time, in seconds from now; - * over 2592000 = absolute time, unix timestamp + * @param mixed $token Token received from get() or getMulti() + * @param int $expire Time when item falls out of the cache: + * 0 = permanent (doesn't expires); + * under 2592000 (30 days) = relative time, in seconds from now; + * over 2592000 = absolute time, unix timestamp */ public function cas(mixed $token, string $key, mixed $value, int $expire = 0): bool; @@ -150,12 +150,12 @@ public function cas(mixed $token, string $key, mixed $value, int $expire = 0): b * false for failure (e.g. when the value currently in cache is not a * number, in which case it can't be incremented) * - * @param int $offset Value to increment with + * @param int $offset Value to increment with * @param int $initial Initial value (if item doesn't yet exist) - * @param int $expire Time when item falls out of the cache: - * 0 = permanent (doesn't expires); - * under 2592000 (30 days) = relative time, in seconds from now; - * over 2592000 = absolute time, unix timestamp + * @param int $expire Time when item falls out of the cache: + * 0 = permanent (doesn't expires); + * under 2592000 (30 days) = relative time, in seconds from now; + * over 2592000 = absolute time, unix timestamp * * @return int|false New value or false on failure */ @@ -169,12 +169,12 @@ public function increment(string $key, int $offset = 1, int $initial = 0, int $e * false for failure (e.g. when the value currently in cache is not a * number, in which case it can't be decremented) * - * @param int $offset Value to decrement with + * @param int $offset Value to decrement with * @param int $initial Initial value (if item doesn't yet exist) - * @param int $expire Time when item falls out of the cache: - * 0 = permanent (doesn't expires); - * under 2592000 (30 days) = relative time, in seconds from now; - * over 2592000 = absolute time, unix timestamp + * @param int $expire Time when item falls out of the cache: + * 0 = permanent (doesn't expires); + * under 2592000 (30 days) = relative time, in seconds from now; + * over 2592000 = absolute time, unix timestamp * * @return int|false New value or false on failure */ diff --git a/src/Psr16/InvalidArgumentException.php b/src/Psr16/InvalidArgumentException.php index 339199f..c66256e 100644 --- a/src/Psr16/InvalidArgumentException.php +++ b/src/Psr16/InvalidArgumentException.php @@ -6,6 +6,4 @@ use MatthiasMullie\Scrapbook\Exception\Exception; -class InvalidArgumentException extends Exception implements \Psr\SimpleCache\InvalidArgumentException -{ -} +class InvalidArgumentException extends Exception implements \Psr\SimpleCache\InvalidArgumentException {} diff --git a/src/Psr6/InvalidArgumentException.php b/src/Psr6/InvalidArgumentException.php index bb78942..8cd0fc5 100644 --- a/src/Psr6/InvalidArgumentException.php +++ b/src/Psr6/InvalidArgumentException.php @@ -6,6 +6,4 @@ use MatthiasMullie\Scrapbook\Exception\Exception; -class InvalidArgumentException extends Exception implements \Psr\Cache\InvalidArgumentException -{ -} +class InvalidArgumentException extends Exception implements \Psr\Cache\InvalidArgumentException {} diff --git a/src/Scale/StampedeProtector.php b/src/Scale/StampedeProtector.php index 5e3c8f2..4eb2169 100644 --- a/src/Scale/StampedeProtector.php +++ b/src/Scale/StampedeProtector.php @@ -61,7 +61,7 @@ class StampedeProtector implements KeyValueStore /** * @param KeyValueStore $cache The real cache we'll buffer for - * @param int $sla Stampede protection time, in milliseconds + * @param int $sla Stampede protection time, in milliseconds */ public function __construct(KeyValueStore $cache, int $sla = 1000) { @@ -215,7 +215,7 @@ protected function protect(array $keys): array $success[$key] = $this->cache->add( $this->stampedeKey($key), '', - (int) ceil($this->sla / 1000) + (int) ceil($this->sla / 1000), ); } diff --git a/tests/Adapters/Couchbase/AdapterProviderTrait.php b/tests/Adapters/Couchbase/AdapterProviderTrait.php index 85e7747..61ce6ad 100644 --- a/tests/Adapters/Couchbase/AdapterProviderTrait.php +++ b/tests/Adapters/Couchbase/AdapterProviderTrait.php @@ -50,7 +50,7 @@ public function getAdapterKeyValueStore(): KeyValueStore $collection, $bucketManager, $bucket, - 30000 + 30000, ); } diff --git a/tests/Collections/AbstractCollectionsTestCase.php b/tests/Collections/AbstractCollectionsTestCase.php index 82d23ef..64a237a 100644 --- a/tests/Collections/AbstractCollectionsTestCase.php +++ b/tests/Collections/AbstractCollectionsTestCase.php @@ -30,7 +30,7 @@ public function testCollectionGetParentKey(): void { $this->markTestSkipped( 'This test is invalid for collections derived from collections. ' . - "They don't keep nesting, there's only server/collection." + "They don't keep nesting, there's only server/collection.", ); } @@ -38,7 +38,7 @@ public function testCollectionGetCollectionKey(): void { $this->markTestSkipped( 'This test is invalid for collections derived from collections. ' . - "They don't keep nesting, there's only server/collection." + "They don't keep nesting, there's only server/collection.", ); } @@ -46,7 +46,7 @@ public function testCollectionSetSameKey(): void { $this->markTestSkipped( 'This test is invalid for collections derived from collections. ' . - "They don't keep nesting, there's only server/collection." + "They don't keep nesting, there's only server/collection.", ); } @@ -54,7 +54,7 @@ public function testCollectionFlushParent(): void { $this->markTestSkipped( 'This test is invalid for collections derived from collections. ' . - "They don't keep nesting, there's only server/collection." + "They don't keep nesting, there's only server/collection.", ); } @@ -62,7 +62,7 @@ public function testCollectionFlushCollection(): void { $this->markTestSkipped( 'This test is invalid for collections derived from collections. ' . - "They don't keep nesting, there's only server/collection." + "They don't keep nesting, there's only server/collection.", ); } } diff --git a/tests/Scale/AbstractStampedeProtectorTestCase.php b/tests/Scale/AbstractStampedeProtectorTestCase.php index 792d4df..0d87799 100644 --- a/tests/Scale/AbstractStampedeProtectorTestCase.php +++ b/tests/Scale/AbstractStampedeProtectorTestCase.php @@ -104,12 +104,12 @@ public function testStampedeGetMultiExisting(): void */ $this->assertEquals( ['key' => 'value', 'key2' => 'value2'], - $this->testKeyValueStore->getMulti(['key', 'key2']) + $this->testKeyValueStore->getMulti(['key', 'key2']), ); $this->assertEquals(0, $this->testKeyValueStore->count); $this->assertEquals( [], - $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']) + $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']), ); } @@ -121,12 +121,12 @@ public function testStampedeGetMultiNonExisting(): void */ $this->assertEquals( [], - $this->testKeyValueStore->getMulti(['key', 'key2']) + $this->testKeyValueStore->getMulti(['key', 'key2']), ); $this->assertEquals(0, $this->testKeyValueStore->count); $this->assertEquals( ['key.stampede' => '', 'key2.stampede' => ''], - $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']) + $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']), ); } @@ -140,12 +140,12 @@ public function testStampedeGetMultiExistingAndNonExisting(): void */ $this->assertEquals( ['key' => 'value'], - $this->testKeyValueStore->getMulti(['key', 'key2']) + $this->testKeyValueStore->getMulti(['key', 'key2']), ); $this->assertEquals(0, $this->testKeyValueStore->count); $this->assertEquals( ['key2.stampede' => ''], - $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']) + $this->adapterKeyValueStore->getMulti(['key.stampede', 'key2.stampede']), ); } @@ -189,7 +189,7 @@ public function testStampedeGetMultiStampede(): void // some time because we were in stampede protection $this->assertEquals( ['key' => 'value', 'key2' => 'value2'], - $this->testKeyValueStore->getMulti(['key', 'key2']) + $this->testKeyValueStore->getMulti(['key', 'key2']), ); $this->assertGreaterThan(0, $this->testKeyValueStore->count);