Skip to content

Commit d17ec60

Browse files
authored
Removing getdkan/contracts as much as possible (#20)
1 parent a76042d commit d17ec60

File tree

9 files changed

+45
-25
lines changed

9 files changed

+45
-25
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"require": {
77
"php": ">7.3 <9.0",
88
"ext-json": "*",
9-
"getdkan/contracts": "^1.1.3",
109
"guzzlehttp/guzzle": "^6.5.8 || >7.4.5",
1110
"opis/json-schema": "^1.0.8"
1211
},
1312
"require-dev": {
13+
"getdkan/contracts": "^1.2",
1414
"phpunit/phpunit": "^9.6",
15-
"rector/rector": "^0.15.19",
15+
"rector/rector": "^1@stable",
1616
"squizlabs/php_codesniffer": "^3.7",
1717
"symfony/phpunit-bridge": "^7.0"
1818
},

rector.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
77
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
88
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
9-
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
109
use Rector\Set\ValueObject\SetList;
1110
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
12-
use Rector\TypeDeclaration\Rector\ClassMethod\ArrayShapeFromConstantArrayReturnRector;
1311

1412
return static function (RectorConfig $rectorConfig): void {
1513
$rectorConfig->paths([
1614
__DIR__ . '/src',
1715
__DIR__ . '/test',
18-
__DIR__ . 'rector.php',
16+
__DIR__ . '/rector.php',
1917
]);
2018

2119
$rectorConfig->sets([
@@ -27,14 +25,10 @@
2725
]);
2826

2927
$rectorConfig->skip([
30-
// Don't throw errors on JSON parse problems. Yet.
31-
// @todo Throw errors and deal with them appropriately.
32-
JsonThrowOnErrorRector::class,
3328
// We like our tags. Please don't remove them.
3429
RemoveUselessParamTagRector::class,
3530
RemoveUselessReturnTagRector::class,
3631
RemoveUselessVarTagRector::class,
37-
ArrayShapeFromConstantArrayReturnRector::class,
3832
AddMethodCallBasedStrictParamTypeRector::class,
3933
]);
4034

src/ETL/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Harvest\ETL;
44

5-
use Opis\JsonSchema\Validator;
65
use Opis\JsonSchema\Schema;
6+
use Opis\JsonSchema\Validator;
77

88
class Factory
99
{

src/ETL/Load/Load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
$this->itemStorage = $item_storage;
2525
}
2626

27-
public function run($item)
27+
public function run($item): int
2828
{
2929

3030
$state = $this->itemState($item);
@@ -42,7 +42,7 @@ public function run($item)
4242
return $state;
4343
}
4444

45-
private function itemState($item)
45+
private function itemState($item): int
4646
{
4747
if (isset($item->identifier)) {
4848
$identifier = Util::getDatasetId($item);

src/Harvester.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(Factory $factory)
1717
$this->factory = $factory;
1818
}
1919

20-
public function revert()
20+
public function revert(): int
2121
{
2222
$ids = $this->factory->hashStorage->retrieveAll();
2323
$load = $this->factory->get("load");
@@ -36,7 +36,7 @@ public function revert()
3636
return $counter;
3737
}
3838

39-
public function harvest()
39+
public function harvest(): array
4040
{
4141
$result = [];
4242
$transformers = null;

src/ResultInterpreter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ public function __construct(array $result)
1111
$this->result = $result;
1212
}
1313

14-
public function countCreated()
14+
public function countCreated(): int
1515
{
1616
return $this->loadCount("NEW");
1717
}
1818

19-
public function countUpdated()
19+
public function countUpdated(): int
2020
{
2121
return $this->loadCount("UPDATED");
2222
}
2323

24-
public function countFailed()
24+
public function countFailed(): int
2525
{
2626
$load_failures = $this->loadCount("FAILURE");
2727
$transform_failures = $this->transformFailures();
@@ -48,7 +48,7 @@ public function countProcessed(): int
4848
return count($ids);
4949
}
5050

51-
private function loadCount(string $status)
51+
private function loadCount(string $status): int
5252
{
5353
$count = 0;
5454
if (!isset($this->result['status']['load'])) {
@@ -64,7 +64,7 @@ private function loadCount(string $status)
6464
return $count;
6565
}
6666

67-
private function transformFailures()
67+
private function transformFailures(): int
6868
{
6969
$count = 0;
7070

src/Storage/StorageInterface.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,33 @@
22

33
namespace Harvest\Storage;
44

5-
use Contracts\BulkRetrieverInterface;
6-
use Contracts\StorerInterface;
7-
8-
interface StorageInterface extends StorerInterface, BulkRetrieverInterface
5+
/**
6+
* Interface for harvest storage.
7+
*/
8+
interface StorageInterface
99
{
10+
/**
11+
* Store data with an identifier.
12+
*
13+
* @param mixed $data
14+
* The data to be stored.
15+
* @param string|null $id
16+
* The identifier for the data. If the act of storing generates the
17+
* id, there is no need to pass one.
18+
*
19+
* @return string
20+
* The identifier.
21+
*
22+
* @throws \Exception
23+
* Issues storing the data.
24+
*/
25+
public function store($data, string $id = null): string;
1026

27+
/**
28+
* Retrieve all.
29+
*
30+
* @return array
31+
* An array of ids.
32+
*/
33+
public function retrieveAll(): array;
1134
}

test/HarvesterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace HarvestTest;
44

5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Psr7\Response;
57
use PHPUnit\Framework\TestCase;
68
use Harvest\ResultInterpreter;
79
use Harvest\ETL\Factory;
@@ -35,9 +37,9 @@ public function testBasic(string $uri): void
3537
$item_store = new MemStore();
3638
$hash_store = new MemStore();
3739

38-
$mock_client = $this->createMock(\GuzzleHttp\Client::class);
40+
$mock_client = $this->createMock(Client::class);
3941
$mock_client->method('request')->willReturn(
40-
new \GuzzleHttp\Psr7\Response(
42+
new Response(
4143
200,
4244
[],
4345
file_get_contents(__DIR__ . "/json/data3.json")

test/UtilTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Harvest\Util;
7+
78
class UtilTest extends TestCase
89
{
910
public function test(): void

0 commit comments

Comments
 (0)