From 57592281a35160430813618f1b935d47e9e0f046 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 1 May 2024 12:45:40 -0400 Subject: [PATCH 01/18] added interfaces to common module --- .../src/Contracts/BulkRetrieverInterface.php | 8 ++ .../src/Contracts/BulkStorerInterface.php | 8 ++ .../src/Contracts/ConditionerInterface.php | 8 ++ .../src/Contracts/CountableInterface.php | 9 ++ .../common/src/Contracts/FactoryInterface.php | 9 ++ .../src/Contracts/HydratableInterface.php | 9 ++ .../src/Contracts/IdGeneratorInterface.php | 9 ++ .../common/src/Contracts/LimiterInterface.php | 9 ++ .../src/Contracts/OffsetterInterface.php | 8 ++ .../common/src/Contracts/ParserInterface.php | 10 ++ .../common/src/Contracts/RemoverInterface.php | 9 ++ .../src/Contracts/RetrieverInterface.php | 9 ++ .../common/src/Contracts/SorterInterface.php | 9 ++ .../common/src/Contracts/StorerInterface.php | 9 ++ modules/common/tests/src/Unit/MemoryTest.php | 132 ++++++++++++++++++ .../src/Unit/Mocks/IdGenerator/Sequential.php | 15 ++ .../Unit/Mocks/Storage/JsonObjectMemory.php | 121 ++++++++++++++++ .../tests/src/Unit/Mocks/Storage/Memory.php | 44 ++++++ .../src/Unit/Mocks/Storage/MemoryFactory.php | 18 +++ .../common/tests/src/Unit/SequentialTest.php | 24 ++++ .../tests/src/Unit/Storage/JobStoreTest.php | 4 +- 21 files changed, 479 insertions(+), 2 deletions(-) create mode 100644 modules/common/src/Contracts/BulkRetrieverInterface.php create mode 100644 modules/common/src/Contracts/BulkStorerInterface.php create mode 100644 modules/common/src/Contracts/ConditionerInterface.php create mode 100644 modules/common/src/Contracts/CountableInterface.php create mode 100644 modules/common/src/Contracts/FactoryInterface.php create mode 100644 modules/common/src/Contracts/HydratableInterface.php create mode 100644 modules/common/src/Contracts/IdGeneratorInterface.php create mode 100644 modules/common/src/Contracts/LimiterInterface.php create mode 100644 modules/common/src/Contracts/OffsetterInterface.php create mode 100644 modules/common/src/Contracts/ParserInterface.php create mode 100644 modules/common/src/Contracts/RemoverInterface.php create mode 100644 modules/common/src/Contracts/RetrieverInterface.php create mode 100644 modules/common/src/Contracts/SorterInterface.php create mode 100644 modules/common/src/Contracts/StorerInterface.php create mode 100644 modules/common/tests/src/Unit/MemoryTest.php create mode 100644 modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php create mode 100644 modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php create mode 100644 modules/common/tests/src/Unit/Mocks/Storage/Memory.php create mode 100644 modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php create mode 100644 modules/common/tests/src/Unit/SequentialTest.php diff --git a/modules/common/src/Contracts/BulkRetrieverInterface.php b/modules/common/src/Contracts/BulkRetrieverInterface.php new file mode 100644 index 0000000000..8697d821af --- /dev/null +++ b/modules/common/src/Contracts/BulkRetrieverInterface.php @@ -0,0 +1,8 @@ +getInstance('store'); + + $this->expectExceptionMessage('An id is required to store the data.'); + $store->store('Data'); + } + + public function testStorageMemory(): void { + $store = new Memory(); + + $store->store('Data', '1'); + $this->assertEquals('Data', $store->retrieve('1')); + + $store->store('Data 2', '2'); + $this->assertEquals('Data 2', $store->retrieve('2')); + + $all = $store->retrieveAll(); + $this->assertTrue(is_array($all)); + + $this->assertEquals('Data', $all['1']); + + $store->remove('1'); + + $this->assertNull($store->retrieve('1')); + } + + public function testStorageJsonObjectMemory(): void { + $objects = []; + $objects[] = << $object) { + $store->store($object, "{$index}"); + } + + $this->assertEquals(4, count($store->retrieveAll())); + + $store->offsetBy(1); + $store->limitTo(1); + + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[1], $string); + } + + $store->offsetBy(3); + + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[3], $string); + } + + $store->limitTo(1); + + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[0], $string); + } + + $store->sortByAscending('first'); + + $order = [0, 2, 3, 1]; + $order_index = 0; + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[$order[$order_index]], $string); + $order_index++; + } + + $store->sortByDescending('first'); + + $order = [1, 3, 2, 0]; + $order_index = 0; + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[$order[$order_index]], $string); + $order_index++; + } + + $store->conditionByIsEqualTo('first', 'Gerardo'); + + $order = [0, 2]; + $order_index = 0; + foreach ($store->retrieveAll() as $string) { + $this->assertEquals($objects[$order[$order_index]], $string); + $order_index++; + } + } + +} diff --git a/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php b/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php new file mode 100644 index 0000000000..d3903e23cb --- /dev/null +++ b/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php @@ -0,0 +1,15 @@ +id++; + return $this->id; + } +} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php b/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php new file mode 100644 index 0000000000..39861be5b7 --- /dev/null +++ b/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php @@ -0,0 +1,121 @@ + [], + 'descend' => [], + ]; + + private array $conditions = []; + + public function retrieveAll(): array { + $results = parent::retrieveAll(); + $results = $this->applyFilters($results); + $this->resetFilters(); + return $results; + } + + public function store($data, string $id = NULL): string { + $this->validate($data); + return parent::store($data, $id); + } + + public function conditionByIsEqualTo(string $property, string $value): void { + $this->conditions[$property][] = $value; + } + + public function limitTo(int $number_of_items): void { + $this->limit = $number_of_items; + } + + public function offsetBy(int $offset): void { + $this->offset = $offset; + } + + public function sortByAscending(string $property): void { + $this->sorts['ascend'][] = $property; + } + + public function sortByDescending(string $property): void { + $this->sorts['descend'][] = $property; + } + + private function applyFilters(array $results) { + + if (!empty($this->conditions)) { + $results2 = []; + + foreach ($this->conditions as $property => $values) { + foreach ($values as $value) { + foreach ($results as $key => $result) { + $obj = json_decode($result); + if ($obj->{$property} == $value) { + $results2[$key] = $result; + } + } + } + } + + $results = $results2; + } + + foreach ($this->sorts as $type => $properties) { + foreach ($properties as $property) { + usort($results, fn($a, $b) => $this->compare($a, $b, $property)); + + if ($type == 'descend') { + $results = array_reverse($results); + } + } + } + + if ($this->limit > 0 || $this->offset > 0) { + $results = array_slice($results, $this->offset, $this->limit); + } + + return $results; + } + + private function resetFilters(): void { + $this->offset = 0; + $this->limit = 0; + + $this->sorts = [ + 'ascend' => [], + 'descend' => [], + ]; + + $this->conditions = []; + } + + private function validate(string $data) { + $decoded = json_decode($data); + if (is_null($decoded)) { + throw new \Exception('Only JSON strings can be stored'); + } + if (!is_object($decoded)) { + throw new \Exception('Only strings with JSON objects can be stored'); + } + } + + private function compare($a, $b, $property): int { + $a = json_decode($a); + $b = json_decode($b); + return strnatcmp($a->{$property}, $b->{$property}); + } + +} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/Memory.php b/modules/common/tests/src/Unit/Mocks/Storage/Memory.php new file mode 100644 index 0000000000..0b033aea88 --- /dev/null +++ b/modules/common/tests/src/Unit/Mocks/Storage/Memory.php @@ -0,0 +1,44 @@ +storage[$id])) { + return $this->storage[$id]; + } + return NULL; + } + + public function retrieveAll(): array { + return $this->storage; + } + + public function store($data, string $id = NULL): string { + if (!isset($id)) { + throw new \Exception('An id is required to store the data.'); + } + if (!isset($this->storage[$id])) { + $this->storage[$id] = $data; + return $id; + } + $this->storage[$id] = $data; + return TRUE; + } + + public function remove(string $id) { + if (isset($this->storage[$id])) { + unset($this->storage[$id]); + return TRUE; + } + return FALSE; + } + +} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php b/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php new file mode 100644 index 0000000000..8fb9e166ea --- /dev/null +++ b/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php @@ -0,0 +1,18 @@ +stores[$identifier])) { + $this->stores[$identifier] = new Memory(); + } + return $this->stores[$identifier]; + } + +} diff --git a/modules/common/tests/src/Unit/SequentialTest.php b/modules/common/tests/src/Unit/SequentialTest.php new file mode 100644 index 0000000000..94434ef432 --- /dev/null +++ b/modules/common/tests/src/Unit/SequentialTest.php @@ -0,0 +1,24 @@ +generate(); + $this->assertEquals(1, $id1); + $id2 = $generator->generate(); + $this->assertEquals(2, $id2); + } + +} diff --git a/modules/common/tests/src/Unit/Storage/JobStoreTest.php b/modules/common/tests/src/Unit/Storage/JobStoreTest.php index 21d9013b24..3aa46130c0 100644 --- a/modules/common/tests/src/Unit/Storage/JobStoreTest.php +++ b/modules/common/tests/src/Unit/Storage/JobStoreTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\common\Unit\Storage; -use Contracts\Mock\Storage\Memory; +use Drupal\common\Storage\JobStore; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\Delete; use Drupal\Core\Database\Query\Select; @@ -10,7 +10,7 @@ use Drupal\Core\Database\Schema; use Drupal\Core\Database\StatementWrapper; use Drupal\Core\Database\StatementWrapperIterator; -use Drupal\common\Storage\JobStore; +use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use FileFetcher\FileFetcher; use MockChain\Chain; use MockChain\Sequence; From 2880beda78e4a8797fe7b381b9ba2e98ee73e172 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 1 May 2024 12:57:28 -0400 Subject: [PATCH 02/18] replaced use statements --- .../src/FileFetcher/FileFetcherFactory.php | 2 +- .../src/Storage/DatabaseTableInterface.php | 12 ++++++------ modules/common/src/Storage/Query.php | 8 ++++---- .../src/Storage/StorageFactoryInterface.php | 2 +- .../src/FileFetcher/CustomFileFetcherFactory.php | 2 +- .../src/Unit/Mocks/IdGenerator/Sequential.php | 16 ++++++++-------- .../src/Plugin/QueueWorker/ImportJob.php | 2 +- .../Service/Factory/ImportFactoryInterface.php | 2 +- .../datastore/src/Service/ResourceLocalizer.php | 2 +- .../src/Storage/DatabaseTableFactory.php | 2 +- .../Unit/Plugin/QueueWorker/ImportJobTest.php | 4 ++-- .../src/Unit/Service/Info/ImportInfoTest.php | 2 +- modules/harvest/src/HarvestService.php | 2 +- modules/harvest/src/Service.php | 2 +- .../harvest/src/Storage/DatabaseTableFactory.php | 2 +- .../HarvestHashesDatabaseTableFactory.php | 2 +- modules/harvest/src/Storage/IdGenerator.php | 2 +- .../harvest/tests/src/Unit/Load/DatasetTest.php | 2 +- .../harvest/tests/src/Unit/WebServiceApiTest.php | 2 +- .../Factory/MetastoreItemFactoryInterface.php | 2 +- modules/metastore/src/Reference/Dereferencer.php | 2 +- .../metastore/src/Reference/ReferenceLookup.php | 2 +- modules/metastore/src/Reference/Referencer.php | 2 +- modules/metastore/src/SchemaRetriever.php | 2 +- modules/metastore/src/Storage/DataFactory.php | 2 +- 25 files changed, 41 insertions(+), 41 deletions(-) diff --git a/modules/common/src/FileFetcher/FileFetcherFactory.php b/modules/common/src/FileFetcher/FileFetcherFactory.php index 43ef59cc0d..b74d95b210 100644 --- a/modules/common/src/FileFetcher/FileFetcherFactory.php +++ b/modules/common/src/FileFetcher/FileFetcherFactory.php @@ -2,7 +2,7 @@ namespace Drupal\common\FileFetcher; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\common\Storage\FileFetcherJobStoreFactory; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; diff --git a/modules/common/src/Storage/DatabaseTableInterface.php b/modules/common/src/Storage/DatabaseTableInterface.php index a00741e2cd..68f564fce9 100644 --- a/modules/common/src/Storage/DatabaseTableInterface.php +++ b/modules/common/src/Storage/DatabaseTableInterface.php @@ -2,12 +2,12 @@ namespace Drupal\common\Storage; -use Contracts\RemoverInterface; -use Contracts\RetrieverInterface; -use Contracts\StorerInterface; -use Contracts\BulkRetrieverInterface; -use Contracts\BulkStorerInterface; -use Contracts\CountableInterface; +use Drupal\common\Contracts\RemoverInterface; +use Drupal\common\Contracts\RetrieverInterface; +use Drupal\common\Contracts\StorerInterface; +use Drupal\common\Contracts\BulkRetrieverInterface; +use Drupal\common\Contracts\BulkStorerInterface; +use Drupal\common\Contracts\CountableInterface; /** * Databaset table interface. diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index a18d330d1b..477e773a69 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -2,10 +2,10 @@ namespace Drupal\common\Storage; -use Contracts\SorterInterface; -use Contracts\ConditionerInterface; -use Contracts\OffsetterInterface; -use Contracts\LimiterInterface; +use Drupal\common\Contracts\SorterInterface; +use Drupal\common\Contracts\ConditionerInterface; +use Drupal\common\Contracts\OffsetterInterface; +use Drupal\common\Contracts\LimiterInterface; /** * DKAN API Query data object. diff --git a/modules/common/src/Storage/StorageFactoryInterface.php b/modules/common/src/Storage/StorageFactoryInterface.php index ec44268f63..b43e7f9580 100644 --- a/modules/common/src/Storage/StorageFactoryInterface.php +++ b/modules/common/src/Storage/StorageFactoryInterface.php @@ -2,7 +2,7 @@ namespace Drupal\common\Storage; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; /** * Interface for storage factories. diff --git a/modules/common/tests/modules/custom_processor_test/src/FileFetcher/CustomFileFetcherFactory.php b/modules/common/tests/modules/custom_processor_test/src/FileFetcher/CustomFileFetcherFactory.php index 7a2d888f37..febf2937a0 100644 --- a/modules/common/tests/modules/custom_processor_test/src/FileFetcher/CustomFileFetcherFactory.php +++ b/modules/common/tests/modules/custom_processor_test/src/FileFetcher/CustomFileFetcherFactory.php @@ -2,7 +2,7 @@ namespace Drupal\custom_processor_test\FileFetcher; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; /** * Creates new file fetcher objects with NonProcessor as a custom processor. diff --git a/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php b/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php index d3903e23cb..2e503a05bf 100644 --- a/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php +++ b/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php @@ -4,12 +4,12 @@ use Drupal\common\Contracts\IdGeneratorInterface; -class Sequential implements IdGeneratorInterface -{ - private int $id = 0; - public function generate(): int - { - $this->id++; - return $this->id; - } +class Sequential implements IdGeneratorInterface { + private int $id = 0; + + public function generate(): int { + $this->id++; + return $this->id; + } + } diff --git a/modules/datastore/src/Plugin/QueueWorker/ImportJob.php b/modules/datastore/src/Plugin/QueueWorker/ImportJob.php index b92072ef48..2c5c5c870e 100644 --- a/modules/datastore/src/Plugin/QueueWorker/ImportJob.php +++ b/modules/datastore/src/Plugin/QueueWorker/ImportJob.php @@ -2,7 +2,7 @@ namespace Drupal\datastore\Plugin\QueueWorker; -use Contracts\ParserInterface; +use Drupal\common\Contracts\ParserInterface; use Drupal\common\Storage\DatabaseTableInterface; use Procrastinator\Job\AbstractPersistentJob; use Procrastinator\Result; diff --git a/modules/datastore/src/Service/Factory/ImportFactoryInterface.php b/modules/datastore/src/Service/Factory/ImportFactoryInterface.php index ab38104629..68a1516a55 100644 --- a/modules/datastore/src/Service/Factory/ImportFactoryInterface.php +++ b/modules/datastore/src/Service/Factory/ImportFactoryInterface.php @@ -2,7 +2,7 @@ namespace Drupal\datastore\Service\Factory; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; /** * Interface for datastore import factories. diff --git a/modules/datastore/src/Service/ResourceLocalizer.php b/modules/datastore/src/Service/ResourceLocalizer.php index 351f3f98f1..1d89e2f7cb 100644 --- a/modules/datastore/src/Service/ResourceLocalizer.php +++ b/modules/datastore/src/Service/ResourceLocalizer.php @@ -2,7 +2,7 @@ namespace Drupal\datastore\Service; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\common\DataResource; use Drupal\common\EventDispatcherTrait; use Drupal\common\UrlHostTokenResolver; diff --git a/modules/datastore/src/Storage/DatabaseTableFactory.php b/modules/datastore/src/Storage/DatabaseTableFactory.php index 2ffa5ac67a..b491728e5d 100644 --- a/modules/datastore/src/Storage/DatabaseTableFactory.php +++ b/modules/datastore/src/Storage/DatabaseTableFactory.php @@ -2,7 +2,7 @@ namespace Drupal\datastore\Storage; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Database\Connection; use Psr\Log\LoggerInterface; diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php index b256814ea7..fc54aaf271 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\datastore\Unit\Plugin\QueueWorker; -use Contracts\ParserInterface; +use Drupal\common\Contracts\ParserInterface; use CsvParser\Parser\Csv; -use Contracts\Mock\Storage\Memory; +use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use Drupal\datastore\DatastoreResource; use Drupal\datastore\Plugin\QueueWorker\ImportJob; use Drupal\common\Storage\DatabaseTableInterface; diff --git a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php index 4ddf9ecb9f..5336445638 100644 --- a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php +++ b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\datastore\Unit\Service\Info; -use Contracts\Mock\Storage\Memory; +use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use CsvParser\Parser\Csv; use Drupal\common\FileFetcher\FileFetcherFactory; use Drupal\datastore\DatastoreResource; diff --git a/modules/harvest/src/HarvestService.php b/modules/harvest/src/HarvestService.php index d99bf6f5ed..f71b482f49 100644 --- a/modules/harvest/src/HarvestService.php +++ b/modules/harvest/src/HarvestService.php @@ -2,7 +2,7 @@ namespace Drupal\harvest; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\harvest\Entity\HarvestPlanRepository; use Drupal\harvest\Entity\HarvestRunRepository; diff --git a/modules/harvest/src/Service.php b/modules/harvest/src/Service.php index fd74d4a26c..a194a5390e 100644 --- a/modules/harvest/src/Service.php +++ b/modules/harvest/src/Service.php @@ -2,7 +2,7 @@ namespace Drupal\harvest; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Entity\EntityTypeManager; use Drupal\metastore\MetastoreService; diff --git a/modules/harvest/src/Storage/DatabaseTableFactory.php b/modules/harvest/src/Storage/DatabaseTableFactory.php index 23735027f3..ccc9a12d3a 100644 --- a/modules/harvest/src/Storage/DatabaseTableFactory.php +++ b/modules/harvest/src/Storage/DatabaseTableFactory.php @@ -2,7 +2,7 @@ namespace Drupal\harvest\Storage; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Database\Connection; /** diff --git a/modules/harvest/src/Storage/HarvestHashesDatabaseTableFactory.php b/modules/harvest/src/Storage/HarvestHashesDatabaseTableFactory.php index 6f23008435..d64fd4044c 100644 --- a/modules/harvest/src/Storage/HarvestHashesDatabaseTableFactory.php +++ b/modules/harvest/src/Storage/HarvestHashesDatabaseTableFactory.php @@ -2,7 +2,7 @@ namespace Drupal\harvest\Storage; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; /** diff --git a/modules/harvest/src/Storage/IdGenerator.php b/modules/harvest/src/Storage/IdGenerator.php index 472d5d8460..ce27083467 100644 --- a/modules/harvest/src/Storage/IdGenerator.php +++ b/modules/harvest/src/Storage/IdGenerator.php @@ -2,7 +2,7 @@ namespace Drupal\harvest\Storage; -use Contracts\IdGeneratorInterface; +use Drupal\common\Contracts\IdGeneratorInterface; /** * Extracts identifiers from metastore data objects. diff --git a/modules/harvest/tests/src/Unit/Load/DatasetTest.php b/modules/harvest/tests/src/Unit/Load/DatasetTest.php index 29ca38d3bf..d11c8ed2bb 100644 --- a/modules/harvest/tests/src/Unit/Load/DatasetTest.php +++ b/modules/harvest/tests/src/Unit/Load/DatasetTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\harvest\Unit\Load; -use Contracts\Mock\Storage\Memory; +use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use Drupal\Core\DependencyInjection\Container; use Drupal\harvest\Load\Dataset; use Drupal\metastore\Exception\ExistingObjectException; diff --git a/modules/harvest/tests/src/Unit/WebServiceApiTest.php b/modules/harvest/tests/src/Unit/WebServiceApiTest.php index 3be415088e..fbb554ebe3 100644 --- a/modules/harvest/tests/src/Unit/WebServiceApiTest.php +++ b/modules/harvest/tests/src/Unit/WebServiceApiTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\harvest\Unit; -use Contracts\Mock\Storage\MemoryFactory; +use Drupal\Tests\common\Unit\Mocks\Storage\MemoryFactory; use Drupal\Component\DependencyInjection\Container; use Drupal\Tests\common\Traits\ServiceCheckTrait; use Drupal\harvest\Entity\HarvestPlanRepository; diff --git a/modules/metastore/src/Factory/MetastoreItemFactoryInterface.php b/modules/metastore/src/Factory/MetastoreItemFactoryInterface.php index 5a04bd9cab..e0c4bd87dc 100644 --- a/modules/metastore/src/Factory/MetastoreItemFactoryInterface.php +++ b/modules/metastore/src/Factory/MetastoreItemFactoryInterface.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Factory; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Entity\EntityRepository; use Drupal\Core\Entity\EntityTypeManager; diff --git a/modules/metastore/src/Reference/Dereferencer.php b/modules/metastore/src/Reference/Dereferencer.php index 017e5ab2ee..917ca34721 100644 --- a/modules/metastore/src/Reference/Dereferencer.php +++ b/modules/metastore/src/Reference/Dereferencer.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Reference; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Psr\Log\LoggerInterface; diff --git a/modules/metastore/src/Reference/ReferenceLookup.php b/modules/metastore/src/Reference/ReferenceLookup.php index 20d40e62e2..6e8ceed32c 100644 --- a/modules/metastore/src/Reference/ReferenceLookup.php +++ b/modules/metastore/src/Reference/ReferenceLookup.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Reference; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Extension\ModuleHandlerInterface; diff --git a/modules/metastore/src/Reference/Referencer.php b/modules/metastore/src/Reference/Referencer.php index be56c33f6f..f377c162cc 100644 --- a/modules/metastore/src/Reference/Referencer.php +++ b/modules/metastore/src/Reference/Referencer.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Reference; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\common\DataResource; diff --git a/modules/metastore/src/SchemaRetriever.php b/modules/metastore/src/SchemaRetriever.php index bfb57439d7..59a1b8e0c9 100644 --- a/modules/metastore/src/SchemaRetriever.php +++ b/modules/metastore/src/SchemaRetriever.php @@ -2,7 +2,7 @@ namespace Drupal\metastore; -use Contracts\RetrieverInterface; +use Drupal\common\Contracts\RetrieverInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Extension\ModuleExtensionList; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/modules/metastore/src/Storage/DataFactory.php b/modules/metastore/src/Storage/DataFactory.php index d9b2cdd091..082bbba683 100644 --- a/modules/metastore/src/Storage/DataFactory.php +++ b/modules/metastore/src/Storage/DataFactory.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Storage; -use Contracts\FactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManager; use Psr\Log\LoggerInterface; From 2ad89430255f23981dc46ac95367ffdd260ee9ba Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 1 May 2024 13:14:18 -0400 Subject: [PATCH 03/18] revert for ImportJob --- modules/datastore/src/Plugin/QueueWorker/ImportJob.php | 2 +- .../tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Plugin/QueueWorker/ImportJob.php b/modules/datastore/src/Plugin/QueueWorker/ImportJob.php index 2c5c5c870e..b92072ef48 100644 --- a/modules/datastore/src/Plugin/QueueWorker/ImportJob.php +++ b/modules/datastore/src/Plugin/QueueWorker/ImportJob.php @@ -2,7 +2,7 @@ namespace Drupal\datastore\Plugin\QueueWorker; -use Drupal\common\Contracts\ParserInterface; +use Contracts\ParserInterface; use Drupal\common\Storage\DatabaseTableInterface; use Procrastinator\Job\AbstractPersistentJob; use Procrastinator\Result; diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php index fc54aaf271..7a3a99df31 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\datastore\Unit\Plugin\QueueWorker; -use Drupal\common\Contracts\ParserInterface; +use Contracts\ParserInterface; use CsvParser\Parser\Csv; use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use Drupal\datastore\DatastoreResource; From 0a7c93f8f3c49e0f066ab53f1a6de0c73c16e45c Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 1 May 2024 15:32:05 -0400 Subject: [PATCH 04/18] still some dependencies because of csvparser and filefetcher --- .../common/src/Contracts/BulkRetrieverInterface.php | 11 +++++++++-- modules/common/src/Contracts/BulkStorerInterface.php | 11 +++++++++-- .../common/src/Contracts/ConditionerInterface.php | 5 +++-- modules/common/src/Contracts/CountableInterface.php | 4 ++-- .../common/src/Contracts/IdGeneratorInterface.php | 4 ++-- modules/common/src/Contracts/LimiterInterface.php | 4 ++-- modules/common/src/Contracts/OffsetterInterface.php | 5 +++-- modules/common/src/Contracts/ParserInterface.php | 11 ++++++++--- modules/common/src/Contracts/RemoverInterface.php | 12 +++++++++--- modules/common/src/Contracts/SorterInterface.php | 6 ++++-- 10 files changed, 51 insertions(+), 22 deletions(-) diff --git a/modules/common/src/Contracts/BulkRetrieverInterface.php b/modules/common/src/Contracts/BulkRetrieverInterface.php index 8697d821af..f251c09cff 100644 --- a/modules/common/src/Contracts/BulkRetrieverInterface.php +++ b/modules/common/src/Contracts/BulkRetrieverInterface.php @@ -2,7 +2,14 @@ namespace Drupal\common\Contracts; -use Contracts\BulkRetrieverInterface as ContactsBulkRetrieverInterface; +interface BulkRetrieverInterface { + + /** + * Retrieve all. + * + * @return array + * An array of ids. + */ + public function retrieveAll(): array; -interface BulkRetrieverInterface extends ContactsBulkRetrieverInterface { } diff --git a/modules/common/src/Contracts/BulkStorerInterface.php b/modules/common/src/Contracts/BulkStorerInterface.php index 0de7f5d653..7b23904539 100644 --- a/modules/common/src/Contracts/BulkStorerInterface.php +++ b/modules/common/src/Contracts/BulkStorerInterface.php @@ -2,7 +2,14 @@ namespace Drupal\common\Contracts; -use Contracts\BulkStorerInterface as ContractsBulkStorerInterface; +interface BulkStorerInterface { + + /** + * Store multiple. + * + * @param array $data + * An array of strings to be stored. + */ + public function storeMultiple(array $data); -interface BulkStorerInterface extends ContractsBulkStorerInterface { } diff --git a/modules/common/src/Contracts/ConditionerInterface.php b/modules/common/src/Contracts/ConditionerInterface.php index bdca112971..92497d1448 100644 --- a/modules/common/src/Contracts/ConditionerInterface.php +++ b/modules/common/src/Contracts/ConditionerInterface.php @@ -2,7 +2,8 @@ namespace Drupal\common\Contracts; -use Contracts\ConditionerInterface as ContractsConditionerInterface; +interface ConditionerInterface { + + public function conditionByIsEqualTo(string $property, string $value); -interface ConditionerInterface extends ContractsConditionerInterface { } diff --git a/modules/common/src/Contracts/CountableInterface.php b/modules/common/src/Contracts/CountableInterface.php index 8fc2d5102b..ce693dde2d 100644 --- a/modules/common/src/Contracts/CountableInterface.php +++ b/modules/common/src/Contracts/CountableInterface.php @@ -2,8 +2,8 @@ namespace Drupal\common\Contracts; -use Contracts\CountableInterface as ContractsCountableInterface; +interface CountableInterface { -interface CountableInterface extends ContractsCountableInterface { + public function count(): int; } diff --git a/modules/common/src/Contracts/IdGeneratorInterface.php b/modules/common/src/Contracts/IdGeneratorInterface.php index bec2a42ea6..51ccd9a167 100644 --- a/modules/common/src/Contracts/IdGeneratorInterface.php +++ b/modules/common/src/Contracts/IdGeneratorInterface.php @@ -2,8 +2,8 @@ namespace Drupal\common\Contracts; -use Contracts\IdGeneratorInterface as ContractsIdGeneratorInterface; +interface IdGeneratorInterface { -interface IdGeneratorInterface extends ContractsIdGeneratorInterface { + public function generate(); } diff --git a/modules/common/src/Contracts/LimiterInterface.php b/modules/common/src/Contracts/LimiterInterface.php index 52ccc3afe2..e58ddb2281 100644 --- a/modules/common/src/Contracts/LimiterInterface.php +++ b/modules/common/src/Contracts/LimiterInterface.php @@ -2,8 +2,8 @@ namespace Drupal\common\Contracts; -use Contracts\LimiterInterface as ContractsLimiterInterface; +interface LimiterInterface { -interface LimiterInterface extends ContractsLimiterInterface { + public function limitTo(int $number_of_items); } diff --git a/modules/common/src/Contracts/OffsetterInterface.php b/modules/common/src/Contracts/OffsetterInterface.php index 914913e9ba..1332c0d165 100644 --- a/modules/common/src/Contracts/OffsetterInterface.php +++ b/modules/common/src/Contracts/OffsetterInterface.php @@ -2,7 +2,8 @@ namespace Drupal\common\Contracts; -use Contracts\OffsetterInterface as ContractsOffsetterInterface; +interface OffsetterInterface { + + public function offsetBy(int $offset); -interface OffsetterInterface extends ContractsOffsetterInterface { } diff --git a/modules/common/src/Contracts/ParserInterface.php b/modules/common/src/Contracts/ParserInterface.php index 0455b38b17..e93e844842 100644 --- a/modules/common/src/Contracts/ParserInterface.php +++ b/modules/common/src/Contracts/ParserInterface.php @@ -1,10 +1,15 @@ Date: Fri, 3 May 2024 11:08:43 -0400 Subject: [PATCH 05/18] some failing --- composer.json | 6 +++--- .../common/src/Contracts/FactoryInterface.php | 18 ++++++++++++++++-- .../src/Contracts/HydratableInterface.php | 9 --------- .../src/Plugin/QueueWorker/ImportJob.php | 8 ++++---- .../Unit/Plugin/QueueWorker/ImportJobTest.php | 10 ++++++---- .../HarvestHashesEntityDatabaseTable.php | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) delete mode 100644 modules/common/src/Contracts/HydratableInterface.php diff --git a/composer.json b/composer.json index da65636d0e..61d4f44d3e 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ "ezyang/htmlpurifier" : "^4.11", "fmizzell/maquina": "^1.1.1", "getdkan/contracts": "^1.1.2", - "getdkan/csv-parser": "^1.3.1", - "getdkan/file-fetcher" : "^5.0.3", + "getdkan/csv-parser": "dev-no-contracts", + "getdkan/file-fetcher" : "dev-no-contracts", "getdkan/harvest": "^1.0.3", - "getdkan/procrastinator": "^5.0.0", + "getdkan/procrastinator": "dev-no-contracts", "getdkan/rooted-json-data": "^0.2.1", "guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5", "ilbee/csv-response": "^1.2.0", diff --git a/modules/common/src/Contracts/FactoryInterface.php b/modules/common/src/Contracts/FactoryInterface.php index 6e93094724..23484685c2 100644 --- a/modules/common/src/Contracts/FactoryInterface.php +++ b/modules/common/src/Contracts/FactoryInterface.php @@ -2,8 +2,22 @@ namespace Drupal\common\Contracts; -use Contracts\FactoryInterface as ContractsFactoryInterface; +/** + * use Contracts\FactoryInterface as ContractsFactoryInterface; + */ +interface FactoryInterface { -interface FactoryInterface extends ContractsFactoryInterface { + /** + * Construct or deliver an object of the expected class. + * + * For example a MemoryStorage factory should return + * MemoryStorage objects. + * + * @param string $identifier + * Some way to discern between different instances of a class. + * + * @return mixed + */ + public function getInstance(string $identifier, array $config = []); } diff --git a/modules/common/src/Contracts/HydratableInterface.php b/modules/common/src/Contracts/HydratableInterface.php deleted file mode 100644 index 76f1d796da..0000000000 --- a/modules/common/src/Contracts/HydratableInterface.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Sat, 4 May 2024 10:02:51 -0600 Subject: [PATCH 06/18] phase 1 complete... --- modules/common/src/Contracts/FactoryInterface.php | 3 --- modules/common/src/Contracts/RetrieverInterface.php | 9 +++++++++ modules/common/src/Contracts/StorerInterface.php | 9 +++++++++ .../src/Controller/MetastoreRevisionController.php | 8 ++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/common/src/Contracts/FactoryInterface.php b/modules/common/src/Contracts/FactoryInterface.php index 23484685c2..6e07d925ba 100644 --- a/modules/common/src/Contracts/FactoryInterface.php +++ b/modules/common/src/Contracts/FactoryInterface.php @@ -2,9 +2,6 @@ namespace Drupal\common\Contracts; -/** - * use Contracts\FactoryInterface as ContractsFactoryInterface; - */ interface FactoryInterface { /** diff --git a/modules/common/src/Contracts/RetrieverInterface.php b/modules/common/src/Contracts/RetrieverInterface.php index eccd60266f..1f41379702 100644 --- a/modules/common/src/Contracts/RetrieverInterface.php +++ b/modules/common/src/Contracts/RetrieverInterface.php @@ -4,6 +4,15 @@ use Contracts\RetrieverInterface as ContractsRetrieverInterface; +/** + * {@inheritDoc} + * + * @todo For now, this interface must inherit from getdkan/contracts because + * it is used by a number of other packages, with no clear point of + * encapsulation. Within getdkan/dkan we should use this sub-interface. + * + * @see \Procrastinator\Job\AbstractPersistentJob::get() + */ interface RetrieverInterface extends ContractsRetrieverInterface { } diff --git a/modules/common/src/Contracts/StorerInterface.php b/modules/common/src/Contracts/StorerInterface.php index 2f59818759..2a7b721daa 100644 --- a/modules/common/src/Contracts/StorerInterface.php +++ b/modules/common/src/Contracts/StorerInterface.php @@ -4,6 +4,15 @@ use Contracts\StorerInterface as ContractsStorerInterface; +/** + * {@inheritDoc} + * + * @todo For now, this interface must inherit from getdkan/contracts because + * it is used by a number of other packages, with no clear point of + * encapsulation. Within getdkan/dkan we should use this sub-interface. + * + * @see \Procrastinator\Job\AbstractPersistentJob::get() + */ interface StorerInterface extends ContractsStorerInterface { } diff --git a/modules/metastore/src/Controller/MetastoreRevisionController.php b/modules/metastore/src/Controller/MetastoreRevisionController.php index cc06ae47ab..9c072fd37f 100644 --- a/modules/metastore/src/Controller/MetastoreRevisionController.php +++ b/modules/metastore/src/Controller/MetastoreRevisionController.php @@ -2,7 +2,7 @@ namespace Drupal\metastore\Controller; -use Contracts\FactoryInterface as ContractsFactoryInterface; +use Drupal\common\Contracts\FactoryInterface; use Drupal\common\JsonResponseTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; @@ -51,9 +51,9 @@ class MetastoreRevisionController implements ContainerInjectionInterface { /** * Storage factory service. * - * @var \Contracts\FactoryInterface + * @var \Drupal\common\Contracts\FactoryInterface */ - private ContractsFactoryInterface $storageFactory; + private FactoryInterface $storageFactory; /** * Inherited. @@ -72,7 +72,7 @@ public static function create(ContainerInterface $container) { */ public function __construct( MetastoreApiResponse $apiResponse, - ContractsFactoryInterface $storageFactory + FactoryInterface $storageFactory ) { $this->apiResponse = $apiResponse; $this->storageFactory = $storageFactory; From a70de0641c0f72ec06faeb801f11076149e73d30 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sat, 4 May 2024 10:51:34 -0600 Subject: [PATCH 07/18] docs, return hints --- .../src/Contracts/BulkRetrieverInterface.php | 3 +++ .../src/Contracts/BulkStorerInterface.php | 3 +++ .../src/Contracts/ConditionerInterface.php | 13 +++++++++++- .../src/Contracts/CountableInterface.php | 11 ++++++++++ .../common/src/Contracts/FactoryInterface.php | 6 ++++++ .../src/Contracts/IdGeneratorInterface.php | 9 +++++++++ .../common/src/Contracts/LimiterInterface.php | 11 +++++++++- .../src/Contracts/OffsetterInterface.php | 11 +++++++++- .../common/src/Contracts/ParserInterface.php | 15 -------------- .../common/src/Contracts/RemoverInterface.php | 8 +++++++- .../common/src/Contracts/SorterInterface.php | 19 ++++++++++++++++-- .../src/Storage/AbstractDatabaseTable.php | 4 +--- modules/common/src/Storage/Query.php | 20 +++++++++---------- 13 files changed, 99 insertions(+), 34 deletions(-) delete mode 100644 modules/common/src/Contracts/ParserInterface.php diff --git a/modules/common/src/Contracts/BulkRetrieverInterface.php b/modules/common/src/Contracts/BulkRetrieverInterface.php index f251c09cff..17ebfeedd4 100644 --- a/modules/common/src/Contracts/BulkRetrieverInterface.php +++ b/modules/common/src/Contracts/BulkRetrieverInterface.php @@ -2,6 +2,9 @@ namespace Drupal\common\Contracts; +/** + * Interface for bulk retrieval of all records. + */ interface BulkRetrieverInterface { /** diff --git a/modules/common/src/Contracts/BulkStorerInterface.php b/modules/common/src/Contracts/BulkStorerInterface.php index 7b23904539..5393736b51 100644 --- a/modules/common/src/Contracts/BulkStorerInterface.php +++ b/modules/common/src/Contracts/BulkStorerInterface.php @@ -2,6 +2,9 @@ namespace Drupal\common\Contracts; +/** + * Interface for storage of multiple records. + */ interface BulkStorerInterface { /** diff --git a/modules/common/src/Contracts/ConditionerInterface.php b/modules/common/src/Contracts/ConditionerInterface.php index 92497d1448..4b03471e05 100644 --- a/modules/common/src/Contracts/ConditionerInterface.php +++ b/modules/common/src/Contracts/ConditionerInterface.php @@ -2,8 +2,19 @@ namespace Drupal\common\Contracts; +/** + * Interface for conditional query. + */ interface ConditionerInterface { - public function conditionByIsEqualTo(string $property, string $value); + /** + * Retrieve only objects with properties of certain values. + * + * @param string $property + * Property to filter on. + * @param string $value + * Property value to filter against. + */ + public function conditionByIsEqualTo(string $property, string $value): void; } diff --git a/modules/common/src/Contracts/CountableInterface.php b/modules/common/src/Contracts/CountableInterface.php index ce693dde2d..25fcfff225 100644 --- a/modules/common/src/Contracts/CountableInterface.php +++ b/modules/common/src/Contracts/CountableInterface.php @@ -2,8 +2,19 @@ namespace Drupal\common\Contracts; +/** + * Interface for countable objects. + * + * @todo Replace with \Countable? + */ interface CountableInterface { + /** + * Count elements of an object. + * + * @return int + * Number of elements represented by this object. + */ public function count(): int; } diff --git a/modules/common/src/Contracts/FactoryInterface.php b/modules/common/src/Contracts/FactoryInterface.php index 6e07d925ba..c536f1eef7 100644 --- a/modules/common/src/Contracts/FactoryInterface.php +++ b/modules/common/src/Contracts/FactoryInterface.php @@ -2,6 +2,9 @@ namespace Drupal\common\Contracts; +/** + * Interface for the factory pattern. + */ interface FactoryInterface { /** @@ -12,8 +15,11 @@ interface FactoryInterface { * * @param string $identifier * Some way to discern between different instances of a class. + * @param array $config + * (Optional) Arbitrary configuration passed in to the factory. * * @return mixed + * The desired instance. Generally this wil be an object. */ public function getInstance(string $identifier, array $config = []); diff --git a/modules/common/src/Contracts/IdGeneratorInterface.php b/modules/common/src/Contracts/IdGeneratorInterface.php index 51ccd9a167..1897fd945f 100644 --- a/modules/common/src/Contracts/IdGeneratorInterface.php +++ b/modules/common/src/Contracts/IdGeneratorInterface.php @@ -2,8 +2,17 @@ namespace Drupal\common\Contracts; +/** + * Interface for generating an identifier. + */ interface IdGeneratorInterface { + /** + * Generate or glean an identifier. + * + * @return mixed + * An identifier. + */ public function generate(); } diff --git a/modules/common/src/Contracts/LimiterInterface.php b/modules/common/src/Contracts/LimiterInterface.php index e58ddb2281..c48dcaa7cf 100644 --- a/modules/common/src/Contracts/LimiterInterface.php +++ b/modules/common/src/Contracts/LimiterInterface.php @@ -2,8 +2,17 @@ namespace Drupal\common\Contracts; +/** + * Interface to add a limit to queries. + */ interface LimiterInterface { - public function limitTo(int $number_of_items); + /** + * Limit the number of records returned on a query. + * + * @param int $number_of_items + * The number of items to limit to. + */ + public function limitTo(int $number_of_items): void; } diff --git a/modules/common/src/Contracts/OffsetterInterface.php b/modules/common/src/Contracts/OffsetterInterface.php index 1332c0d165..d8defb9c87 100644 --- a/modules/common/src/Contracts/OffsetterInterface.php +++ b/modules/common/src/Contracts/OffsetterInterface.php @@ -2,8 +2,17 @@ namespace Drupal\common\Contracts; +/** + * Interface to offset query results. + */ interface OffsetterInterface { - public function offsetBy(int $offset); + /** + * Set the number of records to offset by. + * + * @param int $offset + * The number of records to offset by. + */ + public function offsetBy(int $offset): void; } diff --git a/modules/common/src/Contracts/ParserInterface.php b/modules/common/src/Contracts/ParserInterface.php deleted file mode 100644 index e93e844842..0000000000 --- a/modules/common/src/Contracts/ParserInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -getTableName(); diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index 477e773a69..90aafcfaad 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -11,10 +11,10 @@ * DKAN API Query data object. */ class Query implements - SorterInterface, - ConditionerInterface, - OffsetterInterface, - LimiterInterface { + SorterInterface, + ConditionerInterface, + OffsetterInterface, + LimiterInterface { /** * The collection of records (usually, a database table) to query against. @@ -135,9 +135,9 @@ public function filterByProperty($property) { * @param string $value * Property value to filter against. * @param bool $case - * Case sensitive filter? + * Case-sensitive filter? */ - public function conditionByIsEqualTo(string $property, string $value, bool $case = FALSE) { + public function conditionByIsEqualTo(string $property, string $value, bool $case = FALSE): void { $this->conditions[] = (object) [ 'property' => $property, 'value' => $value, @@ -151,7 +151,7 @@ public function conditionByIsEqualTo(string $property, string $value, bool $case * @param int $number_of_items * Number of items. */ - public function limitTo(int $number_of_items) { + public function limitTo(int $number_of_items): void { $this->limit = $number_of_items; } @@ -161,7 +161,7 @@ public function limitTo(int $number_of_items) { * @param int $offset * Number of records to offset by before retrieving. */ - public function offsetBy(int $offset) { + public function offsetBy(int $offset): void { $this->offset = $offset; } @@ -171,7 +171,7 @@ public function offsetBy(int $offset) { * @param string $property * Property to sort by in ascending order. */ - public function sortByAscending(string $property) { + public function sortByAscending(string $property): void { $this->sorts[] = (object) [ "property" => $property, "order" => "asc", @@ -184,7 +184,7 @@ public function sortByAscending(string $property) { * @param string $property * Property to sort by in descending order. */ - public function sortByDescending(string $property) { + public function sortByDescending(string $property): void { $this->sorts[] = (object) [ "property" => $property, "order" => "desc", From 756ca692f8bd585aab0851b5212b52525d8ac64f Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sat, 4 May 2024 22:22:35 -0600 Subject: [PATCH 08/18] updated composer.json --- composer.json | 4 ++-- phpunit.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 61d4f44d3e..58cfcb1969 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,10 @@ "ext-json": "*", "ezyang/htmlpurifier" : "^4.11", "fmizzell/maquina": "^1.1.1", - "getdkan/contracts": "^1.1.2", + "getdkan/contracts": "dev-no-contracts", "getdkan/csv-parser": "dev-no-contracts", "getdkan/file-fetcher" : "dev-no-contracts", - "getdkan/harvest": "^1.0.3", + "getdkan/harvest": "dev-no-contracts", "getdkan/procrastinator": "dev-no-contracts", "getdkan/rooted-json-data": "^0.2.1", "guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5", diff --git a/phpunit.xml b/phpunit.xml index 13dca2b74f..9d6c0e45bd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -63,6 +63,6 @@ - + From 3d304646fa7c2844ac338f36d017c7613154f4ef Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sun, 5 May 2024 10:38:59 -0600 Subject: [PATCH 09/18] turn off deprecation fails --- phpunit.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 9d6c0e45bd..5dc09e73a4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -63,6 +63,7 @@ - + + From c025b0a2b1fe4b5dda3484f73f9a1b0cfd6f78e5 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sun, 5 May 2024 10:53:44 -0600 Subject: [PATCH 10/18] minor --- modules/common/src/Storage/AbstractDatabaseTable.php | 4 +++- modules/common/src/Storage/Query.php | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 980f0eb89f..62e53a6715 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -190,7 +190,9 @@ protected function getNonSerialFields() { } /** - * {@inheritDoc} + * Inherited. + * + * @inheritdoc */ public function remove(string $id) { $tableName = $this->getTableName(); diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index 90aafcfaad..37f776c963 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -2,19 +2,19 @@ namespace Drupal\common\Storage; -use Drupal\common\Contracts\SorterInterface; use Drupal\common\Contracts\ConditionerInterface; -use Drupal\common\Contracts\OffsetterInterface; use Drupal\common\Contracts\LimiterInterface; +use Drupal\common\Contracts\OffsetterInterface; +use Drupal\common\Contracts\SorterInterface; /** * DKAN API Query data object. */ class Query implements - SorterInterface, ConditionerInterface, + LimiterInterface, OffsetterInterface, - LimiterInterface { + SorterInterface { /** * The collection of records (usually, a database table) to query against. From 5d8b06d930a3981ef2ba8212af6578839492136d Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sun, 5 May 2024 11:07:03 -0600 Subject: [PATCH 11/18] replaces CountableInterface with \Countable, removes unused imports --- .../src/Contracts/CountableInterface.php | 20 ------------------- .../src/Storage/DatabaseTableInterface.php | 13 ++++++++---- modules/common/tests/src/Traits/CleanUp.php | 1 - .../src/Unit/DkanApiDocsGeneratorTest.php | 1 - .../Unit/DataDictionaryWidgetBuildTest.php | 3 --- .../Service/Info/ImportInfoListTest.php | 1 - .../src/Unit/Service/Info/ImportInfoTest.php | 8 -------- .../Unit/Service/ResourceLocalizerTest.php | 1 - .../Unit/Storage/DatabaseTableFactoryTest.php | 1 - .../search_api/datasource/DkanDatasetTest.php | 1 - .../Unit/Commands/MetastoreCommandsTest.php | 1 - .../src/Unit/MetastoreSubscriberTest.php | 1 - rector.php | 15 +++++++------- 13 files changed, 16 insertions(+), 51 deletions(-) delete mode 100644 modules/common/src/Contracts/CountableInterface.php diff --git a/modules/common/src/Contracts/CountableInterface.php b/modules/common/src/Contracts/CountableInterface.php deleted file mode 100644 index 25fcfff225..0000000000 --- a/modules/common/src/Contracts/CountableInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -fileExtensions([ 'php', 'module', 'theme', 'install', 'profile', 'inc', 'engine', ]); + $rectorConfig->removeUnusedImports(); $rectorConfig->importNames(TRUE, FALSE); $rectorConfig->importShortClasses(FALSE); }; From 8d9bb3fabaeeb1d2c55c8d932d33f8802fcc7c48 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 6 May 2024 12:18:41 -0600 Subject: [PATCH 12/18] todo --- modules/common/src/Storage/Query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index 37f776c963..fe7cc3e4eb 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -9,6 +9,9 @@ /** * DKAN API Query data object. + * + * @todo Should we remove these external interfaces and only declare + * QueryInterface? */ class Query implements ConditionerInterface, From 05b908865734c972f3a68a7de2d0ada3b1527594 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 8 May 2024 11:21:55 -0700 Subject: [PATCH 13/18] indentation --- .../common/src/Storage/DatabaseTableInterface.php | 12 ++++++------ modules/common/src/Storage/Query.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/common/src/Storage/DatabaseTableInterface.php b/modules/common/src/Storage/DatabaseTableInterface.php index 0991b7eb82..e1173cb502 100644 --- a/modules/common/src/Storage/DatabaseTableInterface.php +++ b/modules/common/src/Storage/DatabaseTableInterface.php @@ -12,12 +12,12 @@ * Databaset table interface. */ interface DatabaseTableInterface extends - BulkRetrieverInterface, - BulkStorerInterface, - \Countable, - RemoverInterface, - RetrieverInterface, - StorerInterface { + BulkRetrieverInterface, + BulkStorerInterface, + \Countable, + RemoverInterface, + RetrieverInterface, + StorerInterface { /** * Remove the table from the database. diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index fe7cc3e4eb..07555722ed 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -14,10 +14,10 @@ * QueryInterface? */ class Query implements - ConditionerInterface, - LimiterInterface, - OffsetterInterface, - SorterInterface { + ConditionerInterface, + LimiterInterface, + OffsetterInterface, + SorterInterface { /** * The collection of records (usually, a database table) to query against. From 088039e4d53508df3d718654c1a938b84c96a8b9 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 8 May 2024 14:36:38 -0700 Subject: [PATCH 14/18] test in proper namespace --- .../common/tests/src/Unit/{ => Contracts}/SequentialTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/common/tests/src/Unit/{ => Contracts}/SequentialTest.php (90%) diff --git a/modules/common/tests/src/Unit/SequentialTest.php b/modules/common/tests/src/Unit/Contracts/SequentialTest.php similarity index 90% rename from modules/common/tests/src/Unit/SequentialTest.php rename to modules/common/tests/src/Unit/Contracts/SequentialTest.php index 94434ef432..061ab34587 100644 --- a/modules/common/tests/src/Unit/SequentialTest.php +++ b/modules/common/tests/src/Unit/Contracts/SequentialTest.php @@ -1,6 +1,6 @@ Date: Mon, 13 May 2024 11:19:55 -0700 Subject: [PATCH 15/18] revert contracts added to common --- .../src/Contracts/BulkRetrieverInterface.php | 18 ------------- .../src/Contracts/BulkStorerInterface.php | 18 ------------- .../src/Contracts/ConditionerInterface.php | 20 -------------- .../common/src/Contracts/FactoryInterface.php | 26 ------------------- .../src/Contracts/IdGeneratorInterface.php | 18 ------------- .../common/src/Contracts/LimiterInterface.php | 18 ------------- .../src/Contracts/OffsetterInterface.php | 18 ------------- .../common/src/Contracts/RemoverInterface.php | 21 --------------- .../src/Contracts/RetrieverInterface.php | 18 ------------- .../common/src/Contracts/SorterInterface.php | 26 ------------------- .../common/src/Contracts/StorerInterface.php | 18 ------------- .../src/FileFetcher/FileFetcherFactory.php | 2 +- .../src/Storage/DatabaseTableInterface.php | 10 +++---- modules/common/src/Storage/Query.php | 8 +++--- .../src/Storage/StorageFactoryInterface.php | 2 +- .../FileFetcher/CustomFileFetcherFactory.php | 2 +- .../src/Unit/Mocks/IdGenerator/Sequential.php | 2 +- .../Unit/Mocks/Storage/JsonObjectMemory.php | 8 +++--- .../tests/src/Unit/Mocks/Storage/Memory.php | 6 ++--- .../src/Unit/Mocks/Storage/MemoryFactory.php | 2 +- .../Factory/ImportFactoryInterface.php | 2 +- .../src/Service/ResourceLocalizer.php | 2 +- .../src/Storage/DatabaseTableFactory.php | 2 +- modules/harvest/src/HarvestService.php | 2 +- modules/harvest/src/Service.php | 2 +- .../src/Storage/DatabaseTableFactory.php | 2 +- .../HarvestHashesDatabaseTableFactory.php | 2 +- modules/harvest/src/Storage/IdGenerator.php | 2 +- .../MetastoreRevisionController.php | 4 +-- .../Factory/MetastoreItemFactoryInterface.php | 2 +- .../metastore/src/Reference/Dereferencer.php | 2 +- .../src/Reference/ReferenceLookup.php | 2 +- .../metastore/src/Reference/Referencer.php | 2 +- modules/metastore/src/SchemaRetriever.php | 2 +- modules/metastore/src/Storage/DataFactory.php | 2 +- 35 files changed, 37 insertions(+), 256 deletions(-) delete mode 100644 modules/common/src/Contracts/BulkRetrieverInterface.php delete mode 100644 modules/common/src/Contracts/BulkStorerInterface.php delete mode 100644 modules/common/src/Contracts/ConditionerInterface.php delete mode 100644 modules/common/src/Contracts/FactoryInterface.php delete mode 100644 modules/common/src/Contracts/IdGeneratorInterface.php delete mode 100644 modules/common/src/Contracts/LimiterInterface.php delete mode 100644 modules/common/src/Contracts/OffsetterInterface.php delete mode 100644 modules/common/src/Contracts/RemoverInterface.php delete mode 100644 modules/common/src/Contracts/RetrieverInterface.php delete mode 100644 modules/common/src/Contracts/SorterInterface.php delete mode 100644 modules/common/src/Contracts/StorerInterface.php diff --git a/modules/common/src/Contracts/BulkRetrieverInterface.php b/modules/common/src/Contracts/BulkRetrieverInterface.php deleted file mode 100644 index 17ebfeedd4..0000000000 --- a/modules/common/src/Contracts/BulkRetrieverInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Mon, 13 May 2024 11:59:00 -0700 Subject: [PATCH 16/18] some reverts, some tweaks --- modules/common/tests/src/Unit/Storage/JobStoreTest.php | 4 ++-- .../tests/src/Unit/Service/Info/ImportInfoTest.php | 10 +++++++++- modules/harvest/tests/src/Unit/Load/DatasetTest.php | 2 +- modules/harvest/tests/src/Unit/WebServiceApiTest.php | 2 +- .../Plugin/search_api/datasource/DkanDatasetTest.php | 1 + .../src/Controller/MetastoreRevisionController.php | 4 ++-- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/JobStoreTest.php b/modules/common/tests/src/Unit/Storage/JobStoreTest.php index 3aa46130c0..21d9013b24 100644 --- a/modules/common/tests/src/Unit/Storage/JobStoreTest.php +++ b/modules/common/tests/src/Unit/Storage/JobStoreTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\common\Unit\Storage; -use Drupal\common\Storage\JobStore; +use Contracts\Mock\Storage\Memory; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\Delete; use Drupal\Core\Database\Query\Select; @@ -10,7 +10,7 @@ use Drupal\Core\Database\Schema; use Drupal\Core\Database\StatementWrapper; use Drupal\Core\Database\StatementWrapperIterator; -use Drupal\Tests\common\Unit\Mocks\Storage\Memory; +use Drupal\common\Storage\JobStore; use FileFetcher\FileFetcher; use MockChain\Chain; use MockChain\Sequence; diff --git a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php index b2acabbde3..4ddf9ecb9f 100644 --- a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php +++ b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php @@ -2,15 +2,23 @@ namespace Drupal\Tests\datastore\Unit\Service\Info; -use Drupal\Tests\common\Unit\Mocks\Storage\Memory; +use Contracts\Mock\Storage\Memory; use CsvParser\Parser\Csv; +use Drupal\common\FileFetcher\FileFetcherFactory; use Drupal\datastore\DatastoreResource; use Drupal\datastore\Plugin\QueueWorker\ImportJob; +use Drupal\common\Storage\JobStore; +use Drupal\common\Storage\JobStoreFactory; use Drupal\datastore\Service\Info\ImportInfo; +use Drupal\datastore\Service\Info\ImportInfoList; use Drupal\Tests\datastore\Unit\Plugin\QueueWorker\TestMemStorage; use FileFetcher\FileFetcher; +use MockChain\Chain; +use MockChain\Options; use PHPUnit\Framework\TestCase; use Procrastinator\Job\Job; +use Procrastinator\Result; +use Symfony\Component\DependencyInjection\Container; /** * @coversDefaultClass \Drupal\datastore\Service\Info\ImportInfo diff --git a/modules/harvest/tests/src/Unit/Load/DatasetTest.php b/modules/harvest/tests/src/Unit/Load/DatasetTest.php index d11c8ed2bb..29ca38d3bf 100644 --- a/modules/harvest/tests/src/Unit/Load/DatasetTest.php +++ b/modules/harvest/tests/src/Unit/Load/DatasetTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\harvest\Unit\Load; -use Drupal\Tests\common\Unit\Mocks\Storage\Memory; +use Contracts\Mock\Storage\Memory; use Drupal\Core\DependencyInjection\Container; use Drupal\harvest\Load\Dataset; use Drupal\metastore\Exception\ExistingObjectException; diff --git a/modules/harvest/tests/src/Unit/WebServiceApiTest.php b/modules/harvest/tests/src/Unit/WebServiceApiTest.php index fbb554ebe3..3be415088e 100644 --- a/modules/harvest/tests/src/Unit/WebServiceApiTest.php +++ b/modules/harvest/tests/src/Unit/WebServiceApiTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\harvest\Unit; -use Drupal\Tests\common\Unit\Mocks\Storage\MemoryFactory; +use Contracts\Mock\Storage\MemoryFactory; use Drupal\Component\DependencyInjection\Container; use Drupal\Tests\common\Traits\ServiceCheckTrait; use Drupal\harvest\Entity\HarvestPlanRepository; diff --git a/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php b/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php index 0f1da92eb5..e8f833fbc6 100644 --- a/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php +++ b/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\metastore_search\Unit\Plugin\search_api\datasource; +use _PHPStan_7d6f0f6a4\Psr\Container\ContainerInterface; use Drupal\Core\DependencyInjection\Container; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManager; diff --git a/modules/metastore/src/Controller/MetastoreRevisionController.php b/modules/metastore/src/Controller/MetastoreRevisionController.php index 7e3c101e4a..9988eab082 100644 --- a/modules/metastore/src/Controller/MetastoreRevisionController.php +++ b/modules/metastore/src/Controller/MetastoreRevisionController.php @@ -3,13 +3,13 @@ namespace Drupal\metastore\Controller; use Contracts\FactoryInterface; -use Drupal\common\JsonResponseTrait; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\RevisionLogInterface; +use Drupal\common\JsonResponseTrait; use Drupal\metastore\Exception\MissingObjectException; use Drupal\metastore\MetastoreApiResponse; use Drupal\metastore\Storage\MetastoreEntityStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** From 3a5d4aabbc30f8e97315573915cfd4715312e4b6 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 13 May 2024 12:18:50 -0700 Subject: [PATCH 17/18] more reverts, remove unused uses --- modules/common/src/Storage/Query.php | 10 +- .../src/Unit/Contracts/SequentialTest.php | 24 ---- modules/common/tests/src/Unit/MemoryTest.php | 132 ------------------ .../src/Unit/Mocks/IdGenerator/Sequential.php | 15 -- .../Unit/Mocks/Storage/JsonObjectMemory.php | 121 ---------------- .../tests/src/Unit/Mocks/Storage/Memory.php | 44 ------ .../src/Unit/Mocks/Storage/MemoryFactory.php | 18 --- .../data_dictionary_widget.module | 4 +- .../Unit/Plugin/QueueWorker/ImportJobTest.php | 2 +- .../src/Unit/Service/Info/ImportInfoTest.php | 8 -- .../search_api/datasource/DkanDatasetTest.php | 1 - phpunit.xml | 4 +- rector.php | 49 ++----- 13 files changed, 18 insertions(+), 414 deletions(-) delete mode 100644 modules/common/tests/src/Unit/Contracts/SequentialTest.php delete mode 100644 modules/common/tests/src/Unit/MemoryTest.php delete mode 100644 modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php delete mode 100644 modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php delete mode 100644 modules/common/tests/src/Unit/Mocks/Storage/Memory.php delete mode 100644 modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index 9c32f424f9..a1f2bff459 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -140,7 +140,7 @@ public function filterByProperty($property) { * @param bool $case * Case-sensitive filter? */ - public function conditionByIsEqualTo(string $property, string $value, bool $case = FALSE): void { + public function conditionByIsEqualTo(string $property, string $value, bool $case = FALSE) { $this->conditions[] = (object) [ 'property' => $property, 'value' => $value, @@ -154,7 +154,7 @@ public function conditionByIsEqualTo(string $property, string $value, bool $case * @param int $number_of_items * Number of items. */ - public function limitTo(int $number_of_items): void { + public function limitTo(int $number_of_items) { $this->limit = $number_of_items; } @@ -164,7 +164,7 @@ public function limitTo(int $number_of_items): void { * @param int $offset * Number of records to offset by before retrieving. */ - public function offsetBy(int $offset): void { + public function offsetBy(int $offset) { $this->offset = $offset; } @@ -174,7 +174,7 @@ public function offsetBy(int $offset): void { * @param string $property * Property to sort by in ascending order. */ - public function sortByAscending(string $property): void { + public function sortByAscending(string $property) { $this->sorts[] = (object) [ "property" => $property, "order" => "asc", @@ -187,7 +187,7 @@ public function sortByAscending(string $property): void { * @param string $property * Property to sort by in descending order. */ - public function sortByDescending(string $property): void { + public function sortByDescending(string $property) { $this->sorts[] = (object) [ "property" => $property, "order" => "desc", diff --git a/modules/common/tests/src/Unit/Contracts/SequentialTest.php b/modules/common/tests/src/Unit/Contracts/SequentialTest.php deleted file mode 100644 index 061ab34587..0000000000 --- a/modules/common/tests/src/Unit/Contracts/SequentialTest.php +++ /dev/null @@ -1,24 +0,0 @@ -generate(); - $this->assertEquals(1, $id1); - $id2 = $generator->generate(); - $this->assertEquals(2, $id2); - } - -} diff --git a/modules/common/tests/src/Unit/MemoryTest.php b/modules/common/tests/src/Unit/MemoryTest.php deleted file mode 100644 index 1fc5dd3d62..0000000000 --- a/modules/common/tests/src/Unit/MemoryTest.php +++ /dev/null @@ -1,132 +0,0 @@ -getInstance('store'); - - $this->expectExceptionMessage('An id is required to store the data.'); - $store->store('Data'); - } - - public function testStorageMemory(): void { - $store = new Memory(); - - $store->store('Data', '1'); - $this->assertEquals('Data', $store->retrieve('1')); - - $store->store('Data 2', '2'); - $this->assertEquals('Data 2', $store->retrieve('2')); - - $all = $store->retrieveAll(); - $this->assertTrue(is_array($all)); - - $this->assertEquals('Data', $all['1']); - - $store->remove('1'); - - $this->assertNull($store->retrieve('1')); - } - - public function testStorageJsonObjectMemory(): void { - $objects = []; - $objects[] = << $object) { - $store->store($object, "{$index}"); - } - - $this->assertEquals(4, count($store->retrieveAll())); - - $store->offsetBy(1); - $store->limitTo(1); - - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[1], $string); - } - - $store->offsetBy(3); - - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[3], $string); - } - - $store->limitTo(1); - - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[0], $string); - } - - $store->sortByAscending('first'); - - $order = [0, 2, 3, 1]; - $order_index = 0; - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[$order[$order_index]], $string); - $order_index++; - } - - $store->sortByDescending('first'); - - $order = [1, 3, 2, 0]; - $order_index = 0; - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[$order[$order_index]], $string); - $order_index++; - } - - $store->conditionByIsEqualTo('first', 'Gerardo'); - - $order = [0, 2]; - $order_index = 0; - foreach ($store->retrieveAll() as $string) { - $this->assertEquals($objects[$order[$order_index]], $string); - $order_index++; - } - } - -} diff --git a/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php b/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php deleted file mode 100644 index fc1a7b66ac..0000000000 --- a/modules/common/tests/src/Unit/Mocks/IdGenerator/Sequential.php +++ /dev/null @@ -1,15 +0,0 @@ -id++; - return $this->id; - } - -} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php b/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php deleted file mode 100644 index 663e3839e3..0000000000 --- a/modules/common/tests/src/Unit/Mocks/Storage/JsonObjectMemory.php +++ /dev/null @@ -1,121 +0,0 @@ - [], - 'descend' => [], - ]; - - private array $conditions = []; - - public function retrieveAll(): array { - $results = parent::retrieveAll(); - $results = $this->applyFilters($results); - $this->resetFilters(); - return $results; - } - - public function store($data, string $id = NULL): string { - $this->validate($data); - return parent::store($data, $id); - } - - public function conditionByIsEqualTo(string $property, string $value): void { - $this->conditions[$property][] = $value; - } - - public function limitTo(int $number_of_items): void { - $this->limit = $number_of_items; - } - - public function offsetBy(int $offset): void { - $this->offset = $offset; - } - - public function sortByAscending(string $property): void { - $this->sorts['ascend'][] = $property; - } - - public function sortByDescending(string $property): void { - $this->sorts['descend'][] = $property; - } - - private function applyFilters(array $results) { - - if (!empty($this->conditions)) { - $results2 = []; - - foreach ($this->conditions as $property => $values) { - foreach ($values as $value) { - foreach ($results as $key => $result) { - $obj = json_decode($result); - if ($obj->{$property} == $value) { - $results2[$key] = $result; - } - } - } - } - - $results = $results2; - } - - foreach ($this->sorts as $type => $properties) { - foreach ($properties as $property) { - usort($results, fn($a, $b) => $this->compare($a, $b, $property)); - - if ($type == 'descend') { - $results = array_reverse($results); - } - } - } - - if ($this->limit > 0 || $this->offset > 0) { - $results = array_slice($results, $this->offset, $this->limit); - } - - return $results; - } - - private function resetFilters(): void { - $this->offset = 0; - $this->limit = 0; - - $this->sorts = [ - 'ascend' => [], - 'descend' => [], - ]; - - $this->conditions = []; - } - - private function validate(string $data) { - $decoded = json_decode($data); - if (is_null($decoded)) { - throw new \Exception('Only JSON strings can be stored'); - } - if (!is_object($decoded)) { - throw new \Exception('Only strings with JSON objects can be stored'); - } - } - - private function compare($a, $b, $property): int { - $a = json_decode($a); - $b = json_decode($b); - return strnatcmp($a->{$property}, $b->{$property}); - } - -} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/Memory.php b/modules/common/tests/src/Unit/Mocks/Storage/Memory.php deleted file mode 100644 index 1285b7148c..0000000000 --- a/modules/common/tests/src/Unit/Mocks/Storage/Memory.php +++ /dev/null @@ -1,44 +0,0 @@ -storage[$id])) { - return $this->storage[$id]; - } - return NULL; - } - - public function retrieveAll(): array { - return $this->storage; - } - - public function store($data, string $id = NULL): string { - if (!isset($id)) { - throw new \Exception('An id is required to store the data.'); - } - if (!isset($this->storage[$id])) { - $this->storage[$id] = $data; - return $id; - } - $this->storage[$id] = $data; - return TRUE; - } - - public function remove(string $id) { - if (isset($this->storage[$id])) { - unset($this->storage[$id]); - return TRUE; - } - return FALSE; - } - -} diff --git a/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php b/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php deleted file mode 100644 index 4b64eb0bdb..0000000000 --- a/modules/common/tests/src/Unit/Mocks/Storage/MemoryFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -stores[$identifier])) { - $this->stores[$identifier] = new Memory(); - } - return $this->stores[$identifier]; - } - -} diff --git a/modules/data_dictionary_widget/data_dictionary_widget.module b/modules/data_dictionary_widget/data_dictionary_widget.module index f6a6f7a64a..07c9f721c9 100644 --- a/modules/data_dictionary_widget/data_dictionary_widget.module +++ b/modules/data_dictionary_widget/data_dictionary_widget.module @@ -4,7 +4,7 @@ * @file * Module for creating Data Dictionary Widget. */ - +use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -77,7 +77,7 @@ function data_dictionary_widget_form_alter(&$form, &$form_state, $form_id) { $formObject = $form_state->getFormObject(); $target_form_ids = ['node_data_edit_form', 'node_data_form']; - if ($formObject instanceof \Drupal\Core\Entity\EntityFormInterface && in_array($form_id, $target_form_ids)) { + if ($formObject instanceof EntityFormInterface && in_array($form_id, $target_form_ids)) { $entity = $formObject->getEntity(); $data_type = $entity->get('field_data_type')->value; if (isset($form["field_json_metadata"]["widget"][0]["dictionary_fields"])) { diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php index 5740c8fe3a..0507640b9b 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\datastore\Unit\Plugin\QueueWorker; +use Contracts\Mock\Storage\Memory; use CsvParser\Parser\Csv; use CsvParser\Parser\ParserInterface; -use Drupal\Tests\common\Unit\Mocks\Storage\Memory; use Drupal\common\Storage\DatabaseTableInterface; use Drupal\datastore\DatastoreResource; use Drupal\datastore\Plugin\QueueWorker\ImportJob; diff --git a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php index 4ddf9ecb9f..6944cd6088 100644 --- a/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php +++ b/modules/datastore/tests/src/Unit/Service/Info/ImportInfoTest.php @@ -4,21 +4,13 @@ use Contracts\Mock\Storage\Memory; use CsvParser\Parser\Csv; -use Drupal\common\FileFetcher\FileFetcherFactory; use Drupal\datastore\DatastoreResource; use Drupal\datastore\Plugin\QueueWorker\ImportJob; -use Drupal\common\Storage\JobStore; -use Drupal\common\Storage\JobStoreFactory; use Drupal\datastore\Service\Info\ImportInfo; -use Drupal\datastore\Service\Info\ImportInfoList; use Drupal\Tests\datastore\Unit\Plugin\QueueWorker\TestMemStorage; use FileFetcher\FileFetcher; -use MockChain\Chain; -use MockChain\Options; use PHPUnit\Framework\TestCase; use Procrastinator\Job\Job; -use Procrastinator\Result; -use Symfony\Component\DependencyInjection\Container; /** * @coversDefaultClass \Drupal\datastore\Service\Info\ImportInfo diff --git a/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php b/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php index e8f833fbc6..0f1da92eb5 100644 --- a/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php +++ b/modules/metastore/modules/metastore_search/tests/src/Unit/Plugin/search_api/datasource/DkanDatasetTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\metastore_search\Unit\Plugin\search_api\datasource; -use _PHPStan_7d6f0f6a4\Psr\Container\ContainerInterface; use Drupal\Core\DependencyInjection\Container; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManager; diff --git a/phpunit.xml b/phpunit.xml index 5dc09e73a4..053093c03c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -63,7 +63,7 @@ - - + + diff --git a/rector.php b/rector.php index 733bf93f6c..7ca609cdc2 100644 --- a/rector.php +++ b/rector.php @@ -22,22 +22,11 @@ declare(strict_types=1); use DrupalFinder\DrupalFinder; -use DrupalRector\Drupal8\Rector\Deprecation\GetMockRector as DrupalGetMockRector; -use DrupalRector\Set\Drupal9SetList; use Rector\Config\RectorConfig; -use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; -use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; -use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; -use Rector\PHPUnit\PHPUnit50\Rector\StaticCall\GetMockRector; -use Rector\PHPUnit\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector; -use Rector\PHPUnit\PHPUnit60\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector; -use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; -use Rector\Php71\Rector\ClassConst\PublicConstantVisibilityRector; -use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; -use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; -use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Set\ValueObject\LevelSetList; -use Rector\ValueObject\PhpVersion; +use DrupalRector\Set\Drupal10SetList; +use DrupalRector\Rector\Deprecation\FunctionToStaticRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector; +use DrupalRector\Rector\PHPUnit\ShouldCallParentMethodsRector; return static function (RectorConfig $rectorConfig): void { @@ -46,36 +35,14 @@ __DIR__, ]); - // Our base version of PHP. - $rectorConfig->phpVersion(PhpVersion::PHP_74); - $rectorConfig->sets([ - Drupal9SetList::DRUPAL_94, - LevelSetList::UP_TO_PHP_74, + Drupal10SetList::DRUPAL_10, ]); $rectorConfig->skip([ - '*/upgrade_status/tests/modules/*', - // Keep getMockBuilder() for now. - GetMockBuilderGetMockToCreateMockRector::class, - DrupalGetMockRector::class, - GetMockRector::class, - // Don't throw errors on JSON parse problems. Yet. - // @todo Throw errors and deal with them appropriately. - JsonThrowOnErrorRector::class, - // We like our tags. Unfortunately some other rules obliterate them anyway. - RemoveUselessParamTagRector::class, - RemoveUselessVarTagRector::class, - RemoveUselessReturnTagRector::class, - AddDoesNotPerformAssertionToNonAssertingTestRector::class, - ClosureToArrowFunctionRector::class, - // Don't automate ::class because we need some string literals that look - // like class names. - // @see \Drupal\common\Util\JobStoreUtil - // @see \Drupal\common\EventDispatcherTrait - StringClassNameToClassConstantRector::class, - RemoveExtraParametersRector::class, - PublicConstantVisibilityRector::class, + FunctionToStaticRector::class, + AddReturnTypeDeclarationRector::class, + ShouldCallParentMethodsRector::class, ]); $drupalFinder = new DrupalFinder(); From 8625e8ce1ffae425d64a0b1fa852b81f49972be2 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 13 May 2024 13:33:36 -0700 Subject: [PATCH 18/18] ignore deprecations --- phpunit.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 053093c03c..5dc09e73a4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -63,7 +63,7 @@ - - + +