From 38eba44d1ebd5cbac2a89d1c0d848ee92428dd3b Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 16 Jan 2024 10:51:12 -0800 Subject: [PATCH] Support PHP 8.2 (#15) * helpful rector, declare return values * adds php 8.2 to testing matrix * adds symfony/phpunit-bridge * make circleci config consistent with other getdkan packages --- .circleci/config.yml | 8 +++--- composer.json | 3 +- phpunit.xml | 9 +++++- rector.php | 36 ++++++++++++++++++++---- src/Mock/IdGenerator/Sequential.php | 2 +- src/Mock/Storage/JsonObjectMemory.php | 14 ++++----- src/StorerInterface.php | 30 ++++++++++---------- test/Mock/IdGenerator/SequentialTest.php | 2 +- test/Mock/Storage/MemoryTest.php | 15 ++++++---- 9 files changed, 77 insertions(+), 42 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index baca078..bea41e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -143,7 +143,7 @@ jobs: tag: << parameters.version >> parameters: version: - default: "7.4" + default: "8.2" description: The `cimg/php` Docker image version tag. type: string install-flags: @@ -154,7 +154,7 @@ jobs: - when: condition: and: - - equal: [ "8.1", <> ] + - equal: [ "8.2", <> ] - equal: [ "", <> ] steps: - run-phpunit-tests: @@ -164,7 +164,7 @@ jobs: condition: not: and: - - equal: [ "8.1", <> ] + - equal: [ "8.2", <> ] - equal: [ "", <> ] steps: - run-phpunit-tests: @@ -176,5 +176,5 @@ workflows: - matrix-conditions: matrix: parameters: - version: ["7.4", "8.0", "8.1"] + version: ["7.4", "8.0", "8.1", "8.2"] install-flags: ["", "--prefer-lowest"] diff --git a/composer.json b/composer.json index 69ed766..66f087b 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "require-dev": { "phpunit/phpunit": "^9.6", "rector/rector": "^0.15.17", - "squizlabs/php_codesniffer": "^3.7" + "squizlabs/php_codesniffer": "^3.7", + "symfony/phpunit-bridge": "^7.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 8ffc757..eceeba6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,9 +6,16 @@ src + + + + + + + - test + test diff --git a/rector.php b/rector.php index 81e3216..310105f 100644 --- a/rector.php +++ b/rector.php @@ -1,14 +1,18 @@ paths([ @@ -16,11 +20,31 @@ __DIR__ . '/test', ]); + // Our base version of PHP. + $rectorConfig->phpVersion(PhpVersion::PHP_74); + $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_74, + SetList::PHP_82, + // Please no dead code or unneeded variables. + SetList::DEAD_CODE, + // Try to figure out type hints. + SetList::TYPE_DECLARATION, ]); $rectorConfig->skip([ + // Don't throw errors on JSON parse problems. Yet. + // @todo Throw errors and deal with them appropriately. JsonThrowOnErrorRector::class, + // We like our tags. Please don't remove them. + RemoveUselessParamTagRector::class, + RemoveUselessReturnTagRector::class, + RemoveUselessVarTagRector::class, + ArrayShapeFromConstantArrayReturnRector::class, + AddMethodCallBasedStrictParamTypeRector::class, + AddArrowFunctionReturnTypeRector::class, + ReturnTypeFromStrictTypedCallRector::class, ]); + + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); }; diff --git a/src/Mock/IdGenerator/Sequential.php b/src/Mock/IdGenerator/Sequential.php index dd7a68c..49b9171 100644 --- a/src/Mock/IdGenerator/Sequential.php +++ b/src/Mock/IdGenerator/Sequential.php @@ -7,7 +7,7 @@ class Sequential implements IdGeneratorInterface { private int $id = 0; - public function generate() + public function generate(): int { $this->id++; return $this->id; diff --git a/src/Mock/Storage/JsonObjectMemory.php b/src/Mock/Storage/JsonObjectMemory.php index 11f6d59..4723cbc 100644 --- a/src/Mock/Storage/JsonObjectMemory.php +++ b/src/Mock/Storage/JsonObjectMemory.php @@ -37,27 +37,27 @@ public function store($data, string $id = null): string return parent::store($data, $id); } - public function conditionByIsEqualTo(string $property, string $value) + public function conditionByIsEqualTo(string $property, string $value): void { $this->conditions[$property][] = $value; } - public function limitTo(int $number_of_items) + public function limitTo(int $number_of_items): void { $this->limit = $number_of_items; } - public function offsetBy(int $offset) + public function offsetBy(int $offset): void { $this->offset = $offset; } - public function sortByAscending(string $property) + public function sortByAscending(string $property): void { $this->sorts['ascend'][] = $property; } - public function sortByDescending(string $property) + public function sortByDescending(string $property): void { $this->sorts['descend'][] = $property; } @@ -100,7 +100,7 @@ private function applyFilters(array $results) return $results; } - private function resetFilters() + private function resetFilters(): void { $this->offset = 0; $this->limit = 0; @@ -124,7 +124,7 @@ private function validate(string $data) } } - private function compare($a, $b, $property) + private function compare($a, $b, $property): int { $a = json_decode($a); $b = json_decode($b); diff --git a/src/StorerInterface.php b/src/StorerInterface.php index b8e8eb5..53565d5 100644 --- a/src/StorerInterface.php +++ b/src/StorerInterface.php @@ -4,20 +4,20 @@ interface StorerInterface { - /** - * Store. - * - * @param string|HydratableInterface $data - * The data to be stored. - * @param string $id - * The identifier for the data. If the act of storing generates the - * id, there is no need to pass one. - * - * @return string - * The identifier. - * - * @throws \Exception - * Issues storing the data. - */ + /** + * Store. + * + * @param string|HydratableInterface $data + * The data to be stored. + * @param string|null $id + * The identifier for the data. If the act of storing generates the + * id, there is no need to pass one. + * + * @return string + * The identifier. + * + * @throws \Exception + * Issues storing the data. + */ public function store($data, string $id = null): string; } diff --git a/test/Mock/IdGenerator/SequentialTest.php b/test/Mock/IdGenerator/SequentialTest.php index f037055..c9a812f 100644 --- a/test/Mock/IdGenerator/SequentialTest.php +++ b/test/Mock/IdGenerator/SequentialTest.php @@ -7,7 +7,7 @@ class SequentialTest extends TestCase { - public function test() + public function test(): void { $generator = new Sequential(); $id1 = $generator->generate(); diff --git a/test/Mock/Storage/MemoryTest.php b/test/Mock/Storage/MemoryTest.php index 604186b..f96427a 100644 --- a/test/Mock/Storage/MemoryTest.php +++ b/test/Mock/Storage/MemoryTest.php @@ -4,11 +4,14 @@ namespace ContractsTest; +use PHPUnit\Framework\TestCase; +use Contracts\Mock\Storage\Memory; +use Contracts\Mock\Storage\JsonObjectMemory; use Contracts\Mock\Storage\MemoryFactory; -class MemoryTest extends \PHPUnit\Framework\TestCase +class MemoryTest extends TestCase { - public function testStorageMemoryException() + public function testStorageMemoryException(): void { $factory = new MemoryFactory(); $store = $factory->getInstance("store"); @@ -17,9 +20,9 @@ public function testStorageMemoryException() $store->store("Data"); } - public function testStorageMemory() + public function testStorageMemory(): void { - $store = new \Contracts\Mock\Storage\Memory(); + $store = new Memory(); $store->store("Data", "1"); $this->assertEquals("Data", $store->retrieve("1")); @@ -37,7 +40,7 @@ public function testStorageMemory() $this->assertNull($store->retrieve("1")); } - public function testStorageJsonObjectMemory() + public function testStorageJsonObjectMemory(): void { $objects = []; $objects[] = << $object) {