From d17ec60cc68fa02e173fa453337ae2d60977ff47 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 16 Dec 2024 08:48:24 -0600 Subject: [PATCH] Removing getdkan/contracts as much as possible (#20) --- composer.json | 4 ++-- rector.php | 8 +------- src/ETL/Factory.php | 2 +- src/ETL/Load/Load.php | 4 ++-- src/Harvester.php | 4 ++-- src/ResultInterpreter.php | 10 +++++----- src/Storage/StorageInterface.php | 31 +++++++++++++++++++++++++++---- test/HarvesterTest.php | 6 ++++-- test/UtilTest.php | 1 + 9 files changed, 45 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 1a44132..d869f82 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "require": { "php": ">7.3 <9.0", "ext-json": "*", - "getdkan/contracts": "^1.1.3", "guzzlehttp/guzzle": "^6.5.8 || >7.4.5", "opis/json-schema": "^1.0.8" }, "require-dev": { + "getdkan/contracts": "^1.2", "phpunit/phpunit": "^9.6", - "rector/rector": "^0.15.19", + "rector/rector": "^1@stable", "squizlabs/php_codesniffer": "^3.7", "symfony/phpunit-bridge": "^7.0" }, diff --git a/rector.php b/rector.php index 1236e6d..7d0808c 100644 --- a/rector.php +++ b/rector.php @@ -6,16 +6,14 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; -use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Set\ValueObject\SetList; use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ArrayShapeFromConstantArrayReturnRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src', __DIR__ . '/test', - __DIR__ . 'rector.php', + __DIR__ . '/rector.php', ]); $rectorConfig->sets([ @@ -27,14 +25,10 @@ ]); $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, ]); diff --git a/src/ETL/Factory.php b/src/ETL/Factory.php index fa7b3b9..42d9110 100644 --- a/src/ETL/Factory.php +++ b/src/ETL/Factory.php @@ -2,8 +2,8 @@ namespace Harvest\ETL; -use Opis\JsonSchema\Validator; use Opis\JsonSchema\Schema; +use Opis\JsonSchema\Validator; class Factory { diff --git a/src/ETL/Load/Load.php b/src/ETL/Load/Load.php index 53fe86d..df12191 100644 --- a/src/ETL/Load/Load.php +++ b/src/ETL/Load/Load.php @@ -24,7 +24,7 @@ public function __construct( $this->itemStorage = $item_storage; } - public function run($item) + public function run($item): int { $state = $this->itemState($item); @@ -42,7 +42,7 @@ public function run($item) return $state; } - private function itemState($item) + private function itemState($item): int { if (isset($item->identifier)) { $identifier = Util::getDatasetId($item); diff --git a/src/Harvester.php b/src/Harvester.php index 19c0ca6..523f1a5 100644 --- a/src/Harvester.php +++ b/src/Harvester.php @@ -17,7 +17,7 @@ public function __construct(Factory $factory) $this->factory = $factory; } - public function revert() + public function revert(): int { $ids = $this->factory->hashStorage->retrieveAll(); $load = $this->factory->get("load"); @@ -36,7 +36,7 @@ public function revert() return $counter; } - public function harvest() + public function harvest(): array { $result = []; $transformers = null; diff --git a/src/ResultInterpreter.php b/src/ResultInterpreter.php index 0e1453b..a1e54b9 100644 --- a/src/ResultInterpreter.php +++ b/src/ResultInterpreter.php @@ -11,17 +11,17 @@ public function __construct(array $result) $this->result = $result; } - public function countCreated() + public function countCreated(): int { return $this->loadCount("NEW"); } - public function countUpdated() + public function countUpdated(): int { return $this->loadCount("UPDATED"); } - public function countFailed() + public function countFailed(): int { $load_failures = $this->loadCount("FAILURE"); $transform_failures = $this->transformFailures(); @@ -48,7 +48,7 @@ public function countProcessed(): int return count($ids); } - private function loadCount(string $status) + private function loadCount(string $status): int { $count = 0; if (!isset($this->result['status']['load'])) { @@ -64,7 +64,7 @@ private function loadCount(string $status) return $count; } - private function transformFailures() + private function transformFailures(): int { $count = 0; diff --git a/src/Storage/StorageInterface.php b/src/Storage/StorageInterface.php index fdcc1cc..246c39c 100644 --- a/src/Storage/StorageInterface.php +++ b/src/Storage/StorageInterface.php @@ -2,10 +2,33 @@ namespace Harvest\Storage; -use Contracts\BulkRetrieverInterface; -use Contracts\StorerInterface; - -interface StorageInterface extends StorerInterface, BulkRetrieverInterface +/** + * Interface for harvest storage. + */ +interface StorageInterface { + /** + * Store data with an identifier. + * + * @param mixed $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; + /** + * Retrieve all. + * + * @return array + * An array of ids. + */ + public function retrieveAll(): array; } diff --git a/test/HarvesterTest.php b/test/HarvesterTest.php index f845c4f..2aeba77 100644 --- a/test/HarvesterTest.php +++ b/test/HarvesterTest.php @@ -2,6 +2,8 @@ namespace HarvestTest; +use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; use Harvest\ResultInterpreter; use Harvest\ETL\Factory; @@ -35,9 +37,9 @@ public function testBasic(string $uri): void $item_store = new MemStore(); $hash_store = new MemStore(); - $mock_client = $this->createMock(\GuzzleHttp\Client::class); + $mock_client = $this->createMock(Client::class); $mock_client->method('request')->willReturn( - new \GuzzleHttp\Psr7\Response( + new Response( 200, [], file_get_contents(__DIR__ . "/json/data3.json") diff --git a/test/UtilTest.php b/test/UtilTest.php index 2c350fd..5f9c5dc 100644 --- a/test/UtilTest.php +++ b/test/UtilTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Harvest\Util; + class UtilTest extends TestCase { public function test(): void