Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing getdkan/contracts as much as possible #20

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 1 addition & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/ETL/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Harvest\ETL;

use Opis\JsonSchema\Validator;
use Opis\JsonSchema\Schema;
use Opis\JsonSchema\Validator;

class Factory
{
Expand Down
4 changes: 2 additions & 2 deletions src/ETL/Load/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
$this->itemStorage = $item_storage;
}

public function run($item)
public function run($item): int
{

$state = $this->itemState($item);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Harvester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -36,7 +36,7 @@ public function revert()
return $counter;
}

public function harvest()
public function harvest(): array
{
$result = [];
$transformers = null;
Expand Down
10 changes: 5 additions & 5 deletions src/ResultInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'])) {
Expand All @@ -64,7 +64,7 @@ private function loadCount(string $status)
return $count;
}

private function transformFailures()
private function transformFailures(): int
{
$count = 0;

Expand Down
31 changes: 27 additions & 4 deletions src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 4 additions & 2 deletions test/HarvesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace HarvestTest;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Harvest\ResultInterpreter;
use Harvest\ETL\Factory;
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions test/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Harvest\Util;

class UtilTest extends TestCase
{
public function test(): void
Expand Down