diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3fc411..6f9cfb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,11 +19,6 @@ jobs: - 7.3 - 7.2 - 7.1 - - 7.0 - - 5.6 - - 5.5 - - 5.4 - - 5.3 steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 @@ -36,19 +31,3 @@ jobs: if: ${{ matrix.php >= 7.3 }} - run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy if: ${{ matrix.php < 7.3 }} - - PHPUnit-hhvm: - name: PHPUnit (HHVM) - runs-on: ubuntu-22.04 - continue-on-error: true - steps: - - uses: actions/checkout@v4 - - run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM - - name: Run hhvm composer.phar require react/promise:^2 # downgrade Promise for HHVM - uses: docker://hhvm/hhvm:3.30-lts-latest - with: - args: hhvm composer.phar require react/promise:^2 - - name: Run hhvm vendor/bin/phpunit - uses: docker://hhvm/hhvm:3.30-lts-latest - with: - args: hhvm vendor/bin/phpunit diff --git a/README.md b/README.md index 2213c57..cf6a8ea 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Similarly, an expired cache item (once the time-to-live is expired) is considered a cache miss. ```php -$cache->getMultiple(array('name', 'age'))->then(function (array $values) { +$cache->getMultiple(['name', 'age'])->then(function (array $values) { $name = $values['name'] ?? 'User'; $age = $values['age'] ?? 'n/a'; @@ -170,7 +170,7 @@ supports. Trying to access an expired cache items results in a cache miss, see also [`getMultiple()`](#getmultiple). ```php -$cache->setMultiple(array('foo' => 1, 'bar' => 2), 60); +$cache->setMultiple(['foo' => 1, 'bar' => 2], 60); ``` This example eventually sets the list of values - the key `foo` to `1` value @@ -187,7 +187,7 @@ to `true`. If the cache implementation has to go over the network to delete it, it may take a while. ```php -$cache->deleteMultiple(array('foo', 'bar, 'baz')); +$cache->deleteMultiple(['foo', 'bar, 'baz']); ``` This example eventually deletes keys `foo`, `bar` and `baz` from the cache. @@ -322,7 +322,7 @@ public function getAndCacheFooFromDb() { return $this->db ->get('foo') - ->then(array($this, 'cacheFooFromDb')); + ->then([$this, 'cacheFooFromDb']); } public function cacheFooFromDb($foo) @@ -351,9 +351,8 @@ composer require react/cache:^3@dev See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. This project aims to run on any platform and thus does not require any PHP -extensions and supports running on legacy PHP 5.3 through current PHP 8+ and -HHVM. -It's *highly recommended to use PHP 7+* for this project. +extensions and supports running on PHP 7.1 through current PHP 8+. +It's *highly recommended to use the latest supported PHP version* for this project. ## Tests diff --git a/composer.json b/composer.json index 4924c2e..25983ae 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,11 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=7.1", "react/promise": "^3.0 || ^2.0 || ^1.1" }, "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + "phpunit/phpunit": "^9.6 || ^7.5" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy index 8916116..0086860 100644 --- a/phpunit.xml.legacy +++ b/phpunit.xml.legacy @@ -2,7 +2,7 @@ diff --git a/src/ArrayCache.php b/src/ArrayCache.php index 81f25ef..ed97c0c 100644 --- a/src/ArrayCache.php +++ b/src/ArrayCache.php @@ -2,14 +2,14 @@ namespace React\Cache; -use React\Promise; -use React\Promise\PromiseInterface; +use function React\Promise\all; +use function React\Promise\resolve; class ArrayCache implements CacheInterface { private $limit; - private $data = array(); - private $expires = array(); + private $data = []; + private $expires = []; private $supportsHighResolution; /** @@ -65,7 +65,7 @@ public function get($key, $default = null) } if (!\array_key_exists($key, $this->data)) { - return Promise\resolve($default); + return resolve($default); } // remove and append to end of array to keep track of LRU info @@ -73,7 +73,7 @@ public function get($key, $default = null) unset($this->data[$key]); $this->data[$key] = $value; - return Promise\resolve($value); + return resolve($value); } public function set($key, $value, $ttl = null) @@ -105,25 +105,25 @@ public function set($key, $value, $ttl = null) unset($this->data[$key], $this->expires[$key]); } - return Promise\resolve(true); + return resolve(true); } public function delete($key) { unset($this->data[$key], $this->expires[$key]); - return Promise\resolve(true); + return resolve(true); } public function getMultiple(array $keys, $default = null) { - $values = array(); + $values = []; foreach ($keys as $key) { $values[$key] = $this->get($key, $default); } - return Promise\all($values); + return all($values); } public function setMultiple(array $values, $ttl = null) @@ -132,7 +132,7 @@ public function setMultiple(array $values, $ttl = null) $this->set($key, $value, $ttl); } - return Promise\resolve(true); + return resolve(true); } public function deleteMultiple(array $keys) @@ -141,15 +141,15 @@ public function deleteMultiple(array $keys) unset($this->data[$key], $this->expires[$key]); } - return Promise\resolve(true); + return resolve(true); } public function clear() { - $this->data = array(); - $this->expires = array(); + $this->data = []; + $this->expires = []; - return Promise\resolve(true); + return resolve(true); } public function has($key) @@ -160,7 +160,7 @@ public function has($key) } if (!\array_key_exists($key, $this->data)) { - return Promise\resolve(false); + return resolve(false); } // remove and append to end of array to keep track of LRU info @@ -168,7 +168,7 @@ public function has($key) unset($this->data[$key]); $this->data[$key] = $value; - return Promise\resolve(true); + return resolve(true); } /** diff --git a/src/CacheInterface.php b/src/CacheInterface.php index 8e51c19..04beb69 100644 --- a/src/CacheInterface.php +++ b/src/CacheInterface.php @@ -106,7 +106,7 @@ public function delete($key); * considered a cache miss. * * ```php - * $cache->getMultiple(array('name', 'age'))->then(function (array $values) { + * $cache->getMultiple(['name', 'age'])->then(function (array $values) { * $name = $values['name'] ?? 'User'; * $age = $values['age'] ?? 'n/a'; * @@ -138,7 +138,7 @@ public function getMultiple(array $keys, $default = null); * see also [`get()`](#get). * * ```php - * $cache->setMultiple(array('foo' => 1, 'bar' => 2), 60); + * $cache->setMultiple(['foo' => 1, 'bar' => 2], 60); * ``` * * This example eventually sets the list of values - the key `foo` to 1 value diff --git a/tests/ArrayCacheTest.php b/tests/ArrayCacheTest.php index 420d45f..be86783 100644 --- a/tests/ArrayCacheTest.php +++ b/tests/ArrayCacheTest.php @@ -203,27 +203,27 @@ public function testGetMultiple() $this->cache->set('foo', '1'); $this->cache - ->getMultiple(array('foo', 'bar'), 'baz') - ->then($this->expectCallableOnceWith(array('foo' => '1', 'bar' => 'baz'))); + ->getMultiple(['foo', 'bar'], 'baz') + ->then($this->expectCallableOnceWith(['foo' => '1', 'bar' => 'baz'])); } public function testSetMultiple() { $this->cache = new ArrayCache(); - $this->cache->setMultiple(array('foo' => '1', 'bar' => '2'), 10); + $this->cache->setMultiple(['foo' => '1', 'bar' => '2'], 10); $this->cache - ->getMultiple(array('foo', 'bar')) - ->then($this->expectCallableOnceWith(array('foo' => '1', 'bar' => '2'))); + ->getMultiple(['foo', 'bar']) + ->then($this->expectCallableOnceWith(['foo' => '1', 'bar' => '2'])); } public function testDeleteMultiple() { $this->cache = new ArrayCache(); - $this->cache->setMultiple(array('foo' => 1, 'bar' => 2, 'baz' => 3)); + $this->cache->setMultiple(['foo' => 1, 'bar' => 2, 'baz' => 3]); $this->cache - ->deleteMultiple(array('foo', 'baz')) + ->deleteMultiple(['foo', 'baz']) ->then($this->expectCallableOnceWith(true)); $this->cache @@ -242,7 +242,7 @@ public function testDeleteMultiple() public function testClearShouldClearCache() { $this->cache = new ArrayCache(); - $this->cache->setMultiple(array('foo' => 1, 'bar' => 2, 'baz' => 3)); + $this->cache->setMultiple(['foo' => 1, 'bar' => 2, 'baz' => 3]); $this->cache->clear(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 53597e0..45aa5c2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -49,12 +49,13 @@ protected function expectCallableNever() protected function createCallableMock() { - if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + $builder = $this->getMockBuilder(\stdClass::class); + if (method_exists($builder, 'addMethods')) { // PHPUnit 9+ - return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock(); + return $builder->addMethods(['__invoke'])->getMock(); } else { - // legacy PHPUnit 4 - PHPUnit 9 - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + // legacy PHPUnit + return $builder->setMethods(['__invoke'])->getMock(); } } }