diff --git a/.github/ci.yml b/.github/ci.yml index ae161fac..bca704a5 100644 --- a/.github/ci.yml +++ b/.github/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 7.4 ] + php: [ 8.2 ] version: [ lowest, standard ] steps: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c403febb..e1f8c8d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 7.4, 8.0, 8.1 ] + php: [ 8.2, 8.3 ] version: [ lowest, standard ] - elastic: [ 7.12.1 ] + elastic: [ 8.12.0 ] steps: - uses: actions/checkout@v2 @@ -39,15 +39,15 @@ jobs: name: Composer standard run: make composer - - if: matrix.php == '7.4' + - if: matrix.php == '8.2' name: Coding standard run: make cs - - if: matrix.php == '7.4' && matrix.version == 'lowest' + - if: matrix.php == '8.2' && matrix.version == 'lowest' name: PHPStan lowest run: make phpstan-lowest - - if: matrix.php == '7.4' && matrix.version == 'standard' + - if: matrix.php == '8.2' && matrix.version == 'standard' name: PHPStan standard run: make phpstan diff --git a/composer.json b/composer.json index 7f92e9ba..ea56d144 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,11 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.2", "ext-json": "*", "ext-curl": "*", - "spameri/elastic-query": "^v1.0.0", - "elasticsearch/elasticsearch": "^7.12.0", + "spameri/elastic-query": "dev-master", + "elasticsearch/elasticsearch": "^8.12.0", "nette/di": "^3.0.5", "nette/utils": "^3.2.5", "symfony/console": "^4.4.26", @@ -37,10 +37,10 @@ "ezimuel/ringphp": "^1.2" }, "require-dev": { - "spameri/coding-standard": "dev-master", - "spameri/dependency-mocker": "^1.3", + "slevomat/coding-standard": "^8.0", + "spameri/dependency-mocker": "^1.3", "nette/tester": "^2.4", - "phpstan/phpstan": "0.12.84", + "phpstan/phpstan": "^1.10.66", "php-coveralls/php-coveralls": "^2.1", "nette/bootstrap": "^3.0", "nette/http": "^3.0.7", @@ -59,7 +59,8 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "php-http/discovery": true } } } diff --git a/doc/03_entity_class.md b/doc/03_entity_class.md index 0c2416cc..80e3a245 100644 --- a/doc/03_entity_class.md +++ b/doc/03_entity_class.md @@ -231,7 +231,7 @@ class People extends \Spameri\Elastic\Entity\Collection\AbstractElasticEntityCol { /** @var \SpameriTests\Elastic\Data\Entity\Person $entity */ foreach ($this->collection() as $entity) { - if ($imdb->value() === $entity->identification()->imdb()->value()) { + if ($imdb->value() === $entity->identification->imdb->value()) { return $entity; } } diff --git a/makefile b/makefile index 2c531042..72a86990 100644 --- a/makefile +++ b/makefile @@ -28,13 +28,10 @@ phpstan-lowest: vendor/bin/phpstan analyse -l 6 -c phpstan-low.neon src tests cs: - vendor/bin/phpcs --standard=vendor/spameri/coding-standard/src/ruleset.xml --cache=.phpcs-cache src tests/SpameriTests + vendor/bin/phpcs --standard=ruleset.xml --cache=.phpcs-cache src tests -cs-local: - vendor/bin/phpcs --standard=vendor/spameri/coding-standard/src/ruleset.xml src tests/SpameriTests - -cbf: - vendor/bin/phpcbf --standard=vendor/spameri/coding-standard/src/ruleset.xml src tests/SpameriTests +csf: + vendor/bin/phpcbf --standard=ruleset.xml src tests coverage: vendor/bin/tester $COVERAGE -s -c ./tests/php.ini-unix ./tests diff --git a/phpstan-low.neon b/phpstan-low.neon index 7969873e..97de0bc1 100644 --- a/phpstan-low.neon +++ b/phpstan-low.neon @@ -1,5 +1,5 @@ parameters: - excludes_analyse: + excludePaths: - %rootDir%/../../../tests/tmp/* checkGenericClassInNonGenericObjectType: false diff --git a/phpstan.neon b/phpstan.neon index ecfe68c0..60bc1978 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,39 +1,13 @@ parameters: - excludes_analyse: + excludePaths: - %rootDir%/../../../tests/tmp/* ignoreErrors: - - - message: "#^PHPDoc tag @throws with type Elasticsearch\\\\Common\\\\Exceptions\\\\ElasticsearchException is not subtype of Throwable$#" - count: 1 - path: src/ClientProvider.php - - - - message: "#^PHPDoc tag @throws with type Elasticsearch\\\\Common\\\\Exceptions\\\\ElasticsearchException is not subtype of Throwable$#" - count: 1 - path: src/Commands/TypeToNewIndex.php - - - - message: "#^Call to function array_key_exists\\(\\) with string and array\\ will always evaluate to false\\.$#" - count: 1 - path: src/Entity/Collection/AbstractElasticEntityCollection.php - - - - message: "#^Call to function array_key_exists\\(\\) with string and array\\ will always evaluate to false\\.$#" - count: 1 - path: src/Entity/Collection/AbstractEntityCollection.php - - - - message: "#^PHPDoc tag @throws with type Elasticsearch\\\\Common\\\\Exceptions\\\\ElasticsearchException is not subtype of Throwable$#" - count: 2 - path: src/Model/TypeToNewIndex/Migrate.php - - message: "#^Unable to resolve the template type T in call to method Nette\\\\DI\\\\Container\\:\\:getByType\\(\\)$#" count: 2 path: src/Model/ServiceLocator.php - checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 00000000..dbf45e07 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ClientProvider.php b/src/ClientProvider.php index d754ff2f..241463f5 100644 --- a/src/ClientProvider.php +++ b/src/ClientProvider.php @@ -5,29 +5,14 @@ class ClientProvider { - /** - * @var \Elasticsearch\Client - */ - private $client; - - /** - * @var \Elasticsearch\ClientBuilder - */ - private $clientBuilder; - - /** - * @var \Spameri\Elastic\SettingsProviderInterface - */ - private $settingsProvider; + private \Elastic\Elasticsearch\Client $client; public function __construct( - \Elasticsearch\ClientBuilder $clientBuilder, - \Spameri\Elastic\SettingsProviderInterface $settingsProvider + private readonly \Elastic\Elasticsearch\ClientBuilder $clientBuilder, + private readonly \Spameri\Elastic\SettingsProviderInterface $settingsProvider, ) { - $this->clientBuilder = $clientBuilder; - $this->settingsProvider = $settingsProvider; $this->init(); } @@ -38,24 +23,17 @@ public function init(): void $this->clientBuilder->setHosts( [ $settings->host() . ':' . $settings->port(), - ] - ); - $this->clientBuilder->setConnectionParams( - [ - 'client' => [ - 'headers' => $settings->headers(), - ], - ] + ], ); } /** - * @throws \Elasticsearch\Common\Exceptions\ElasticsearchException + * @throws \Elastic\Elasticsearch\Exception\ElasticsearchException */ - public function client(): \Elasticsearch\Client + public function client(): \Elastic\Elasticsearch\Client { - if ( ! ($this->client instanceof \Elasticsearch\Client)) { + if ( ! ($this->client instanceof \Elastic\Elasticsearch\Client)) { $this->client = $this->clientBuilder->build(); } diff --git a/src/Commands/AddAlias.php b/src/Commands/AddAlias.php index 0e9773bd..7526e450 100644 --- a/src/Commands/AddAlias.php +++ b/src/Commands/AddAlias.php @@ -5,22 +5,24 @@ class AddAlias extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\Indices\AddAlias $addAlias; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:add-alias'; public function __construct( - \Spameri\Elastic\Model\Indices\AddAlias $addAlias + private readonly \Spameri\Elastic\Model\Indices\AddAlias $addAlias, ) { - parent::__construct(NULL); - $this->addAlias = $addAlias; + parent::__construct(null); } protected function configure(): void { $this - ->setName('spameri:elastic:add-alias') + ->setName(self::$defaultName) ->setDescription('Adds alias to existing index.') ->addArgument('index', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('alias', \Symfony\Component\Console\Input\InputArgument::REQUIRED) @@ -30,7 +32,7 @@ protected function configure(): void protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { /** @var string $index */ diff --git a/src/Commands/CreateIndex.php b/src/Commands/CreateIndex.php index 92f40c6e..6f31d877 100644 --- a/src/Commands/CreateIndex.php +++ b/src/Commands/CreateIndex.php @@ -4,34 +4,32 @@ class CreateIndex extends \Symfony\Component\Console\Command\Command { - - private \Spameri\Elastic\Model\CreateIndex $createIndex; - - private \Spameri\Elastic\Model\DeleteIndex $deleteIndex; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:create-index'; public function __construct( - \Spameri\Elastic\Model\CreateIndex $createIndex, - \Spameri\Elastic\Model\DeleteIndex $deleteIndex + private readonly \Spameri\Elastic\Model\CreateIndex $createIndex, + private readonly \Spameri\Elastic\Model\DeleteIndex $deleteIndex, ) { - parent::__construct(NULL); - $this->createIndex = $createIndex; - $this->deleteIndex = $deleteIndex; + parent::__construct(null); } protected function configure(): void { $this - ->setName('spameri:elastic:create-index') + ->setName(self::$defaultName) ->setDescription( - 'Creates index. Take string as is, adds timestamp and inserts it in Elastic. No mapping or settings.' + 'Creates index. Take string as is, adds timestamp and inserts it in Elastic. No mapping or settings.', ) ->addArgument('indexName', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addOption( - 'force', 'f', NULL, - 'Warning this deletes your data! Forces now used index to be deleted before new index is created.' + 'force', 'f', null, + 'Warning this deletes your data! Forces now used index to be deleted before new index is created.', ) ; } @@ -42,7 +40,7 @@ protected function configure(): void */ protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { /** @var string $indexName */ diff --git a/src/Commands/DeleteIndex.php b/src/Commands/DeleteIndex.php index 18ce2faa..2609a431 100644 --- a/src/Commands/DeleteIndex.php +++ b/src/Commands/DeleteIndex.php @@ -5,22 +5,24 @@ class DeleteIndex extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\Indices\Delete $delete; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:delete-index'; public function __construct( - \Spameri\Elastic\Model\Indices\Delete $delete + private readonly \Spameri\Elastic\Model\Indices\Delete $delete, ) { - parent::__construct(NULL); - $this->delete = $delete; + parent::__construct(null); } protected function configure(): void { $this - ->setName('spameri:elastic:delete-index') + ->setName(self::$defaultName) ->setDescription('Deletes index by name or alias. Warning this deletes your data!') ->addArgument('indexName', \Symfony\Component\Console\Input\InputArgument::IS_ARRAY) ; @@ -29,7 +31,7 @@ protected function configure(): void protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { /** @var array $indexNames */ diff --git a/src/Commands/DumpIndex.php b/src/Commands/DumpIndex.php index 7dec382d..d339829c 100644 --- a/src/Commands/DumpIndex.php +++ b/src/Commands/DumpIndex.php @@ -5,15 +5,17 @@ class DumpIndex extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\DumpIndex $dumpIndex; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:dump-index'; public function __construct( - \Spameri\Elastic\Model\DumpIndex $migrate + private readonly \Spameri\Elastic\Model\DumpIndex $migrate, ) { - parent::__construct(NULL); - $this->dumpIndex = $migrate; + parent::__construct(null); } @@ -23,7 +25,7 @@ public function __construct( protected function configure(): void { $this - ->setName('spameri:elastic:dump-index') + ->setName(self::$defaultName) ->setDescription('Dumps all data from index to file') ->addArgument('index', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::REQUIRED) @@ -34,7 +36,7 @@ protected function configure(): void protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { $output->writeln('Starting'); @@ -42,8 +44,8 @@ protected function execute( $index = $input->getArgument('index'); $filename = $input->getArgument('filename'); - $this->dumpIndex->setOutput($output); - $this->dumpIndex->execute($index, $filename); + $this->migrate->setOutput($output); + $this->migrate->execute($index, $filename); $output->writeln('Done'); diff --git a/src/Commands/InitializeIndexes.php b/src/Commands/InitializeIndexes.php index b491cb9a..39a165a5 100644 --- a/src/Commands/InitializeIndexes.php +++ b/src/Commands/InitializeIndexes.php @@ -5,37 +5,33 @@ class InitializeIndexes extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\DeleteIndex $deleteIndex; - - private \Spameri\Elastic\Model\InitializeIndex $initializeIndex; - - private \Spameri\Elastic\Model\EntitySettingsLocator $entitySettingsLocator; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:initialize-index'; public function __construct( - \Spameri\Elastic\Model\EntitySettingsLocator $entitySettingsLocator, - \Spameri\Elastic\Model\DeleteIndex $deleteIndex, - \Spameri\Elastic\Model\InitializeIndex $initializeIndex + private readonly \Spameri\Elastic\Model\EntitySettingsLocator $entitySettingsLocator, + private readonly \Spameri\Elastic\Model\DeleteIndex $deleteIndex, + private readonly \Spameri\Elastic\Model\InitializeIndex $initializeIndex, ) { - parent::__construct(NULL); - $this->entitySettingsLocator = $entitySettingsLocator; - $this->deleteIndex = $deleteIndex; - $this->initializeIndex = $initializeIndex; + parent::__construct(null); } protected function configure(): void { $this - ->setName('spameri:elastic:initialize-index') + ->setName(self::$defaultName) ->setDescription( - 'Creates index/es. And initializes with settings and mappings' + 'Creates index/es. And initializes with settings and mappings', ) ->addArgument('entityName', \Symfony\Component\Console\Input\InputArgument::IS_ARRAY) ->addOption( - 'force', 'f', NULL, - 'Warning this deletes your data! Forces now used index to be deleted before new index is created.' + 'force', 'f', null, + 'Warning this deletes your data! Forces now used index to be deleted before new index is created.', ) ; } @@ -46,7 +42,7 @@ protected function configure(): void */ protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { /** @var array $entityNames */ @@ -59,7 +55,7 @@ protected function execute( $settings = $indexConfig->provide(); foreach ($entityNames as $entityName) { - if (\strpos($settings->indexName(), $entityName) === FALSE) { + if (\strpos($settings->indexName(), $entityName) === false) { continue 2; } } diff --git a/src/Commands/LoadDump.php b/src/Commands/LoadDump.php index e02d39c5..d3360186 100644 --- a/src/Commands/LoadDump.php +++ b/src/Commands/LoadDump.php @@ -5,15 +5,17 @@ class LoadDump extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\RestoreIndex $restoreIndex; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:load-dump'; public function __construct( - \Spameri\Elastic\Model\RestoreIndex $migrate + private readonly \Spameri\Elastic\Model\RestoreIndex $migrate, ) { - parent::__construct(NULL); - $this->restoreIndex = $migrate; + parent::__construct(null); } @@ -23,14 +25,14 @@ public function __construct( protected function configure(): void { $this - ->setName('spameri:elastic:load-dump') + ->setName(self::$defaultName) ->setDescription('Loads data from provided dump file.') ->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument( 'step', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Number of documents per one bulk index', - '500' + '500', ) ; } @@ -38,7 +40,7 @@ protected function configure(): void protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { $output->writeln('Starting'); @@ -46,8 +48,8 @@ protected function execute( $filename = $input->getArgument('filename'); $step = (int) $input->getArgument('step'); - $this->restoreIndex->setOutput($output); - $this->restoreIndex->execute($filename, $step); + $this->migrate->setOutput($output); + $this->migrate->execute($filename, $step); $output->writeln('Done'); diff --git a/src/Commands/RemoveAlias.php b/src/Commands/RemoveAlias.php index c155048c..5804395c 100644 --- a/src/Commands/RemoveAlias.php +++ b/src/Commands/RemoveAlias.php @@ -5,22 +5,24 @@ class RemoveAlias extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\Indices\RemoveAlias $removeAlias; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:remove-alias'; public function __construct( - \Spameri\Elastic\Model\Indices\RemoveAlias $removeAlias + private readonly \Spameri\Elastic\Model\Indices\RemoveAlias $removeAlias, ) { - parent::__construct(NULL); - $this->removeAlias = $removeAlias; + parent::__construct(null); } protected function configure(): void { $this - ->setName('spameri:elastic:remove-alias') + ->setName(self::$defaultName) ->setDescription('Adds alias to existing index.') ->addArgument('index', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('alias', \Symfony\Component\Console\Input\InputArgument::REQUIRED) @@ -30,7 +32,7 @@ protected function configure(): void protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { /** @var string $index */ diff --git a/src/Commands/TypeToNewIndex.php b/src/Commands/TypeToNewIndex.php index e7fa655e..159c0c8f 100644 --- a/src/Commands/TypeToNewIndex.php +++ b/src/Commands/TypeToNewIndex.php @@ -5,15 +5,17 @@ class TypeToNewIndex extends \Symfony\Component\Console\Command\Command { - private \Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate; + /** + * @var string + */ + protected static $defaultName = 'spameri:elastic:move-type'; public function __construct( - \Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate + private readonly \Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate, ) { - parent::__construct(NULL); - $this->migrate = $migrate; + parent::__construct(null); } @@ -23,28 +25,28 @@ public function __construct( protected function configure(): void { $this - ->setName('spameri:elastic:move-type') + ->setName(self::$defaultName) ->setDescription('Move type to new index to separate data and prepare for deprecation of types is ES.') ->addArgument('indexFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('typeFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('indexTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED) ->addArgument('aliasTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED) - ->addArgument('typeTo', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Use only on old ElasticSearch', NULL) + ->addArgument('typeTo', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Use only on old ElasticSearch', null) ->addOption( 'allowClose', 'c', \Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, 'Allows command to close index for data transfer. After data is transferred index is opened and resumes normal operations. When open it needs to check changed files after move and sync remaining.', - TRUE + true, ) ; } /** - * @throws \Elasticsearch\Common\Exceptions\ElasticsearchException + * @throws \Elastic\Elasticsearch\Exception\ElasticsearchException */ protected function execute( \Symfony\Component\Console\Input\InputInterface $input, - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): int { $output->writeln('Starting'); diff --git a/src/Config/Elastic.neon b/src/Config/Elastic.neon index 354d76ea..d5fe362b 100644 --- a/src/Config/Elastic.neon +++ b/src/Config/Elastic.neon @@ -189,12 +189,12 @@ services: # ### clientBuilder: - factory: Elasticsearch\ClientBuilder + factory: \Elastic\Elasticsearch\ClientBuilder setup: - setLogger(@spameriElasticSearch.elasticPanelLogger) client: - class: Elasticsearch\Client + class: \Elastic\Elasticsearch\Client factory: @spameriElasticSearch.clientBuilder::build dateTimeProvider: @@ -217,3 +217,12 @@ services: nullAfterImport: factory: Spameri\Elastic\Import\AfterImport\NullAfterImport + + entityFactory: + factory: Spameri\Elastic\Factory\EntityFactory + +# entityService: +# factory: Spameri\Elastic\Model\EntityService + + entityRepository: + factory: Spameri\Elastic\EntityRepository diff --git a/src/DI/SpameriElasticSearchExtension.php b/src/DI/SpameriElasticSearchExtension.php index 34a2a60e..353b4101 100644 --- a/src/DI/SpameriElasticSearchExtension.php +++ b/src/DI/SpameriElasticSearchExtension.php @@ -39,7 +39,7 @@ public function loadConfiguration(): void } $this->compiler->loadDefinitionsFromConfig( - $aliasedServices + $aliasedServices, ); } @@ -47,7 +47,7 @@ public function loadConfiguration(): void public function setConfigOptions( array $services, - array $config + array $config, ): array { $neonSettingsProvider = $services['services']['neonSettingsProvider']['factory']; @@ -68,7 +68,7 @@ public function setConfigOptions( */ public function toggleDebugBar( array $config, - array $services + array $services, ): array { if ( ! $config['debug']) { @@ -77,7 +77,7 @@ public function toggleDebugBar( $services['services']['elasticPanelLogger'], $services['services']['nullLogger'], $services['services']['elasticPanel'], - $services['services']['clientBuilder']['setup'] + $services['services']['clientBuilder']['setup'], ); } else { diff --git a/src/Diagnostics/Panel.php b/src/Diagnostics/Panel.php index b98cd018..9482d221 100644 --- a/src/Diagnostics/Panel.php +++ b/src/Diagnostics/Panel.php @@ -1,21 +1,16 @@ -logger = $logger; } diff --git a/src/Diagnostics/PanelLogger.php b/src/Diagnostics/PanelLogger.php index 61e12837..55b97358 100644 --- a/src/Diagnostics/PanelLogger.php +++ b/src/Diagnostics/PanelLogger.php @@ -1,36 +1,32 @@ - */ - private $queries = []; + private array $queries = []; /** * @var array */ - private $requestBodies = []; + private array $requestBodies = []; /** * @var array */ - private $responseBodies = []; + private array $responseBodies = []; public function __construct( - \Psr\Log\LoggerInterface $logger + private \Psr\Log\LoggerInterface $logger, ) { - $this->logger = $logger; } @@ -40,7 +36,7 @@ public function __construct( */ public function emergency( $message, - array $context = [] + array $context = [], ) { $this->logger->emergency($message, $context); @@ -54,7 +50,7 @@ public function emergency( */ public function alert( $message, - array $context = [] + array $context = [], ): void { $this->logger->alert($message, $context); @@ -68,7 +64,7 @@ public function alert( */ public function critical( $message, - array $context = [] + array $context = [], ): void { $this->logger->critical($message, $context); @@ -82,7 +78,7 @@ public function critical( */ public function error( $message, - array $context = [] + array $context = [], ): void { $this->logger->error($message, $context); @@ -96,7 +92,7 @@ public function error( */ public function warning( $message, - array $context = [] + array $context = [], ): void { $this->logger->warning($message, $context); @@ -110,7 +106,7 @@ public function warning( */ public function notice( $message, - array $context = [] + array $context = [], ): void { $this->logger->notice($message, $context); @@ -124,7 +120,7 @@ public function notice( */ public function info( $message, - array $context = [] + array $context = [], ): void { $this->logger->info($message, $context); @@ -138,7 +134,7 @@ public function info( */ public function debug( $message, - array $context = [] + array $context = [], ): void { $this->logger->debug($message, $context); @@ -156,7 +152,7 @@ public function debug( public function log( $level, $message, - array $context = [] + array $context = [], ): void { $this->logger->log($level, $message, $context); @@ -195,7 +191,7 @@ public function getResponseBodies(): array * @param array $context */ private function logQuery( - array $context = [] + array $context = [], ): void { if (isset($context['method'], $context['uri'])) { @@ -211,7 +207,7 @@ private function logQuery( */ private function logRequestBody( string $message, - $context + $context, ): void { if ( @@ -228,7 +224,7 @@ private function logRequestBody( */ private function logResponseBody( string $message, - $context + $context, ): void { if ($message === 'Response') { diff --git a/src/Entity/AbstractElasticEntity.php b/src/Entity/AbstractElasticEntity.php new file mode 100644 index 00000000..19d4eabf --- /dev/null +++ b/src/Entity/AbstractElasticEntity.php @@ -0,0 +1,26 @@ +id; + } + + + public function entityVariables(): array + { + return \get_object_vars($this); + } + +} \ No newline at end of file diff --git a/src/Entity/AbstractImport.php b/src/Entity/AbstractImport.php index 1f47ad14..2c5fec0e 100644 --- a/src/Entity/AbstractImport.php +++ b/src/Entity/AbstractImport.php @@ -2,30 +2,17 @@ namespace Spameri\Elastic\Entity; -abstract class AbstractImport implements \Spameri\Elastic\Entity\Import\ValidationObjectInterface +abstract readonly class AbstractImport implements \Spameri\Elastic\Entity\Import\ValidationObjectInterface { - /** - * @var int|string - */ - private $key; - - - /** - * @param int|string $key - */ public function __construct( - $key + private int|string $key, ) { - $this->key = $key; } - /** - * @return int|string - */ - public function key() + public function key(): int|string { return $this->key; } diff --git a/src/Entity/AbstractValueCollection.php b/src/Entity/AbstractValueCollection.php index ba2a1e86..e1eb910a 100644 --- a/src/Entity/AbstractValueCollection.php +++ b/src/Entity/AbstractValueCollection.php @@ -8,11 +8,11 @@ abstract class AbstractValueCollection implements ValueCollectionInterface /** * @var array<\Spameri\Elastic\Entity\ValueInterface> */ - protected $collection; + protected array $collection; public function __construct( - \Spameri\Elastic\Entity\ValueInterface ...$collection + \Spameri\Elastic\Entity\ValueInterface ...$collection, ) { $this->collection = []; @@ -23,26 +23,20 @@ public function __construct( public function add( - \Spameri\Elastic\Entity\ValueInterface $value + \Spameri\Elastic\Entity\ValueInterface $value, ): void { $this->collection[$value->value()] = $value; } - /** - * @param mixed $key - */ - public function remove($key): void + public function remove(mixed $key): void { unset($this->collection[$key]); } - /** - * @param mixed $key - */ - public function get($key): ?\Spameri\Elastic\Entity\ValueInterface + public function get(mixed $key): \Spameri\Elastic\Entity\ValueInterface|null { if ( ! isset($this->collection[$key])) { return NULL; diff --git a/src/Entity/Collection/AbstractCachedEntityCollection.php b/src/Entity/Collection/AbstractCachedEntityCollection.php new file mode 100644 index 00000000..ba730cbc --- /dev/null +++ b/src/Entity/Collection/AbstractCachedEntityCollection.php @@ -0,0 +1,79 @@ +initialize(); + + return parent::entity($key); + } + + + public function remove( + string|int $key, + ): void + { + $this->initialize(); + + parent::remove($key); + } + + + public function isValue( + string $key, + ): bool + { + $this->initialize(); + + return parent::isValue($key); + } + + + public function count(): int + { + $this->initialize(); + + return parent::count(); + } + + + public function keys(): array + { + $this->initialize(); + + return parent::keys(); + } + + + public function isKey( + string $key, + ): bool + { + $this->initialize(); + + return parent::isKey($key); + } + + + public function sort( + \Spameri\Elastic\Entity\Collection\SortField $sortField, // phpcs:ignore + string $type, + ): void + { + $this->initialize(); + + parent::sort($sortField, $type); + } + +} diff --git a/src/Entity/Collection/AbstractElasticEntityCollection.php b/src/Entity/Collection/AbstractElasticEntityCollection.php index 2f3f6d13..dc64a644 100644 --- a/src/Entity/Collection/AbstractElasticEntityCollection.php +++ b/src/Entity/Collection/AbstractElasticEntityCollection.php @@ -8,33 +8,18 @@ abstract class AbstractElasticEntityCollection implements \Spameri\Elastic\Entit /** * @var array<\Spameri\Elastic\Entity\ElasticEntityInterface> */ - protected $collection; + protected array $collection; - /** - * @var \Spameri\Elastic\Model\ServiceInterface - */ - protected $service; - - /** - * @var array - */ - protected $elasticIds; - - /** - * @var bool - */ - protected $initialized; + protected bool $initialized; public function __construct( - \Spameri\Elastic\Model\ServiceInterface $service, - array $elasticIds = [], - \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection + protected \Spameri\Elastic\Model\ServiceInterface $service, + protected array $elasticIds = [], + \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection, ) { $this->collection = []; - $this->service = $service; - $this->elasticIds = $elasticIds; $this->initialized = FALSE; if ( @@ -51,7 +36,7 @@ public function __construct( public function add( - \Spameri\Elastic\Entity\ElasticEntityInterface $elasticEntity + \Spameri\Elastic\Entity\ElasticEntityInterface $elasticEntity, ): void { if ( ! $this->initialized) { @@ -76,11 +61,11 @@ public function initialize(): void new \Spameri\ElasticQuery\Query\MustCollection( new \Spameri\ElasticQuery\Query\Terms( '_id', - $this->elasticIds - ) - ) - ) - ) + $this->elasticIds, + ), + ), + ), + ), ); $this->initialized = TRUE; @@ -123,8 +108,8 @@ public function getIterator(): \ArrayIterator public function entity( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id - ): ?\Spameri\Elastic\Entity\ElasticEntityInterface + \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, + ): \Spameri\Elastic\Entity\ElasticEntityInterface|null { if ( ! $this->initialized) { $this->initialize(); @@ -143,7 +128,7 @@ public function entity( public function remove( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id + \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, ): void { if ( ! $this->initialized) { @@ -155,7 +140,7 @@ public function remove( public function isValue( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id + \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, ): bool { if ( ! $this->initialized) { @@ -187,7 +172,7 @@ public function keys(): array public function isKey( - string $key + string $key, ): bool { if ( ! $this->initialized) { @@ -206,7 +191,7 @@ public function clear(): void public function sort( \Spameri\Elastic\Entity\Collection\SortField $sortField, // phpcs:ignore - string $type + string $type, ): void { if ( ! $this->initialized) { @@ -220,4 +205,14 @@ public function sort( throw new \Nette\NotImplementedException(); } + + public function first(): \Spameri\Elastic\Entity\ElasticEntityInterface|null + { + if ( ! $this->initialized) { + $this->initialize(); + } + + return \reset($this->collection) ?: NULL; + } + } diff --git a/src/Entity/Collection/AbstractEntityCollection.php b/src/Entity/Collection/AbstractEntityCollection.php index 2af991f3..4b206a97 100644 --- a/src/Entity/Collection/AbstractEntityCollection.php +++ b/src/Entity/Collection/AbstractEntityCollection.php @@ -8,22 +8,22 @@ abstract class AbstractEntityCollection implements \Spameri\Elastic\Entity\Entit /** * @var array<\Spameri\Elastic\Entity\EntityInterface> */ - private $collection; + protected array $collection; public function __construct( - \Spameri\Elastic\Entity\EntityInterface ...$entityCollection + \Spameri\Elastic\Entity\EntityInterface ...$collection, ) { $this->collection = []; - foreach ($entityCollection as $elasticEntity) { + foreach ($collection as $elasticEntity) { $this->add($elasticEntity); } } public function add( - \Spameri\Elastic\Entity\EntityInterface $entity + \Spameri\Elastic\Entity\EntityInterface $entity, ): void { $this->collection[$entity->key()] = $entity; @@ -43,8 +43,8 @@ public function getIterator(): \ArrayIterator public function entity( - string $key - ): ?\Spameri\Elastic\Entity\EntityInterface + string $key, + ): \Spameri\Elastic\Entity\EntityInterface|null { if (\array_key_exists($key, $this->collection)) { return $this->collection[$key]; @@ -55,7 +55,7 @@ public function entity( public function remove( - string $key + string|int $key, ): void { unset($this->collection[$key]); @@ -63,7 +63,7 @@ public function remove( public function isValue( - string $key + string $key, ): bool { return \array_key_exists($key, $this->collection); @@ -83,7 +83,7 @@ public function keys(): array public function isKey( - string $key + string $key, ): bool { return \array_key_exists($key, \array_map('\strval', \array_keys($this->collection))); @@ -98,7 +98,7 @@ public function clear(): void public function sort( \Spameri\Elastic\Entity\Collection\SortField $sortField, // phpcs:ignore - string $type + string $type, ): void { if ( ! \in_array($type, ['asc', 'desc'], TRUE)) { @@ -108,4 +108,10 @@ public function sort( throw new \Nette\NotImplementedException(); } + + public function first(): \Spameri\Elastic\Entity\EntityInterface|null + { + return \reset($this->collection) ?: NULL; + } + } diff --git a/src/Entity/Collection/ElasticEntityCollection.php b/src/Entity/Collection/ElasticEntityCollection.php new file mode 100644 index 00000000..fa24f550 --- /dev/null +++ b/src/Entity/Collection/ElasticEntityCollection.php @@ -0,0 +1,11 @@ + - */ - private $array; - - /** - * @var string - */ - private $key; - - /** * @param array $array */ public function __construct( - array $array, - string $key + private array $array, + private string $key, ) { - $this->array = $array; - $this->key = $key; } diff --git a/src/Entity/Import/BoolValue.php b/src/Entity/Import/BoolValue.php index f88cf329..9babb629 100644 --- a/src/Entity/Import/BoolValue.php +++ b/src/Entity/Import/BoolValue.php @@ -2,27 +2,14 @@ namespace Spameri\Elastic\Entity\Import; -class BoolValue implements ValidationPropertyInterface +readonly class BoolValue implements ValidationPropertyInterface { - /** - * @var bool - */ - private $value; - - /** - * @var string - */ - private $key; - - public function __construct( - bool $value, - string $key + private bool $value, + private string $key, ) { - $this->value = $value; - $this->key = $key; } diff --git a/src/Entity/Import/DateValue.php b/src/Entity/Import/DateValue.php index d7044bff..c1002f24 100644 --- a/src/Entity/Import/DateValue.php +++ b/src/Entity/Import/DateValue.php @@ -2,34 +2,15 @@ namespace Spameri\Elastic\Entity\Import; -class DateValue implements ValidationPropertyInterface +readonly class DateValue implements ValidationPropertyInterface { - /** - * @var \DateTime - */ - private $value; - - /** - * @var string - */ - private $key; - - /** - * @var string - */ - private $format; - - public function __construct( - \DateTime $value, - string $key, - string $format = 'Y-m-d H:i:s' + private \DateTime $value, + private string $key, + private string $format = 'Y-m-d H:i:s', ) { - $this->value = $value; - $this->key = $key; - $this->format = $format; } diff --git a/src/Entity/Import/EmptyValue.php b/src/Entity/Import/EmptyValue.php index 96436812..bf62b762 100644 --- a/src/Entity/Import/EmptyValue.php +++ b/src/Entity/Import/EmptyValue.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Entity\Import; -class EmptyValue implements ValidationPropertyInterface +readonly class EmptyValue implements ValidationPropertyInterface { - /** - * @var string - */ - private $key; - - public function __construct( - string $key + private string $key, ) { - $this->key = $key; } @@ -25,7 +18,7 @@ public function key(): string } - public function getValue() + public function getValue(): null { return NULL; } diff --git a/src/Entity/Import/FloatValue.php b/src/Entity/Import/FloatValue.php index 6b08ff48..ad2ae2f4 100644 --- a/src/Entity/Import/FloatValue.php +++ b/src/Entity/Import/FloatValue.php @@ -2,27 +2,14 @@ namespace Spameri\Elastic\Entity\Import; -class FloatValue implements ValidationPropertyInterface +readonly class FloatValue implements ValidationPropertyInterface { - /** - * @var float - */ - private $value; - - /** - * @var string - */ - private $key; - - public function __construct( - float $value, - string $key + private float $value, + private string $key, ) { - $this->value = $value; - $this->key = $key; } diff --git a/src/Entity/Import/IntegerValue.php b/src/Entity/Import/IntegerValue.php index 34c43d14..0af762a0 100644 --- a/src/Entity/Import/IntegerValue.php +++ b/src/Entity/Import/IntegerValue.php @@ -2,27 +2,14 @@ namespace Spameri\Elastic\Entity\Import; -class IntegerValue implements ValidationPropertyInterface +readonly class IntegerValue implements ValidationPropertyInterface { - /** - * @var int - */ - private $value; - - /** - * @var string - */ - private $key; - - public function __construct( - int $value, - string $key + private int $value, + private string $key, ) { - $this->value = $value; - $this->key = $key; } diff --git a/src/Entity/Import/NoValue.php b/src/Entity/Import/NoValue.php index bc71a5c5..682dec5a 100644 --- a/src/Entity/Import/NoValue.php +++ b/src/Entity/Import/NoValue.php @@ -2,22 +2,16 @@ namespace Spameri\Elastic\Entity\Import; -class NoValue implements ValidationPropertyInterface +readonly class NoValue implements ValidationPropertyInterface { - /** - * @return NULL - */ - public function key() + public function key(): null { return NULL; } - /** - * @return NULL - */ - public function getValue() + public function getValue(): null { return NULL; } diff --git a/src/Entity/Import/StringValue.php b/src/Entity/Import/StringValue.php index fd39bd9e..a0cae107 100644 --- a/src/Entity/Import/StringValue.php +++ b/src/Entity/Import/StringValue.php @@ -2,27 +2,14 @@ namespace Spameri\Elastic\Entity\Import; -class StringValue implements ValidationPropertyInterface +readonly class StringValue implements ValidationPropertyInterface { - /** - * @var string - */ - private $value; - - /** - * @var string - */ - private $key; - - public function __construct( - string $value, - string $key + private string $value, + private string $key, ) { - $this->value = $value; - $this->key = $key; } diff --git a/src/Entity/Import/ValidationObjectInterface.php b/src/Entity/Import/ValidationObjectInterface.php index 0cf95eb4..4909d577 100644 --- a/src/Entity/Import/ValidationObjectInterface.php +++ b/src/Entity/Import/ValidationObjectInterface.php @@ -5,10 +5,7 @@ interface ValidationObjectInterface extends \Spameri\ElasticQuery\Entity\ArrayInterface { - /** - * @return mixed - */ - public function key(); + public function key(): mixed; /** diff --git a/src/Entity/Import/ValidationPropertyInterface.php b/src/Entity/Import/ValidationPropertyInterface.php index 4e932e88..53d63ed2 100644 --- a/src/Entity/Import/ValidationPropertyInterface.php +++ b/src/Entity/Import/ValidationPropertyInterface.php @@ -5,15 +5,8 @@ interface ValidationPropertyInterface { - /** - * @return mixed - */ - public function key(); + public function key(): mixed; - - /** - * @return mixed - */ - public function getValue(); + public function getValue(): mixed; } diff --git a/src/Entity/Property/Date.php b/src/Entity/Property/Date.php index d2b5b40f..0c49c765 100644 --- a/src/Entity/Property/Date.php +++ b/src/Entity/Property/Date.php @@ -8,13 +8,9 @@ class Date extends \Nette\Utils\DateTime implements \Spameri\Elastic\Entity\Date public const FORMAT = 'Y-m-d'; - /** - * @param string|null $format - * @return string - */ - public function format($format = NULL) + public function format(string $format = ''): string { - if ( ! $format) { + if ($format === '') { $format = self::FORMAT; } diff --git a/src/Entity/Property/DateTime.php b/src/Entity/Property/DateTime.php index a4df11ab..5df6690e 100644 --- a/src/Entity/Property/DateTime.php +++ b/src/Entity/Property/DateTime.php @@ -1,4 +1,4 @@ -format('U'); + + if ($timeDifference < 1) { + return 'less than 1 second ago'; + } + + $condition = [ + 12 * 30 * 24 * 60 * 60 => 'year', + 30 * 24 * 60 * 60 => 'month', + 24 * 60 * 60 => 'day', + 60 * 60 => 'hour', + 60 => 'minute', + 1 => 'second', + ]; + + foreach ($condition as $secs => $str) { + $d = $timeDifference / $secs; + + if ($d >= 1) { + $t = \round($d); + return $t . ' ' . $str . ($t > 1 ? 's' : '') . ' ago'; + } + } + + return 'some time ago'; + } + } diff --git a/src/Entity/Property/ElasticId.php b/src/Entity/Property/ElasticId.php index 48503b66..ab56c62f 100644 --- a/src/Entity/Property/ElasticId.php +++ b/src/Entity/Property/ElasticId.php @@ -2,23 +2,18 @@ namespace Spameri\Elastic\Entity\Property; -class ElasticId implements \Spameri\Elastic\Entity\ValueInterface, \Spameri\Elastic\Entity\Property\ElasticIdInterface +readonly class ElasticId implements \Spameri\Elastic\Entity\ValueInterface, \Spameri\Elastic\Entity\Property\ElasticIdInterface { - /** - * @var string - */ - private $value; - + public const FIELD_NAME = '_id'; public function __construct( - string $id + private string $value, ) { - if ($id === '') { + if ($value === '') { throw new \InvalidArgumentException(); } - $this->value = $id; } diff --git a/src/Entity/Property/EmptyElasticId.php b/src/Entity/Property/EmptyElasticId.php index da60ff76..dc9c568b 100644 --- a/src/Entity/Property/EmptyElasticId.php +++ b/src/Entity/Property/EmptyElasticId.php @@ -2,23 +2,16 @@ namespace Spameri\Elastic\Entity\Property; -class EmptyElasticId implements \Spameri\Elastic\Entity\ValueInterface, \Spameri\Elastic\Entity\Property\ElasticIdInterface +readonly class EmptyElasticId implements \Spameri\Elastic\Entity\ValueInterface, \Spameri\Elastic\Entity\Property\ElasticIdInterface { - /** - * @var string - */ - private $value; - - public function __construct( - string $id = '' + private string $value = '', ) { - if ($id !== '') { + if ($value !== '') { throw new \InvalidArgumentException(); } - $this->value = $id; } diff --git a/src/Entity/Value/BoolValue.php b/src/Entity/Value/BoolValue.php index ffcdec64..c79f9301 100644 --- a/src/Entity/Value/BoolValue.php +++ b/src/Entity/Value/BoolValue.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Entity\Value; -class BoolValue implements \Spameri\Elastic\Entity\ValueInterface +readonly class BoolValue implements \Spameri\Elastic\Entity\ValueInterface { - /** - * @var bool - */ - private $value; - - public function __construct( - bool $value + private bool $value, ) { - $this->value = $value; } diff --git a/src/Entity/Value/IntegerValue.php b/src/Entity/Value/IntegerValue.php index 0a5d202a..d4d1f3e1 100644 --- a/src/Entity/Value/IntegerValue.php +++ b/src/Entity/Value/IntegerValue.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Entity\Value; -class IntegerValue implements \Spameri\Elastic\Entity\ValueInterface +readonly class IntegerValue implements \Spameri\Elastic\Entity\ValueInterface { - /** - * @var int - */ - private $value; - - public function __construct( - int $value + private int $value, ) { - $this->value = $value; } diff --git a/src/Entity/Value/NullValue.php b/src/Entity/Value/NullValue.php index fda6b080..31f6e282 100644 --- a/src/Entity/Value/NullValue.php +++ b/src/Entity/Value/NullValue.php @@ -2,26 +2,17 @@ namespace Spameri\Elastic\Entity\Value; -class NullValue implements \Spameri\Elastic\Entity\ValueInterface +readonly class NullValue implements \Spameri\Elastic\Entity\ValueInterface { - /** - * @var NULL - */ - private $value; - - public function __construct() { } - /** - * @return NULL - */ - public function value() + public function value(): null { - return $this->value; + return NULL; } } diff --git a/src/Entity/Value/StringValue.php b/src/Entity/Value/StringValue.php index 171bb19c..71614ea0 100644 --- a/src/Entity/Value/StringValue.php +++ b/src/Entity/Value/StringValue.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Entity\Value; -class StringValue implements \Spameri\Elastic\Entity\ValueInterface +readonly class StringValue implements \Spameri\Elastic\Entity\ValueInterface { - /** - * @var string - */ - private $value; - - public function __construct( - string $value + private string $value, ) { - $this->value = $value; } diff --git a/src/Entity/ValueInterface.php b/src/Entity/ValueInterface.php index 4bfc69f1..c7cd0ed0 100644 --- a/src/Entity/ValueInterface.php +++ b/src/Entity/ValueInterface.php @@ -5,9 +5,6 @@ interface ValueInterface { - /** - * @return mixed - */ - public function value(); + public function value(): mixed; } diff --git a/src/EntityRepository.php b/src/EntityRepository.php new file mode 100644 index 00000000..029eac35 --- /dev/null +++ b/src/EntityRepository.php @@ -0,0 +1,115 @@ +addMustQuery( + new \Spameri\ElasticQuery\Query\Term( + '_id', + $id, + ), + ); + + return $this->findOneBy($elasticQuery, $class); + } + + + public function findOneBy( + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, + string $class, + ): \Spameri\Elastic\Entity\ElasticEntityInterface + { + $elasticQuery->options()->changeSize(1); + + $entities = $this->findBy($elasticQuery, $class); + + if (\count($entities) === 0) { + throw new \Spameri\Elastic\Exception\DocumentNotFound('Entity ' . $class . ' not found.'); + } + + return \reset($entities); + } + + + public function findBy( + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, + string $class, + ): array + { + $indexConfig = $this->entitySettingsLocator->locateByEntityClass($class); + + try { + $resultSearch = $this->getAllBy->execute($elasticQuery, $indexConfig->indexName()); + + } catch (\Spameri\Elastic\Exception\ElasticSearch $exception) { + \Tracy\Debugger::log($exception->getMessage(), \Tracy\ILogger::CRITICAL); + + throw $exception; + } + + $entities = []; + foreach ($resultSearch->hits() as $hit) { + try { + $entities[] = $this->entityFactory->create($hit, $class)->current(); + + } catch (\Spameri\Elastic\Exception\ElasticSearch $exception) { + \Tracy\Debugger::log($exception->getMessage(), \Tracy\ILogger::CRITICAL); + } + } + + // TODO univerzální kolekce + return $entities; + } + + + public function findAll(string $class): array + { + $elasticQuery = new \Spameri\ElasticQuery\ElasticQuery(); + $elasticQuery->options()->changeSize(10000); + + return $this->findBy($elasticQuery, $class); + } + + + public function persist( + \Spameri\Elastic\Entity\AbstractElasticEntity $entity + ): string + { + $indexConfig = $this->entitySettingsLocator->locateByEntityClass($entity::class); + + return $this->insert->execute( + entity: $entity, + index: $indexConfig->indexName(), + hasSti: $indexConfig->hasSti(), + ); + } + + + public function remove(\Spameri\Elastic\Entity\ElasticEntityInterface $entity): bool + { + $indexConfig = $this->entitySettingsLocator->locateByEntityClass($entity::class); + + return $this->delete->execute($entity->id(), $indexConfig->indexName()); + } + +} diff --git a/src/Exception/AliasAlreadyExists.php b/src/Exception/AliasAlreadyExists.php index 92b6d6ab..dd4be20c 100644 --- a/src/Exception/AliasAlreadyExists.php +++ b/src/Exception/AliasAlreadyExists.php @@ -6,11 +6,11 @@ class AliasAlreadyExists extends \Spameri\Elastic\Exception\AbstractElasticSearc { public function __construct( - string $indexName + string $indexName, ) { parent::__construct( - 'You are trying to create already existing alias with name: ' . $indexName . "\n" + 'You are trying to create already existing alias with name: ' . $indexName . "\n", ); } diff --git a/src/Exception/DocumentNotFound.php b/src/Exception/DocumentNotFound.php index 43684518..b707e0be 100644 --- a/src/Exception/DocumentNotFound.php +++ b/src/Exception/DocumentNotFound.php @@ -7,7 +7,7 @@ class DocumentNotFound extends \Spameri\Elastic\Exception\AbstractElasticSearchE public function __construct( string $message, - ?\Spameri\ElasticQuery\ElasticQuery $elasticQuery = NULL + \Spameri\ElasticQuery\ElasticQuery|null $elasticQuery = NULL, ) { $queryString = ''; @@ -22,7 +22,7 @@ public function __construct( parent::__construct( 'Document in index "' . $message . '" not found. With query: ' - . $queryString + . $queryString, ); } diff --git a/src/Exception/IndexAlreadyExists.php b/src/Exception/IndexAlreadyExists.php index 6d4bbb76..7fdfb4b9 100644 --- a/src/Exception/IndexAlreadyExists.php +++ b/src/Exception/IndexAlreadyExists.php @@ -6,12 +6,12 @@ class IndexAlreadyExists extends \Spameri\Elastic\Exception\AbstractElasticSearc { public function __construct( - string $indexName + string $indexName, ) { parent::__construct( 'You are trying to create already existing index or aliased index with name: ' . $indexName . "\n" - . 'You can delete already existing index by -f option' . "\n" + . 'You can delete already existing index by -f option' . "\n", ); } diff --git a/src/Exception/InvalidArgument.php b/src/Exception/InvalidArgument.php new file mode 100644 index 00000000..28621328 --- /dev/null +++ b/src/Exception/InvalidArgument.php @@ -0,0 +1,10 @@ + $elasticIds + * @return \Spameri\Elastic\Entity\ElasticEntityCollectionInterface<\Spameri\Elastic\Entity\ElasticEntityInterface> + */ public function create( \Spameri\Elastic\Model\ServiceInterface $service, array $elasticIds = [], - \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection + \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface; } diff --git a/src/Factory/EntityFactory.php b/src/Factory/EntityFactory.php new file mode 100644 index 00000000..a204d827 --- /dev/null +++ b/src/Factory/EntityFactory.php @@ -0,0 +1,141 @@ + + */ + public function create( + \Spameri\ElasticQuery\Response\Result\Hit $hit, + string|null $class = null, + ): \Generator + { + if ($class === null) { + throw new \Spameri\Elastic\Exception\InvalidArgument('Class must be set.'); + } + + $properties = $this->resolveProperties($hit, $class); + + if ($hit->getValue(\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS) !== null) { + $class = $hit->getValue(\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS); + } + + yield new $class( + ... $properties, + ); + } + + protected function resolveProperties( + \Spameri\ElasticQuery\Response\Result\Hit $hit, + string $class, + string|null $parentFieldName = null, + ): array + { + $reflection = $this->reflection->createReflection($class); + + $resolvedProperties = []; + foreach ($this->reflection->getProperties($reflection) as $property) { + $hitKey = $property->getName(); + if ($parentFieldName !== null) { + $hitKey = $parentFieldName . '.' . $hitKey; + } + + $reflectionPropertyType = $this->reflection->getPropertyType($property); + if ($reflectionPropertyType === null) { + $resolvedProperties[$property->getName()] = $hit->getValue($parentFieldName); + continue; + } + + $value = $hit->getValue($hitKey); + $propertyTypeName = $reflectionPropertyType->getName(); + if ($reflectionPropertyType->allowsNull() && $value === null) { + $propertyValue = null; + + } elseif ($property->hasDefaultValue() === true && $value === null) { + $propertyValue = $property->getDefaultValue(); + + } elseif ($propertyTypeName === \Spameri\Elastic\Entity\Property\Date::class) { + if ($value !== null) { + $propertyValue = new \Spameri\Elastic\Entity\Property\Date( + datetime: $value, + ); + + } else { + $propertyValue = null; + } + + } elseif (\count($property->getAttributes()) > 0) { + foreach ($property->getAttributes() as $attribute) { + if ( + $attribute->getName() === \Spameri\Elastic\Mapping\Entity::class + ) { + $arguments = $attribute->getArguments(); + + if ($arguments['class'] === \Spameri\Elastic\Entity\Property\ElasticId::class) { + $propertyValue = new $arguments['class']( + $hit->id(), + ); + + } else { + $propertyValue = new $arguments['class']( + ... $this->resolveProperties($hit, $propertyTypeName, $hitKey), + ); + } + } elseif ( + $attribute->getName() === \Spameri\Elastic\Mapping\Collection::class + ) { + $propertyValue = new $propertyTypeName(); + if ($value !== null) { + foreach ($value as $entityKey => $entity) { + $propertyValue->add( + new $entity[\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS]( + ... $this->resolveProperties($hit, $entity[\Spameri\Elastic\Model\Insert\PrepareEntityArray::ENTITY_CLASS], $hitKey . '.' . $entityKey), + ), + ); + } + } + } elseif ( + $attribute->getName() === \Spameri\Elastic\Mapping\Ignored::class + ) { + continue 2; + } + } + + } elseif (\class_exists($propertyTypeName)) { + if (isset(\class_implements($propertyTypeName)[\Spameri\Elastic\Entity\ValueInterface::class]) === true) { + $propertyValue = new $propertyTypeName( + $value, + ); + + } else { + $propertyValue = new $propertyTypeName( + ... $this->resolveProperties($hit, $propertyTypeName, $hitKey), + ); + } + + } else { + $propertyValue = $value; + } + + if (isset($propertyValue)) { + $resolvedProperties[$property->getName()] = $propertyValue; + } + + unset($propertyValue); + } + + return $resolvedProperties; + } + +} diff --git a/src/Factory/EntityFactoryInterface.php b/src/Factory/EntityFactoryInterface.php index 5a5c310f..168b7989 100644 --- a/src/Factory/EntityFactoryInterface.php +++ b/src/Factory/EntityFactoryInterface.php @@ -6,7 +6,8 @@ interface EntityFactoryInterface { public function create( - \Spameri\ElasticQuery\Response\Result\Hit $hit + \Spameri\ElasticQuery\Response\Result\Hit $hit, + string|null $class = null, ): \Generator; } diff --git a/src/Import/AfterImportInterface.php b/src/Import/AfterImportInterface.php index 3ef02dfe..6b24a5a4 100644 --- a/src/Import/AfterImportInterface.php +++ b/src/Import/AfterImportInterface.php @@ -10,7 +10,7 @@ interface AfterImportInterface */ public function process( array $entityData, - \Spameri\Elastic\Import\ResponseInterface $result + \Spameri\Elastic\Import\ResponseInterface $result, ): void; } diff --git a/src/Import/DataImportInterface.php b/src/Import/DataImportInterface.php index b61b924d..65af255c 100644 --- a/src/Import/DataImportInterface.php +++ b/src/Import/DataImportInterface.php @@ -6,7 +6,7 @@ interface DataImportInterface { public function import( - \Spameri\Elastic\Entity\AbstractImport $entity + \Spameri\Elastic\Entity\AbstractImport $entity, ): \Spameri\Elastic\Import\ResponseInterface; } diff --git a/src/Import/DataProviderInterface.php b/src/Import/DataProviderInterface.php index a92be2b3..32f5e919 100644 --- a/src/Import/DataProviderInterface.php +++ b/src/Import/DataProviderInterface.php @@ -9,12 +9,12 @@ interface DataProviderInterface * @return \Generator */ public function provide( - \Spameri\Elastic\Import\Run\Options $options + \Spameri\Elastic\Import\Run\Options $options, ): \Generator; public function count( - \Spameri\Elastic\Import\Run\Options $options + \Spameri\Elastic\Import\Run\Options $options, ): int; } diff --git a/src/Import/Lock/FileLock.php b/src/Import/Lock/FileLock.php index f54e7734..b479c93a 100644 --- a/src/Import/Lock/FileLock.php +++ b/src/Import/Lock/FileLock.php @@ -5,22 +5,13 @@ class FileLock implements \Spameri\Elastic\Import\LockInterface { - /** - * @var string - */ - private $lockDir; - - /** - * @var string - */ - private $runName; + private string $runName; public function __construct( - string $lockDir + private readonly string $lockDir, ) { - $this->lockDir = $lockDir; } diff --git a/src/Import/LockInterface.php b/src/Import/LockInterface.php index f8f04d86..17d648c5 100644 --- a/src/Import/LockInterface.php +++ b/src/Import/LockInterface.php @@ -12,7 +12,7 @@ public function setRunName(string $runName): void; * @throws \Spameri\Elastic\Import\Exception\AlreadyLocked */ public function acquire( - int $time + int $time, ): self; @@ -20,7 +20,7 @@ public function release(): void; public function extend( - int $time + int $time, ): void; } diff --git a/src/Import/LoggerHandlerInterface.php b/src/Import/LoggerHandlerInterface.php index 587b079a..26d8f7a5 100644 --- a/src/Import/LoggerHandlerInterface.php +++ b/src/Import/LoggerHandlerInterface.php @@ -5,36 +5,33 @@ interface LoggerHandlerInterface { - /** - * @param mixed $item - */ public function logItemStart( - $item + mixed $item, ): void; public function logPrepared( - \Spameri\Elastic\Entity\AbstractImport $import + \Spameri\Elastic\Entity\AbstractImport $import, ): void; public function logResponse( - \Spameri\Elastic\Import\ResponseInterface $result + \Spameri\Elastic\Import\ResponseInterface $result, ): void; public function logOmitException( - \Spameri\Elastic\Import\Exception\ImportException $exception + \Spameri\Elastic\Import\Exception\ImportException $exception, ): void; public function logErrorException( - \Spameri\Elastic\Import\Exception\ImportException $exception + \Spameri\Elastic\Import\Exception\ImportException $exception, ): void; public function logFatalException( - \Spameri\Elastic\Import\Exception\ImportException $exception + \Spameri\Elastic\Import\Exception\ImportException $exception, ): void; diff --git a/src/Import/PrepareImportDataInterface.php b/src/Import/PrepareImportDataInterface.php index 79622efd..48bc3b58 100644 --- a/src/Import/PrepareImportDataInterface.php +++ b/src/Import/PrepareImportDataInterface.php @@ -5,11 +5,8 @@ interface PrepareImportDataInterface { - /** - * @param mixed $entityData - */ public function prepare( - $entityData + mixed $entityData, ): \Spameri\Elastic\Entity\AbstractImport; } diff --git a/src/Import/Response/SimpleResponse.php b/src/Import/Response/SimpleResponse.php index 926db986..94e657cf 100644 --- a/src/Import/Response/SimpleResponse.php +++ b/src/Import/Response/SimpleResponse.php @@ -2,40 +2,24 @@ namespace Spameri\Elastic\Import\Response; -class SimpleResponse implements \Spameri\Elastic\Import\ResponseInterface +readonly class SimpleResponse implements \Spameri\Elastic\Import\ResponseInterface { - /** - * @var mixed - */ - private $response; - - /** - * @var \Spameri\Elastic\Entity\AbstractImport - */ - private $entity; - - public function __construct( - $response, - \Spameri\Elastic\Entity\AbstractImport $entity + private mixed $response, + private \Spameri\Elastic\Entity\AbstractImport $entity, ) { - $this->response = $response; - $this->entity = $entity; } public function isSuccessful(): bool { - return $this->response ? TRUE : FALSE; + return (bool) $this->response; } - /** - * @return mixed - */ - public function getResponse() + public function getResponse(): mixed { return $this->response; } diff --git a/src/Import/ResponseInterface.php b/src/Import/ResponseInterface.php index 9c3552c0..09f64dba 100644 --- a/src/Import/ResponseInterface.php +++ b/src/Import/ResponseInterface.php @@ -5,22 +5,16 @@ interface ResponseInterface { - /** - * @param mixed $response - */ public function __construct( - $response, - \Spameri\Elastic\Entity\AbstractImport $entity + mixed $response, + \Spameri\Elastic\Entity\AbstractImport $entity, ); public function isSuccessful(): bool; - /** - * @return mixed - */ - public function getResponse(); + public function getResponse(): mixed; public function getEntity(): \Spameri\Elastic\Entity\AbstractImport; diff --git a/src/Import/Run.php b/src/Import/Run.php index 87807865..f815ce7c 100644 --- a/src/Import/Run.php +++ b/src/Import/Run.php @@ -5,84 +5,29 @@ class Run { - /** - * @var \Symfony\Component\Console\Output\OutputInterface - */ - private $output; - - /** - * @var \Spameri\Elastic\Import\LockInterface - */ - private $lock; - - /** - * @var \Spameri\Elastic\Import\RunHandlerInterface - */ - private $runHandler; - - /** - * @var \Spameri\Elastic\Import\DataProviderInterface - */ - private $dataProvider; - - /** - * @var \Spameri\Elastic\Import\PrepareImportDataInterface - */ - private $prepareImportData; - - /** - * @var \Spameri\Elastic\Import\DataImportInterface - */ - private $dataImport; + private \Symfony\Component\Console\Output\OutputInterface $output; - /** - * @var \Spameri\Elastic\Import\AfterImportInterface - */ - private $afterImport; + protected string $runName; - /** - * @var string - */ - protected $runName; + protected string $fileName; - /** - * @var string - */ - protected $fileName; - - /** - * @var \Symfony\Component\Console\Helper\ProgressBar - */ - private $progressBar; - - /** - * @var \Spameri\Elastic\Import\LoggerHandlerInterface - */ - private $loggerHandler; + private \Symfony\Component\Console\Helper\ProgressBar $progressBar; /** * @throws \ReflectionException */ public function __construct( - string $logDir, - \Spameri\Elastic\Import\LoggerHandlerInterface $loggerHandler, - \Spameri\Elastic\Import\LockInterface $lock, - \Spameri\Elastic\Import\RunHandlerInterface $runHandler, - \Spameri\Elastic\Import\DataProviderInterface $dataProvider, - \Spameri\Elastic\Import\PrepareImportDataInterface $prepareImportData, - \Spameri\Elastic\Import\DataImportInterface $dataImport, - \Spameri\Elastic\Import\AfterImportInterface $afterImport + protected string $logDir, + private readonly \Spameri\Elastic\Import\LoggerHandlerInterface $loggerHandler, + private readonly \Spameri\Elastic\Import\LockInterface $lock, + private readonly \Spameri\Elastic\Import\RunHandlerInterface $runHandler, + private readonly \Spameri\Elastic\Import\DataProviderInterface $dataProvider, + private readonly \Spameri\Elastic\Import\PrepareImportDataInterface $prepareImportData, + private readonly \Spameri\Elastic\Import\DataImportInterface $dataImport, + private readonly \Spameri\Elastic\Import\AfterImportInterface $afterImport, ) { - $this->lock = $lock; - $this->loggerHandler = $loggerHandler; - $this->runHandler = $runHandler; - $this->dataProvider = $dataProvider; - $this->prepareImportData = $prepareImportData; - $this->dataImport = $dataImport; - $this->afterImport = $afterImport; - $this->runName = (new \ReflectionClass($this))->getShortName(); $this->lock->setRunName($this->runName); $this->setUpLogger($logDir); @@ -113,7 +58,7 @@ protected function setUpLogger(string $logDir): void public function execute( - \Spameri\Elastic\Import\Run\Options $options + \Spameri\Elastic\Import\Run\Options $options, ): void { $this->lock->acquire($options->lockDuration()); diff --git a/src/Import/Run/LoggerHandler.php b/src/Import/Run/LoggerHandler.php index a6fb7013..33f0df62 100644 --- a/src/Import/Run/LoggerHandler.php +++ b/src/Import/Run/LoggerHandler.php @@ -2,27 +2,17 @@ namespace Spameri\Elastic\Import\Run; -class LoggerHandler implements \Spameri\Elastic\Import\LoggerHandlerInterface +readonly class LoggerHandler implements \Spameri\Elastic\Import\LoggerHandlerInterface { - /** - * @var \Psr\Log\LoggerInterface - */ - private $logger; - - public function __construct( - \Psr\Log\LoggerInterface $logger + private \Psr\Log\LoggerInterface $logger, ) { - $this->logger = $logger; } - /** - * @param mixed $item - */ - public function logItemStart($item): void + public function logItemStart(mixed $item): void { $this->logger->debug('Processing item ' . \Tracy\Dumper::toText($item)); } diff --git a/src/Import/Run/NullLoggerHandler.php b/src/Import/Run/NullLoggerHandler.php index 9401bab8..0f252dfc 100644 --- a/src/Import/Run/NullLoggerHandler.php +++ b/src/Import/Run/NullLoggerHandler.php @@ -6,10 +6,7 @@ class NullLoggerHandler implements \Spameri\Elastic\Import\LoggerHandlerInterfac { // phpcs:disable - /** - * @param mixed $item - */ - public function logItemStart($item): void + public function logItemStart(mixed $item): void { // do nothing; } diff --git a/src/Import/Run/Options.php b/src/Import/Run/Options.php index 572e4bab..72dc723c 100644 --- a/src/Import/Run/Options.php +++ b/src/Import/Run/Options.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Import\Run; -class Options +readonly class Options { - /** - * @var int - */ - private $lockDuration; - - public function __construct( - int $lockDuration + private int $lockDuration, ) { - $this->lockDuration = $lockDuration; } diff --git a/src/Import/RunHandlerInterface.php b/src/Import/RunHandlerInterface.php index fff41aea..0cd433ed 100644 --- a/src/Import/RunHandlerInterface.php +++ b/src/Import/RunHandlerInterface.php @@ -8,14 +8,14 @@ interface RunHandlerInterface public function advance( string $runName, \Symfony\Component\Console\Helper\ProgressBar $progressBar, - ?\Spameri\Elastic\Entity\AbstractImport $lastProcessed + \Spameri\Elastic\Entity\AbstractImport|null $lastProcessed, ): void; public function finish( string $runName, \Symfony\Component\Console\Helper\ProgressBar $progressBar, - ?\Spameri\Elastic\Entity\AbstractImport $lastProcessed + \Spameri\Elastic\Entity\AbstractImport|null $lastProcessed, ): void; } diff --git a/src/Import/SimpleRun.php b/src/Import/SimpleRun.php index e17d1501..057f3b16 100644 --- a/src/Import/SimpleRun.php +++ b/src/Import/SimpleRun.php @@ -13,7 +13,7 @@ public function __construct( \Spameri\Elastic\Import\DataProviderInterface $dataProvider, \Spameri\Elastic\Import\PrepareImportDataInterface $prepareImportData, \Spameri\Elastic\Import\DataImportInterface $dataImport, - \Spameri\Elastic\Import\AfterImport\NullAfterImport $afterImport + \Spameri\Elastic\Import\AfterImport\NullAfterImport $afterImport, ) { parent::__construct($logDir, $loggerHandler, $lock, $runHandler, $dataProvider, $prepareImportData, $dataImport, $afterImport); diff --git a/src/Mapping/Collection.php b/src/Mapping/Collection.php new file mode 100644 index 00000000..ececd0f5 --- /dev/null +++ b/src/Mapping/Collection.php @@ -0,0 +1,17 @@ +index = $index; - $this->insert = $insert; - $this->get = $get; - $this->delete = $delete; - $this->getBy = $getBy; - $this->getAllBy = $getAllBy; - $this->entityFactory = $entityFactory; - $this->collectionFactory = $collectionFactory; - $this->aggregate = $aggregate; - } + public string $index, + protected readonly \Spameri\Elastic\Factory\EntityFactoryInterface $entityFactory, + protected readonly \Spameri\Elastic\Factory\CollectionFactoryInterface $collectionFactory, + protected readonly \Spameri\Elastic\Model\Insert $insert, + protected readonly \Spameri\Elastic\Model\Get $get, + protected readonly \Spameri\Elastic\Model\GetBy $getBy, + protected readonly \Spameri\Elastic\Model\GetAllBy $getAllBy, + protected readonly \Spameri\Elastic\Model\Delete $delete, + protected readonly \Spameri\Elastic\Model\Aggregate $aggregate, + protected readonly \Spameri\Elastic\Model\ServiceLocator $serviceLocator, + ) {} /** @@ -53,7 +24,7 @@ public function __construct( * @throws \Spameri\Elastic\Exception\DocumentInsertFailed */ public function insert( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\AbstractElasticEntity $entity, ): string { return $this->insert->execute($entity, $this->index); @@ -64,7 +35,7 @@ public function insert( * @throws \Spameri\Elastic\Exception\DocumentNotFound */ public function get( - \Spameri\Elastic\Entity\Property\ElasticId $id + \Spameri\Elastic\Entity\Property\ElasticId $id, ): \Spameri\Elastic\Entity\ElasticEntityInterface { try { @@ -89,7 +60,7 @@ public function get( * @throws \Spameri\Elastic\Exception\ElasticSearch */ public function getBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityInterface { try { @@ -113,7 +84,7 @@ public function getBy( * @throws \Spameri\Elastic\Exception\DocumentNotFound */ public function getAllBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface { try { @@ -125,25 +96,36 @@ public function getAllBy( throw $exception; } - if ($resultSearch->stats()->total() === 0) { + if ($resultSearch->hits()->count() === 0) { throw new \Spameri\Elastic\Exception\DocumentNotFound($this->index, $elasticQuery); } $entities = []; foreach ($resultSearch->hits() as $hit) { - $entities[] = $this->entityFactory->create($hit)->current(); + try { + $entities[] = $this->entityFactory->create($hit)->current(); + + } catch (\Spameri\Elastic\Exception\ElasticSearch $exception) { + \Tracy\Debugger::log($exception->getMessage(), \Tracy\ILogger::CRITICAL); + } } return $this->collectionFactory->create( $this, [], - ... $entities + ... $entities, ); } + public function createEmptyCollection(): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface + { + return $this->collectionFactory->create($this); + } + + public function delete( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id + \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, ): bool { try { @@ -156,9 +138,33 @@ public function delete( } } + public function deleteReference( + \Spameri\Elastic\Entity\ElasticEntityInterface $entityToDelete, + string $class, + string $field, + ): void + { + try { + $service = $this->serviceLocator->locateByEntityClass($class); + $elasticQuery = new \Spameri\ElasticQuery\ElasticQuery(); + $elasticQuery->addMustQuery( + new \Spameri\ElasticQuery\Query\Term( + field: $field, + query: $entityToDelete->id()->value(), + ), + ); + $collection = $service->getAllBy($elasticQuery); + foreach ($collection as $entity) { + $service->delete($entity->id()); + } + + } catch (\Spameri\Elastic\Exception\DocumentNotFound $e) { + // Do nothing + } + } public function aggregate( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\ElasticQuery\Response\ResultSearch { return $this->aggregate->execute($elasticQuery, $this->index); diff --git a/src/Model/Aggregate.php b/src/Model/Aggregate.php index ea128e93..76628bde 100644 --- a/src/Model/Aggregate.php +++ b/src/Model/Aggregate.php @@ -2,38 +2,22 @@ namespace Spameri\Elastic\Model; -class Aggregate +readonly class Aggregate { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } public function execute( \Spameri\ElasticQuery\ElasticQuery $elasticQuery, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSearch { if ($type === NULL) { @@ -50,19 +34,19 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, new \Spameri\ElasticQuery\Document\Body\Plain( - $elasticQuery->toArray() + $elasticQuery->toArray(), ), - $type + $type, ) - )->toArray() + )->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } - return $this->resultMapper->mapSearchResults($result); + return $this->resultMapper->mapSearchResults($result->asArray()); } } diff --git a/src/Model/CreateIndex.php b/src/Model/CreateIndex.php index cccafd8d..82fa997b 100644 --- a/src/Model/CreateIndex.php +++ b/src/Model/CreateIndex.php @@ -2,29 +2,16 @@ namespace Spameri\Elastic\Model; -class CreateIndex +readonly class CreateIndex { - private \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider; - - private Indices\AddAlias $addAlias; - - private Indices\Get $get; - - private Indices\Create $create; - - public function __construct( - \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, - \Spameri\Elastic\Model\Indices\AddAlias $addAlias, - \Spameri\Elastic\Model\Indices\Get $get, - \Spameri\Elastic\Model\Indices\Create $create + private \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, + private \Spameri\Elastic\Model\Indices\AddAlias $addAlias, + private \Spameri\Elastic\Model\Indices\Get $get, + private \Spameri\Elastic\Model\Indices\Create $create, ) { - $this->dateTimeProvider = $dateTimeProvider; - $this->addAlias = $addAlias; - $this->get = $get; - $this->create = $create; } diff --git a/src/Model/Delete.php b/src/Model/Delete.php index bcf6b4b9..edcd4f0a 100644 --- a/src/Model/Delete.php +++ b/src/Model/Delete.php @@ -2,24 +2,14 @@ namespace Spameri\Elastic\Model; -class Delete +readonly class Delete { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -29,7 +19,7 @@ public function __construct( public function execute( \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, string $index, - ?string $type = NULL + string|null $type = NULL, ): bool { if ($type === NULL) { @@ -47,14 +37,14 @@ public function execute( $index, NULL, $type, - $id->value() + $id->value(), ) ) - ->toArray() - ) + ->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -63,11 +53,11 @@ public function execute( ( new \Spameri\ElasticQuery\Document($index) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/DeleteIndex.php b/src/Model/DeleteIndex.php index 49d6f37a..01ca24b1 100644 --- a/src/Model/DeleteIndex.php +++ b/src/Model/DeleteIndex.php @@ -2,21 +2,14 @@ namespace Spameri\Elastic\Model; -class DeleteIndex +readonly class DeleteIndex { - private \Spameri\Elastic\Model\Indices\Get $get; - - private \Spameri\Elastic\Model\Indices\Delete $delete; - - public function __construct( - \Spameri\Elastic\Model\Indices\Get $get, - \Spameri\Elastic\Model\Indices\Delete $delete + private \Spameri\Elastic\Model\Indices\Get $get, + private \Spameri\Elastic\Model\Indices\Delete $delete, ) { - $this->get = $get; - $this->delete = $delete; } diff --git a/src/Model/DeleteMultiple.php b/src/Model/DeleteMultiple.php index 4c6dc1d3..6807214d 100644 --- a/src/Model/DeleteMultiple.php +++ b/src/Model/DeleteMultiple.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class DeleteMultiple +readonly class DeleteMultiple { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -37,7 +21,7 @@ public function __construct( public function execute( \Spameri\Elastic\Entity\ElasticEntityCollectionInterface $entityCollection, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultBulk { if ($type === NULL) { @@ -64,9 +48,9 @@ public function execute( $document = new \Spameri\ElasticQuery\Document\Bulk($documentsArray); try { - $response = $this->clientProvider->client()->bulk($document->toArray()); + $response = $this->clientProvider->client()->bulk($document->toArray())->asArray(); - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -75,11 +59,11 @@ public function execute( ( new \Spameri\ElasticQuery\Document($index) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/DumpIndex.php b/src/Model/DumpIndex.php index 8ca1d3b0..4c107a90 100644 --- a/src/Model/DumpIndex.php +++ b/src/Model/DumpIndex.php @@ -5,33 +5,21 @@ class DumpIndex { - /** - * @var \Symfony\Component\Console\Output\OutputInterface - */ - private $output; + private \Symfony\Component\Console\Output\OutputInterface $output; - /** - * @var string - */ - private $bulkData; - - /** - * @var \Spameri\Elastic\Model\Scroll - */ - private $scroll; + private string $bulkData; public function __construct( - \Spameri\Elastic\Model\Scroll $scroll + private readonly \Spameri\Elastic\Model\Scroll $scroll, ) { $this->bulkData = ''; - $this->scroll = $scroll; } public function setOutput( - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): void { $this->output = $output; @@ -41,7 +29,7 @@ public function setOutput( public function execute( string $index, string $filename, - ?string $type = NULL + string|null $type = NULL, ): void { if ( ! $type) { @@ -84,7 +72,7 @@ public function execute( public function processHit( - \Spameri\ElasticQuery\Response\Result\Hit $hit + \Spameri\ElasticQuery\Response\Result\Hit $hit, ): void { $bulkData = [ @@ -101,7 +89,7 @@ public function processHit( public function writeToFile( - string $filename + string $filename, ): void { @\file_put_contents($filename, $this->bulkData, \FILE_APPEND); diff --git a/src/Model/EntityService.php b/src/Model/EntityService.php new file mode 100644 index 00000000..d4d5fd79 --- /dev/null +++ b/src/Model/EntityService.php @@ -0,0 +1,12 @@ +container = $container; } @@ -20,8 +18,9 @@ public function locate(string $indexName): \Spameri\ElasticQuery\Mapping\Setting { $indexConfigs = $this->locateAll(); + /** @var \Spameri\Elastic\Settings\IndexConfigInterface $indexConfig */ foreach ($indexConfigs as $indexConfig) { - if (\strpos($indexConfig->provide()->indexName(), $indexName) !== FALSE) { + if (\str_contains($indexConfig->provide()->indexName(), $indexName)) { return $indexConfig->provide(); } } @@ -30,6 +29,23 @@ public function locate(string $indexName): \Spameri\ElasticQuery\Mapping\Setting } + public function locateByEntityClass(string $entityClass): \Spameri\ElasticQuery\Mapping\Settings + { + $indexConfigs = $this->locateAll(); + + /** @var \Spameri\Elastic\Settings\AbstractIndexConfig $indexConfig */ + foreach ($indexConfigs as $indexConfig) { + foreach ($indexConfig->entityClass() as $class) { + if ($class === $entityClass) { + return $indexConfig->provide(); + } + } + } + + throw new \Spameri\Elastic\Exception\SettingsNotLocated($entityClass); + } + + /** * @return \Generator<\Spameri\Elastic\Settings\IndexConfigInterface> */ diff --git a/src/Model/Get.php b/src/Model/Get.php index 19e4fbca..158418e5 100644 --- a/src/Model/Get.php +++ b/src/Model/Get.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class Get +readonly class Get { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -38,7 +22,7 @@ public function __construct( public function execute( \Spameri\Elastic\Entity\Property\ElasticId $id, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSingle { if ($type === NULL) { @@ -56,18 +40,18 @@ public function execute( $index, NULL, $type, - $id->value() + $id->value(), ) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } - return $this->resultMapper->mapSingleResult($response); + return $this->resultMapper->mapSingleResult($response->asArray()); } } diff --git a/src/Model/GetAllBy.php b/src/Model/GetAllBy.php index 3e80a97c..bd7c8a18 100644 --- a/src/Model/GetAllBy.php +++ b/src/Model/GetAllBy.php @@ -2,38 +2,22 @@ namespace Spameri\Elastic\Model; -class GetAllBy +readonly class GetAllBy { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } public function execute( \Spameri\ElasticQuery\ElasticQuery $options, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSearch { if ($type === NULL) { @@ -50,14 +34,14 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, new \Spameri\ElasticQuery\Document\Body\Plain($options->toArray()), - $type + $type, ) ) - ->toArray() - ) + ->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/GetBy.php b/src/Model/GetBy.php index 35c68544..c7590015 100644 --- a/src/Model/GetBy.php +++ b/src/Model/GetBy.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class GetBy +readonly class GetBy { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -36,7 +20,7 @@ public function __construct( public function execute( \Spameri\ElasticQuery\ElasticQuery $options, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSearch { if ($type === NULL) { @@ -53,18 +37,18 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, new \Spameri\ElasticQuery\Document\Body\Plain($options->toArray()), - $type + $type, ) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } - return $this->resultMapper->mapSearchResults($response); + return $this->resultMapper->mapSearchResults($response->asArray()); } } diff --git a/src/Model/Index.php b/src/Model/Index.php index 64a1bda1..1e9b1b30 100644 --- a/src/Model/Index.php +++ b/src/Model/Index.php @@ -2,21 +2,14 @@ namespace Spameri\Elastic\Model; -class Index +readonly class Index { - private \Spameri\Elastic\ClientProvider $clientProvider; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -27,7 +20,7 @@ public function __construct( public function execute( array $data, string $index, - ?string $type = NULL + string|null $type = NULL, ): string { if ($type === NULL) { @@ -44,13 +37,13 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, new \Spameri\ElasticQuery\Document\Body\Plain($data), - $type + $type, ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -59,11 +52,11 @@ public function execute( ( new \Spameri\ElasticQuery\Document($index) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/Indices/AddAlias.php b/src/Model/Indices/AddAlias.php index f9344db8..cc143733 100644 --- a/src/Model/Indices/AddAlias.php +++ b/src/Model/Indices/AddAlias.php @@ -2,17 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class AddAlias +readonly class AddAlias { - private \Spameri\Elastic\ClientProvider $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -23,41 +19,45 @@ public function execute(string $alias, string $index): array $this->clientProvider->client()->indices()->get( ( new \Spameri\ElasticQuery\Document( - $alias + $alias, ) - )->toArray() + )->toArray(), ) ; throw new \Spameri\Elastic\Exception\AliasAlreadyExists($alias); - } catch (\Elasticsearch\Common\Exceptions\Missing404Exception $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { + if ($exception->getCode() !== 404) { + throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); + } + return $this->clientProvider->client()->indices()->putAlias( ( - new \Spameri\ElasticQuery\Document( - $index, - new \Spameri\ElasticQuery\Document\Body\Plain( - [ - 'actions' => [ - 'add' => [ - 'index' => $index, - 'alias' => $alias, + new \Spameri\ElasticQuery\Document( + $index, + new \Spameri\ElasticQuery\Document\Body\Plain( + [ + 'actions' => [ + 'add' => [ + 'index' => $index, + 'alias' => $alias, + ], ], ], - ] - ), - NULL, - NULL, - [ - 'name' => $index, - ] - ) - )->toArray() - ) - ; + ), + NULL, + NULL, + [ + 'name' => $index, + ], + ) + )->toArray(), + )->asArray() + ; } - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/Close.php b/src/Model/Indices/Close.php index 5597a3f6..eef07b97 100644 --- a/src/Model/Indices/Close.php +++ b/src/Model/Indices/Close.php @@ -2,32 +2,25 @@ namespace Spameri\Elastic\Model\Indices; -class Close +readonly class Close { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } public function execute( - string $index + string $index, ): bool { try { $result = $this->clientProvider->client()->indices()->close( ( new \Spameri\ElasticQuery\Document($index) - )->toArray() + )->toArray(), ) ; @@ -35,7 +28,7 @@ public function execute( return TRUE; } - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/Indices/Create.php b/src/Model/Indices/Create.php index 2a1a2863..9e895261 100644 --- a/src/Model/Indices/Create.php +++ b/src/Model/Indices/Create.php @@ -2,21 +2,14 @@ namespace Spameri\Elastic\Model\Indices; -class Create +readonly class Create { - private \Spameri\Elastic\ClientProvider $clientProvider; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -27,7 +20,7 @@ public function __construct( public function execute( string $index, array $parameters, - ?string $type = NULL + string|null $type = NULL, ): array { if ($type === NULL) { @@ -56,13 +49,13 @@ public function execute( ( new \Spameri\ElasticQuery\Document( $index, - new \Spameri\ElasticQuery\Document\Body\Plain($parameters) + new \Spameri\ElasticQuery\Document\Body\Plain($parameters), ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } @@ -93,7 +86,7 @@ public function replaceKeywordInOlderVersion(array &$field): void \strtolower($field['type']), [ \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, - ], TRUE + ], TRUE, ) ) { $field['type'] = \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING; diff --git a/src/Model/Indices/Delete.php b/src/Model/Indices/Delete.php index 12d9dde0..9ea7709a 100644 --- a/src/Model/Indices/Delete.php +++ b/src/Model/Indices/Delete.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class Delete +readonly class Delete { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -23,20 +16,20 @@ public function __construct( * @return array */ public function execute( - string $index + string $index, ): array { try { return $this->clientProvider->client()->indices()->delete( ( new \Spameri\ElasticQuery\Document( - $index + $index, ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/Exists.php b/src/Model/Indices/Exists.php index 2a8f95cf..72ece064 100644 --- a/src/Model/Indices/Exists.php +++ b/src/Model/Indices/Exists.php @@ -2,35 +2,31 @@ namespace Spameri\Elastic\Model\Indices; -class Exists +readonly class Exists { - private \Spameri\Elastic\ClientProvider $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } public function execute( - string $index + string $index, ): bool { try { return $this->clientProvider->client()->indices()->exists( ( new \Spameri\ElasticQuery\Document( - $index + $index, ) - )->toArray() - ) + )->toArray(), + )->asBool() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/Get.php b/src/Model/Indices/Get.php index f027a33f..850fc0fe 100644 --- a/src/Model/Indices/Get.php +++ b/src/Model/Indices/Get.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class Get +readonly class Get { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -23,23 +16,20 @@ public function __construct( * @return array */ public function execute( - string $index + string $index, ): array { try { - /** @var array $result */ - $result = $this->clientProvider->client()->indices()->get( - ( - new \Spameri\ElasticQuery\Document( - $index - ) - )->toArray() - ) + return $this->clientProvider->client()->indices()->get( + ( + new \Spameri\ElasticQuery\Document( + $index, + ) + )->toArray(), + )->asArray() ; - return $result; - - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/GetFieldMapping.php b/src/Model/Indices/GetFieldMapping.php index cad9a7d0..947d8c04 100644 --- a/src/Model/Indices/GetFieldMapping.php +++ b/src/Model/Indices/GetFieldMapping.php @@ -2,24 +2,20 @@ namespace Spameri\Elastic\Model\Indices; -class GetFieldMapping +readonly class GetFieldMapping { - private \Spameri\Elastic\ClientProvider $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } public function execute( string $index, string $type = '_doc', - array $fields = [] + array $fields = [], ): array { try { @@ -32,13 +28,13 @@ public function execute( NULL, [ 'fields' => $fields, - ] + ], ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/GetMapping.php b/src/Model/Indices/GetMapping.php index ba3bbeac..1a2443fc 100644 --- a/src/Model/Indices/GetMapping.php +++ b/src/Model/Indices/GetMapping.php @@ -2,24 +2,14 @@ namespace Spameri\Elastic\Model\Indices; -class GetMapping +readonly class GetMapping { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -28,7 +18,7 @@ public function __construct( */ public function execute( string $index, - ?string $type = NULL + string|null $type = NULL, ): array { if ($type === NULL) { @@ -44,13 +34,13 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, NULL, - $type + $type, ) )->toArray(); - return $this->clientProvider->client()->indices()->getMapping($documentArray); + return $this->clientProvider->client()->indices()->getMapping($documentArray)->asArray(); - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/MoveAlias.php b/src/Model/Indices/MoveAlias.php index 7925686c..145f4cbc 100644 --- a/src/Model/Indices/MoveAlias.php +++ b/src/Model/Indices/MoveAlias.php @@ -2,17 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class MoveAlias +readonly class MoveAlias { - private \Spameri\Elastic\ClientProvider $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -35,19 +31,19 @@ public function execute(string $alias, string $indexFrom, string $indexTo): arra 'alias' => $alias, ], ], - ] + ], ), NULL, NULL, [ 'name' => $indexTo, - ] + ], ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/Open.php b/src/Model/Indices/Open.php index 2614d674..b9c9d2f1 100644 --- a/src/Model/Indices/Open.php +++ b/src/Model/Indices/Open.php @@ -2,32 +2,25 @@ namespace Spameri\Elastic\Model\Indices; -class Open +readonly class Open { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } public function execute( - string $index + string $index, ): bool { try { $result = $this->clientProvider->client()->indices()->open( ( new \Spameri\ElasticQuery\Document($index) - )->toArray() + )->toArray(), ) ; @@ -35,7 +28,7 @@ public function execute( return TRUE; } - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } diff --git a/src/Model/Indices/PutMapping.php b/src/Model/Indices/PutMapping.php index 9e56e430..93831652 100644 --- a/src/Model/Indices/PutMapping.php +++ b/src/Model/Indices/PutMapping.php @@ -2,24 +2,14 @@ namespace Spameri\Elastic\Model\Indices; -class PutMapping +readonly class PutMapping { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -31,7 +21,7 @@ public function execute( string $index, array $mapping, string $dynamic = 'false', - ?string $type = NULL + string|null $type = NULL, ): array { if ($type === NULL) { @@ -54,15 +44,15 @@ public function execute( [ 'properties' => $properties, 'dynamic' => $dynamic, - ] + ], ), - $type + $type, ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/PutSettings.php b/src/Model/Indices/PutSettings.php index eef25fd8..58662646 100644 --- a/src/Model/Indices/PutSettings.php +++ b/src/Model/Indices/PutSettings.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class PutSettings +readonly class PutSettings { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -25,7 +18,7 @@ public function __construct( */ public function execute( string $index, - array $settings + array $settings, ): array { try { @@ -33,13 +26,13 @@ public function execute( ( new \Spameri\ElasticQuery\Document( $index, - new \Spameri\ElasticQuery\Document\Body\Plain($settings) + new \Spameri\ElasticQuery\Document\Body\Plain($settings), ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Indices/RemoveAlias.php b/src/Model/Indices/RemoveAlias.php index d090d1c3..69a92d39 100644 --- a/src/Model/Indices/RemoveAlias.php +++ b/src/Model/Indices/RemoveAlias.php @@ -2,17 +2,13 @@ namespace Spameri\Elastic\Model\Indices; -class RemoveAlias +readonly class RemoveAlias { - private \Spameri\Elastic\ClientProvider $clientProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } @@ -31,19 +27,19 @@ public function execute(string $alias, string $index): array 'alias' => $alias, ], ], - ] + ], ), NULL, NULL, [ 'name' => $index, - ] + ], ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/InitializeIndex.php b/src/Model/InitializeIndex.php index 17401e7c..3da88eaf 100644 --- a/src/Model/InitializeIndex.php +++ b/src/Model/InitializeIndex.php @@ -2,29 +2,16 @@ namespace Spameri\Elastic\Model; -class InitializeIndex +readonly class InitializeIndex { - private \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider; - - private \Spameri\Elastic\Model\Indices\Get $get; - - private \Spameri\Elastic\Model\Indices\Create $create; - - private \Spameri\Elastic\Model\Indices\AddAlias $addAlias; - - public function __construct( - \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, - \Spameri\Elastic\Model\Indices\Get $get, - \Spameri\Elastic\Model\Indices\Create $create, - \Spameri\Elastic\Model\Indices\AddAlias $addAlias + private \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, + private \Spameri\Elastic\Model\Indices\Get $get, + private \Spameri\Elastic\Model\Indices\Create $create, + private \Spameri\Elastic\Model\Indices\AddAlias $addAlias, ) { - $this->dateTimeProvider = $dateTimeProvider; - $this->get = $get; - $this->create = $create; - $this->addAlias = $addAlias; } @@ -39,7 +26,8 @@ public function execute(\Spameri\Elastic\Settings\IndexConfigInterface $indexCon } catch (\Spameri\Elastic\Exception\ElasticSearch $exception) { $indexName = - $indexAlias . '-' + $indexAlias + . '-' . $this->dateTimeProvider->provide()->format(\Spameri\Elastic\Entity\Property\DateTime::INDEX_FORMAT); $this->create->execute($indexName, $indexConfig->provide()->toArray(), $indexAlias); diff --git a/src/Model/Insert.php b/src/Model/Insert.php index 4163a785..dc88ad54 100644 --- a/src/Model/Insert.php +++ b/src/Model/Insert.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class Insert +readonly class Insert { - /** - * @var \Spameri\Elastic\Model\Insert\PrepareEntityArray - */ - private $prepareEntityArray; - - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\Model\Insert\PrepareEntityArray $prepareEntityArray, - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\Model\Insert\PrepareEntityArray $prepareEntityArray, + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->prepareEntityArray = $prepareEntityArray; - $this->clientProvider = $clientProvider; - $this->versionProvider = $versionProvider; } @@ -35,9 +19,10 @@ public function __construct( * @throws \Spameri\Elastic\Exception\DocumentInsertFailed */ public function execute( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity, + \Spameri\Elastic\Entity\AbstractElasticEntity $entity, string $index, - ?string $type = NULL + string|null $type = NULL, + bool $hasSti = FALSE, ): string { if ($type === NULL) { @@ -48,7 +33,7 @@ public function execute( $type = NULL; } - $entityArray = $this->prepareEntityArray->prepare($entity); + $entityArray = $this->prepareEntityArray->prepare($entity, $hasSti); unset($entityArray['id']); try { @@ -58,13 +43,13 @@ public function execute( $index, new \Spameri\ElasticQuery\Document\Body\Plain($entityArray), $type, - $entity->id()->value() + $entity->id()->value(), ) - )->toArray() - ) + )->toArray(), + )->asArray() ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -73,19 +58,21 @@ public function execute( ( new \Spameri\ElasticQuery\Document($index) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } if (isset($response['created']) || isset($response['updated'])) { + $entity->id = new \Spameri\Elastic\Entity\Property\ElasticId($response['_id']); return $response['_id']; } if (isset($response['result']) && ($response['result'] === 'created' || $response['result'] === 'updated')) { + $entity->id = new \Spameri\Elastic\Entity\Property\ElasticId($response['_id']); return $response['_id']; } diff --git a/src/Model/Insert/PrepareEntityArray.php b/src/Model/Insert/PrepareEntityArray.php index 9ffcb3e8..00ee6a2c 100644 --- a/src/Model/Insert/PrepareEntityArray.php +++ b/src/Model/Insert/PrepareEntityArray.php @@ -5,17 +5,18 @@ class PrepareEntityArray { + public const ENTITY_CLASS = 'entityClass'; + /** - * @var \Spameri\Elastic\Model\ServiceLocatorInterface + * @var array */ - private $serviceLocator; + private array $insertedEntities; public function __construct( - \Spameri\Elastic\Model\ServiceLocatorInterface $serviceLocator + private readonly \Spameri\Elastic\Model\ServiceLocatorInterface $serviceLocator, ) { - $this->serviceLocator = $serviceLocator; } @@ -23,10 +24,19 @@ public function __construct( * @return array */ public function prepare( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\ElasticEntityInterface $entity, + bool $hasSti = false, ): array { - return $this->iterateVariables($entity->entityVariables()); + $this->insertedEntities = []; + $this->insertedEntities[$entity->id()->value()] = true; + + $entityVariables = $entity->entityVariables(); + if ($hasSti === true) { + $entityVariables[self::ENTITY_CLASS] = $entity::class; + } + + return $this->iterateVariables($entityVariables); } @@ -35,14 +45,25 @@ public function prepare( * @return array */ public function iterateVariables( - array $variables + array $variables, ): array { $preparedArray = []; foreach ($variables as $key => $property) { - if ($property instanceof \Spameri\Elastic\Entity\ElasticEntityInterface) { - $preparedArray[$key] = $this->serviceLocator->locate($property)->insert($property); + if ($property instanceof \Spameri\Elastic\Entity\AbstractElasticEntity) { + if (\in_array($property->id->value(), $this->insertedEntities, true)) { + $preparedArray[$key] = $property->id()->value(); + + } else { + $preparedArray[$key] = $this->serviceLocator->locate($property)->insert($property); + $this->insertedEntities[$property->id()->value()] = true; + } + + } elseif ($property instanceof \Spameri\Elastic\Entity\ElasticEntityInterface) { + throw new \Spameri\Elastic\Exception\DocumentInsertFailed( + 'Entity ' . $property::class . ' must be extend AbstractElasticEntity.', + ); } elseif ($property instanceof \Spameri\Elastic\Entity\EntityInterface) { $preparedArray[$key] = $this->iterateVariables($property->entityVariables()); @@ -50,12 +71,21 @@ public function iterateVariables( } elseif ($property instanceof \Spameri\Elastic\Entity\ValueInterface) { $preparedArray[$key] = $property->value(); + } elseif ($property instanceof \Spameri\Elastic\Entity\Collection\STIEntityCollection) { + $preparedArray[$key] = []; + foreach ($property as $item) { + $iterateVariables = $this->iterateVariables($item->entityVariables()); + $iterateVariables[self::ENTITY_CLASS] = $item::class; + $preparedArray[$key][] = $iterateVariables; + } + } elseif ($property instanceof \Spameri\Elastic\Entity\EntityCollectionInterface) { $preparedArray[$key] = []; /** @var \Spameri\Elastic\Entity\EntityInterface $item */ foreach ($property as $item) { $preparedArray[$key][] = $this->iterateVariables($item->entityVariables()); } + // TODO kolekce bez klíčů } elseif ($property instanceof \Spameri\Elastic\Entity\ElasticEntityCollectionInterface) { $preparedArray[$key] = []; @@ -63,9 +93,15 @@ public function iterateVariables( $preparedArray[$key] = $property->elasticIds(); } else { - /** @var \Spameri\Elastic\Entity\ElasticEntityInterface $item */ + /** @var \Spameri\Elastic\Entity\AbstractElasticEntity $item */ foreach ($property as $item) { - $preparedArray[$key][] = $this->serviceLocator->locate($item)->insert($item); + if (\in_array($item->id()->value(), $this->insertedEntities)) { + $preparedArray[$key][] = $item->id()->value(); + + } else { + $preparedArray[$key][] = $this->serviceLocator->locate($item)->insert($item); + $this->insertedEntities[$item->id()->value()] = true; + } } } @@ -86,7 +122,7 @@ public function iterateVariables( || \is_int($property) || \is_bool($property) || \is_float($property) - || $property === NULL + || $property === null ) { $preparedArray[$key] = $property; @@ -99,15 +135,20 @@ public function iterateVariables( } elseif ($property instanceof \DateTime) { $preparedArray[$key] = $property->format(\Spameri\Elastic\Entity\Property\DateTime::FORMAT); + } elseif ( + $property instanceof \BackedEnum + ) { + $preparedArray[$key] = $property->value; + } else { if (\is_object($property)) { throw new \Spameri\Elastic\Exception\EntityIsNotValid( - 'Property ' . $key . ' in ' . \get_class($property) . ' is not supported.' + 'Property ' . $key . ' in ' . $property::class . ' is not supported.', ); } throw new \Spameri\Elastic\Exception\EntityIsNotValid( - 'Property ' . $key . ' with value' . $property . ' is not supported.' + 'Property ' . $key . ' with value' . $property . ' is not supported.', ); } } diff --git a/src/Model/InsertMultiple.php b/src/Model/InsertMultiple.php index c38fd7d4..2b8e7a32 100644 --- a/src/Model/InsertMultiple.php +++ b/src/Model/InsertMultiple.php @@ -2,38 +2,16 @@ namespace Spameri\Elastic\Model; -class InsertMultiple +readonly class InsertMultiple { - /** - * @var \Spameri\Elastic\Model\Insert\PrepareEntityArray - */ - private $prepareEntityArray; - - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\Model\Insert\PrepareEntityArray $prepareEntityArray, - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private \Spameri\Elastic\Model\Insert\PrepareEntityArray $prepareEntityArray, + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->prepareEntityArray = $prepareEntityArray; - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -44,7 +22,7 @@ public function __construct( public function execute( \Spameri\Elastic\Entity\ElasticEntityCollectionInterface $entityCollection, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultBulk { if ($type === NULL) { @@ -74,7 +52,7 @@ public function execute( try { $response = $this->clientProvider->client()->bulk($document->toArray()); - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -83,14 +61,14 @@ public function execute( ( new \Spameri\ElasticQuery\Document($index) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } - return $this->resultMapper->mapBulkResult($response); + return $this->resultMapper->mapBulkResult($response->asArray()); } } diff --git a/src/Model/RestoreIndex.php b/src/Model/RestoreIndex.php index f540569f..b913c5d0 100644 --- a/src/Model/RestoreIndex.php +++ b/src/Model/RestoreIndex.php @@ -5,27 +5,18 @@ class RestoreIndex { - /** - * @var \Symfony\Component\Console\Output\OutputInterface - */ - private $output; - - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; + private \Symfony\Component\Console\Output\OutputInterface $output; public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider + private readonly \Spameri\Elastic\ClientProvider $clientProvider, ) { - $this->clientProvider = $clientProvider; } public function setOutput( - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): void { $this->output = $output; @@ -34,7 +25,7 @@ public function setOutput( public function execute( string $filename, - int $step + int $step, ): void { $this->output->writeln('Starting import.'); @@ -52,9 +43,9 @@ public function execute( $this->clientProvider->client()->bulk( ( new \Spameri\ElasticQuery\Document\Bulk( - [$bulkData] + [$bulkData], ) - )->toArray() + )->toArray(), ) ; $bulkData = ''; diff --git a/src/Model/Scroll.php b/src/Model/Scroll.php index a291f6fe..47a62dc4 100644 --- a/src/Model/Scroll.php +++ b/src/Model/Scroll.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class Scroll +readonly class Scroll { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -36,7 +20,7 @@ public function __construct( public function execute( \Spameri\ElasticQuery\ElasticQuery $elasticQuery, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSearch { if ($type === NULL) { @@ -58,11 +42,11 @@ public function execute( NULL, [ 'scroll' => $elasticQuery->options()->scroll(), - ] + ], ) ) - ->toArray() - ) + ->toArray(), + )->asArray() ; if (isset($result['_scroll_id'])) { @@ -70,7 +54,7 @@ public function execute( } else { throw new \Spameri\Elastic\Exception\ScrollNotInitialized( - 'ElasticSearch did not return scroll id.' + 'ElasticSearch did not return scroll id.', ); } @@ -85,15 +69,15 @@ public function execute( [ 'scroll' => $elasticQuery->options()->scroll(), 'scroll_id' => $elasticQuery->options()->scrollId(), - ] + ], ) ) - ->toArray() - ) + ->toArray(), + )->asArray() ; } - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } @@ -102,7 +86,7 @@ public function execute( public function closeScroll( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): void { try { @@ -115,14 +99,14 @@ public function closeScroll( NULL, [ 'scroll_id' => $elasticQuery->options()->scrollId(), - ] + ], ) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } } diff --git a/src/Model/Search.php b/src/Model/Search.php index 66b95ba8..fd38d12d 100644 --- a/src/Model/Search.php +++ b/src/Model/Search.php @@ -2,31 +2,15 @@ namespace Spameri\Elastic\Model; -class Search +readonly class Search { - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\ElasticQuery\Response\ResultMapper - */ - private $resultMapper; - - private VersionProvider $versionProvider; - - public function __construct( - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, - VersionProvider $versionProvider + private \Spameri\Elastic\ClientProvider $clientProvider, + private \Spameri\ElasticQuery\Response\ResultMapper $resultMapper, + private VersionProvider $versionProvider, ) { - $this->clientProvider = $clientProvider; - $this->resultMapper = $resultMapper; - $this->versionProvider = $versionProvider; } @@ -36,7 +20,7 @@ public function __construct( public function execute( \Spameri\ElasticQuery\ElasticQuery $elasticQuery, string $index, - ?string $type = NULL + string|null $type = NULL, ): \Spameri\ElasticQuery\Response\ResultSearch { if ($type === NULL) { @@ -53,18 +37,18 @@ public function execute( new \Spameri\ElasticQuery\Document( $index, new \Spameri\ElasticQuery\Document\Body\Plain($elasticQuery->toArray()), - $type + $type, ) ) - ->toArray() + ->toArray(), ) ; - } catch (\Elasticsearch\Common\Exceptions\ElasticsearchException $exception) { + } catch (\Elastic\Elasticsearch\Exception\ElasticsearchException $exception) { throw new \Spameri\Elastic\Exception\ElasticSearch($exception->getMessage()); } - return $this->resultMapper->mapSearchResults($result); + return $this->resultMapper->mapSearchResults($result->asArray()); } } diff --git a/src/Model/ServiceInterface.php b/src/Model/ServiceInterface.php index e7c2d84d..7b19c1c6 100644 --- a/src/Model/ServiceInterface.php +++ b/src/Model/ServiceInterface.php @@ -6,32 +6,32 @@ interface ServiceInterface { public function insert( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\AbstractElasticEntity $entity, ): string; public function get( - \Spameri\Elastic\Entity\Property\ElasticId $id + \Spameri\Elastic\Entity\Property\ElasticId $id, ): \Spameri\Elastic\Entity\ElasticEntityInterface; public function getBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityInterface; public function getAllBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface; public function delete( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id + \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, ): bool; public function aggregate( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\ElasticQuery\Response\ResultSearch; } diff --git a/src/Model/ServiceLocator.php b/src/Model/ServiceLocator.php index 43c84a9d..0839ea73 100644 --- a/src/Model/ServiceLocator.php +++ b/src/Model/ServiceLocator.php @@ -6,21 +6,21 @@ class ServiceLocator implements ServiceLocatorInterface { /** - * @var \Nette\DI\Container + * @var array */ - private $container; + private array $services; public function __construct( - \Nette\DI\Container $container + private readonly \Nette\DI\Container $container, ) { - $this->container = $container; + $this->services = $container->findByType(\Spameri\Elastic\Model\ServiceInterface::class); } public function locate( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\ElasticEntityInterface $entity, ): \Spameri\Elastic\Model\ServiceInterface { $entityName = \get_class($entity); @@ -34,15 +34,36 @@ public function locate( public function locateByEntityClass( - string $entityClass + string $entityClass, ): \Spameri\Elastic\Model\ServiceInterface { $serviceName = \str_replace('Entity', 'Model', $entityClass . 'Service'); + $serviceName = \str_replace('Interface', '', $serviceName); + $serviceName = \str_replace('Abstract', '', $serviceName); + $serviceName = \str_replace('Trait', '', $serviceName); + /** @var \Spameri\Elastic\Model\ServiceInterface $service */ $service = $this->container->getByType($serviceName); return $service; } + + public function locateByIndex(string $index): \Spameri\Elastic\Model\ServiceInterface|null + { + foreach ($this->services as $serviceType) { + $service = $this->container->getService($serviceType); + if (($service instanceof \Spameri\Elastic\Model\AbstractBaseService) === false) { + continue; + } + + if ($service->index === $index) { + return $service; + } + } + + return null; + } + } diff --git a/src/Model/ServiceLocatorInterface.php b/src/Model/ServiceLocatorInterface.php index 9fd86000..cdf30ea4 100644 --- a/src/Model/ServiceLocatorInterface.php +++ b/src/Model/ServiceLocatorInterface.php @@ -6,12 +6,12 @@ interface ServiceLocatorInterface { public function locate( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\ElasticEntityInterface $entity, ): \Spameri\Elastic\Model\ServiceInterface; public function locateByEntityClass( - string $entityClass + string $entityClass, ): \Spameri\Elastic\Model\ServiceInterface; } diff --git a/src/Model/TypeToNewIndex/DocumentMigrateStatus.php b/src/Model/TypeToNewIndex/DocumentMigrateStatus.php index 4ffda67e..cbf12cde 100644 --- a/src/Model/TypeToNewIndex/DocumentMigrateStatus.php +++ b/src/Model/TypeToNewIndex/DocumentMigrateStatus.php @@ -8,12 +8,12 @@ class DocumentMigrateStatus /** * @var array */ - private $storage = []; + private array $storage = []; public function add( string $documentId, - int $version + int $version, ): void { $this->storage[$documentId] = $version; @@ -22,7 +22,7 @@ public function add( public function isChanged( string $documentId, - int $version + int $version, ): bool { if ( ! isset($this->storage[$documentId])) { diff --git a/src/Model/TypeToNewIndex/Migrate.php b/src/Model/TypeToNewIndex/Migrate.php index 3bcdf08e..38e2cc6b 100644 --- a/src/Model/TypeToNewIndex/Migrate.php +++ b/src/Model/TypeToNewIndex/Migrate.php @@ -5,105 +5,29 @@ class Migrate { - /** - * @var \Symfony\Component\Console\Output\OutputInterface $output - */ - private $output; - - /** - * @var \Spameri\Elastic\Model\TypeToNewIndex\DocumentMigrateStatus - */ - private $documentMigrateStatus; - - /** - * @var \Spameri\Elastic\ClientProvider - */ - private $clientProvider; - - /** - * @var \Spameri\Elastic\Provider\DateTimeProvider - */ - private $dateTimeProvider; - - /** - * @var \Spameri\Elastic\Model\Delete - */ - private $delete; - - /** - * @var \Spameri\Elastic\Model\Get - */ - private $get; - - /** - * @var \Spameri\Elastic\Model\Indices\Close - */ - private $close; - - /** - * @var \Spameri\Elastic\Model\Indices\GetMapping - */ - private $getMapping; - - /** - * @var \Spameri\Elastic\Model\Indices\PutMapping - */ - private $putMapping; - - /** - * @var \Spameri\Elastic\Model\Search - */ - private $search; - - /** - * @var \Spameri\Elastic\Model\Indices\Create - */ - private $create; - - /** - * @var \Spameri\Elastic\Model\Indices\Get - */ - private $indicesGet; - - private \Spameri\Elastic\Model\Indices\AddAlias $addAlias; - - private \Spameri\Elastic\Model\VersionProvider $versionProvider; - + private \Symfony\Component\Console\Output\OutputInterface $output; public function __construct( - DocumentMigrateStatus $documentMigrateStatus, - \Spameri\Elastic\ClientProvider $clientProvider, - \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, - \Spameri\Elastic\Model\Delete $delete, - \Spameri\Elastic\Model\Get $get, - \Spameri\Elastic\Model\Indices\Close $close, - \Spameri\Elastic\Model\Indices\GetMapping $getMapping, - \Spameri\Elastic\Model\Indices\PutMapping $putMapping, - \Spameri\Elastic\Model\Search $search, - \Spameri\Elastic\Model\Indices\Create $create, - \Spameri\Elastic\Model\Indices\Get $indicesGet, - \Spameri\Elastic\Model\Indices\AddAlias $addAlias, - \Spameri\Elastic\Model\VersionProvider $versionProvider + private readonly DocumentMigrateStatus $documentMigrateStatus, + private readonly \Spameri\Elastic\ClientProvider $clientProvider, + private readonly \Spameri\Elastic\Provider\DateTimeProvider $dateTimeProvider, + private readonly \Spameri\Elastic\Model\Delete $delete, + private readonly \Spameri\Elastic\Model\Get $get, + private readonly \Spameri\Elastic\Model\Indices\Close $close, + private readonly \Spameri\Elastic\Model\Indices\GetMapping $getMapping, + private readonly \Spameri\Elastic\Model\Indices\PutMapping $putMapping, + private readonly \Spameri\Elastic\Model\Search $search, + private readonly \Spameri\Elastic\Model\Indices\Create $create, + private readonly \Spameri\Elastic\Model\Indices\Get $indicesGet, + private readonly \Spameri\Elastic\Model\Indices\AddAlias $addAlias, + private readonly \Spameri\Elastic\Model\VersionProvider $versionProvider, ) { - $this->documentMigrateStatus = $documentMigrateStatus; - $this->clientProvider = $clientProvider; - $this->dateTimeProvider = $dateTimeProvider; - $this->delete = $delete; - $this->get = $get; - $this->close = $close; - $this->getMapping = $getMapping; - $this->putMapping = $putMapping; - $this->search = $search; - $this->create = $create; - $this->indicesGet = $indicesGet; - $this->addAlias = $addAlias; - $this->versionProvider = $versionProvider; } public function setOutput( - \Symfony\Component\Console\Output\OutputInterface $output + \Symfony\Component\Console\Output\OutputInterface $output, ): void { $this->output = $output; @@ -111,15 +35,15 @@ public function setOutput( /** - * @throws \Elasticsearch\Common\Exceptions\ElasticsearchException + * @throws \Elastic\Elasticsearch\Exception\ElasticsearchException */ public function execute( string $indexFrom, string $typeFrom, string $indexTo, string $aliasTo, - ?string $typeTo, - bool $allowClose + string|null $typeTo, + bool $allowClose, ): void { // 1. Close index @@ -199,7 +123,7 @@ public function execute( $response = $this->get->execute( new \Spameri\Elastic\Entity\Property\ElasticId((string) $documentId), $indexFrom, - $typeFrom + $typeFrom, ); if ($this->documentMigrateStatus->isChanged((string) $documentId, $response->hit()->version())) { @@ -232,7 +156,7 @@ public function execute( // 9. Write info $this->output->writeln( 'Migration done. All old data remains in old index: ' . $indexFrom . ' with type: ' . $typeFrom - . ' it is recommended to manually delete data after this command' + . ' it is recommended to manually delete data after this command', ); // 10. Done @@ -240,14 +164,14 @@ public function execute( /** - * @throws \Elasticsearch\Common\Exceptions\ElasticsearchException + * @throws \Elastic\Elasticsearch\Exception\ElasticsearchException */ public function processHit( string $indexTo, - ?string $typeTo, + string|null $typeTo, string $indexFrom, \Spameri\ElasticQuery\Response\Result\Hit $hit, - bool $allowClose + bool $allowClose, ): void { if ($this->versionProvider->provide() >= \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7) { @@ -260,9 +184,9 @@ public function processHit( $indexTo, new \Spameri\ElasticQuery\Document\Body\Plain($hit->source()), $typeTo, - $hit->id() + $hit->id(), ) - )->toArray() + )->toArray(), ) ; @@ -273,7 +197,7 @@ public function processHit( if ($allowClose === TRUE) { $this->delete->execute( new \Spameri\Elastic\Entity\Property\ElasticId($hit->id()), - $indexFrom + $indexFrom, ); } } diff --git a/src/Model/VersionProvider.php b/src/Model/VersionProvider.php index 8ed8fc67..93ebc951 100644 --- a/src/Model/VersionProvider.php +++ b/src/Model/VersionProvider.php @@ -2,17 +2,13 @@ namespace Spameri\Elastic\Model; -class VersionProvider +readonly class VersionProvider { - private int $versionNumber; - - public function __construct( - int $versionNumber = \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7 + private int $versionNumber = \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7, ) { - $this->versionNumber = $versionNumber; } diff --git a/src/Provider/DateTimeProvider.php b/src/Provider/DateTimeProvider.php index 8bc5d5f2..6f1e46ab 100644 --- a/src/Provider/DateTimeProvider.php +++ b/src/Provider/DateTimeProvider.php @@ -2,20 +2,13 @@ namespace Spameri\Elastic\Provider; -class DateTimeProvider +readonly class DateTimeProvider { - /** - * @var \DateTimeImmutable - */ - private $constant; - - public function __construct( - \DateTimeImmutable $constant + private \DateTimeImmutable $constant, ) { - $this->constant = $constant; } diff --git a/src/Reflection/Reflection.php b/src/Reflection/Reflection.php new file mode 100644 index 00000000..f5b93d63 --- /dev/null +++ b/src/Reflection/Reflection.php @@ -0,0 +1,37 @@ + + */ + public function getProperties(\ReflectionClass $class): array + { + return $class->getProperties(); + } + + + public function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType|null + { + $reflectionType = $property->getType(); + + if ($reflectionType instanceof \ReflectionNamedType) { + return $reflectionType; + } + + return null; + } +} diff --git a/src/Settings.php b/src/Settings.php index 08980cd4..9df25984 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -2,37 +2,18 @@ namespace Spameri\Elastic; -class Settings +readonly class Settings { - /** - * @var string - */ - private $host; - - /** - * @var int - */ - private $port; - - /** - * @var array - */ - private $headers; - - /** * @param array $headers */ public function __construct( - string $host, - int $port, - array $headers + private string $host, + private int $port, + private array $headers, ) { - $this->host = $host; - $this->port = $port; - $this->headers = $headers; } diff --git a/src/Settings/AbstractIndexConfig.php b/src/Settings/AbstractIndexConfig.php new file mode 100644 index 00000000..a956bb12 --- /dev/null +++ b/src/Settings/AbstractIndexConfig.php @@ -0,0 +1,29 @@ +entityClass; + } + + public function indexName(): string + { + return $this->index; + } + +} diff --git a/src/Settings/IndexConfigInterface.php b/src/Settings/IndexConfigInterface.php index e3ff8574..bcfc5d0f 100644 --- a/src/Settings/IndexConfigInterface.php +++ b/src/Settings/IndexConfigInterface.php @@ -7,4 +7,7 @@ interface IndexConfigInterface public function provide(): \Spameri\ElasticQuery\Mapping\Settings; + public function entityClass(): array; + + public function indexName(): string; } diff --git a/src/Settings/NeonSettingsProvider.php b/src/Settings/NeonSettingsProvider.php index 36950cd5..8e69a5e7 100644 --- a/src/Settings/NeonSettingsProvider.php +++ b/src/Settings/NeonSettingsProvider.php @@ -2,37 +2,18 @@ namespace Spameri\Elastic\Settings; -class NeonSettingsProvider implements \Spameri\Elastic\SettingsProviderInterface +readonly class NeonSettingsProvider implements \Spameri\Elastic\SettingsProviderInterface { - /** - * @var string - */ - private $host; - - /** - * @var int - */ - private $port; - - /** - * @var array - */ - private $headers; - - /** * @param array $headers */ public function __construct( - string $host, - int $port, - array $headers = [] + private string $host, + private int $port, + private array $headers = [], ) { - $this->host = $host; - $this->port = $port; - $this->headers = $headers; } @@ -41,7 +22,7 @@ public function provide(): \Spameri\Elastic\Settings return new \Spameri\Elastic\Settings( $this->host, $this->port, - $this->headers + $this->headers, ); } diff --git a/tests/SpameriTests/Elastic/Data/Config/Common.neon b/tests/SpameriTests/Elastic/Data/Config/Common.neon index 295e9082..ef391b66 100644 --- a/tests/SpameriTests/Elastic/Data/Config/Common.neon +++ b/tests/SpameriTests/Elastic/Data/Config/Common.neon @@ -16,7 +16,7 @@ parameters: services: elastic.person.personMapping: - factory: SpameriTests\Elastic\Data\Model\PersonMapping(%elasticSearch.personIndex%) + factory: SpameriTests\Elastic\Data\Model\PersonMapping(%elasticSearch.personIndex%, SpameriTests\Elastic\Data\Entity\Person::class) elastic.person.personFactory: factory: SpameriTests\Elastic\Data\Model\PersonFactory @@ -35,7 +35,7 @@ services: ######################################################################################################################## elastic.video.videoMapping: - factory: SpameriTests\Elastic\Data\Model\VideoMapping(%elasticSearch.personIndex%) + factory: SpameriTests\Elastic\Data\Model\VideoMapping(%elasticSearch.personIndex%, SpameriTests\Elastic\Data\Entity\Video::class) elastic.video.videoFactory: factory: SpameriTests\Elastic\Data\Model\VideoFactory diff --git a/tests/SpameriTests/Elastic/Data/Entity/Person.php b/tests/SpameriTests/Elastic/Data/Entity/Person.php index cb0e5bcf..52ee23d4 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Person.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Person.php @@ -2,166 +2,28 @@ namespace SpameriTests\Elastic\Data\Entity; -class Person implements \Spameri\Elastic\Entity\ElasticEntityInterface +class Person extends \Spameri\Elastic\Entity\AbstractElasticEntity { - /** - * @var \Spameri\Elastic\Entity\Property\ElasticIdInterface - */ - private $id; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Identification - */ - private $identification; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Name - */ - private $name; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Description - */ - private $description; - - /** - * @var \Spameri\Elastic\Entity\Property\Date|NULL - */ - private $birth; - - /** - * @var \Spameri\Elastic\Entity\Property\Date|NULL - */ - private $death; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Name - */ - private $alias; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic - */ - private $characters; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic - */ - private $jobs; - public function __construct( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, - \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, - \SpameriTests\Elastic\Data\Entity\Property\Name $name, - \SpameriTests\Elastic\Data\Entity\Property\Description $description, - ?\Spameri\Elastic\Entity\Property\Date $birth, - ?\Spameri\Elastic\Entity\Property\Date $death, - \SpameriTests\Elastic\Data\Entity\Property\Name $alias, - \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic $characters, - \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic $jobs + #[\Spameri\Elastic\Mapping\Entity(class: \Spameri\Elastic\Entity\Property\ElasticId::class)] + public \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, + public \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, + public \SpameriTests\Elastic\Data\Entity\Property\Name $name, + public \SpameriTests\Elastic\Data\Entity\Property\Description $description, + public \Spameri\Elastic\Entity\Property\Date|null $birth, + public \Spameri\Elastic\Entity\Property\Date|null $death, + public \SpameriTests\Elastic\Data\Entity\Property\Name $alias, + + #[\Spameri\Elastic\Mapping\Collection] + public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $characters, + + #[\Spameri\Elastic\Mapping\Collection] + public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $jobs, ) { - $this->id = $id; - $this->identification = $identification; - $this->name = $name; - $this->description = $description; - $this->birth = $birth; - $this->death = $death; - $this->alias = $alias; - $this->characters = $characters; - $this->jobs = $jobs; - } - - - public function entityVariables(): array - { - return \get_object_vars($this); - } - - - public function id(): \Spameri\Elastic\Entity\Property\ElasticIdInterface - { - return $this->id; - } - - - public function identification(): \SpameriTests\Elastic\Data\Entity\Video\Identification - { - return $this->identification; - } - - - public function name(): \SpameriTests\Elastic\Data\Entity\Property\Name - { - return $this->name; - } - - - public function rename(\SpameriTests\Elastic\Data\Entity\Property\Name $name): void - { - $this->name = $name; - } - - - public function description(): \SpameriTests\Elastic\Data\Entity\Property\Description - { - return $this->description; - } - - - public function changeDescription(\SpameriTests\Elastic\Data\Entity\Property\Description $description): void - { - $this->description = $description; - } - - - public function birth(): ?\Spameri\Elastic\Entity\Property\Date - { - return $this->birth; - } - - - public function setBirth(?\Spameri\Elastic\Entity\Property\Date $birth): void - { - $this->birth = $birth; - } - - - public function death(): ?\Spameri\Elastic\Entity\Property\Date - { - return $this->death; - } - - - public function setDeath(?\Spameri\Elastic\Entity\Property\Date $death): void - { - $this->death = $death; - } - - - public function alias(): \SpameriTests\Elastic\Data\Entity\Property\Name - { - return $this->alias; - } - - - public function setAlias(\SpameriTests\Elastic\Data\Entity\Property\Name $alias): void - { - $this->alias = $alias; - } - - - public function characters(): \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic - { - return $this->characters; - } - - - public function jobs(): \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic - { - return $this->jobs; + parent::__construct($id); } } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Person/Character.php b/tests/SpameriTests/Elastic/Data/Entity/Person/Character.php index 48fb5a9e..376933b3 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Person/Character.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Person/Character.php @@ -5,52 +5,15 @@ class Character implements \Spameri\Elastic\Entity\EntityInterface { - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\ImdbId - */ - private $id; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\ImdbId|null - */ - private $episode; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Name - */ - private $name; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Identification - */ - private $identification; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Description - */ - private $biography; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Name - */ - private $alias; - - public function __construct( - \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode, - \SpameriTests\Elastic\Data\Entity\Property\Name $name, - \SpameriTests\Elastic\Data\Entity\Property\Name $alias, - \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, - \SpameriTests\Elastic\Data\Entity\Property\Description $biography + public string $id, + public \SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode, + public \SpameriTests\Elastic\Data\Entity\Property\Name $name, + public \SpameriTests\Elastic\Data\Entity\Property\Name $alias, + public \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, + public \SpameriTests\Elastic\Data\Entity\Property\Description $biography, ) { - $this->id = $id; - $this->episode = $episode; - $this->name = $name; - $this->identification = $identification; - $this->biography = $biography; - $this->alias = $alias; } @@ -61,62 +24,8 @@ public function entityVariables(): array public function key(): string - { - return (string) $this->id->value(); - } - - - public function id(): \SpameriTests\Elastic\Data\Entity\Property\ImdbId { return $this->id; } - - public function episode(): ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId - { - return $this->episode; - } - - - public function setEpisode(?\SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode): void - { - $this->episode = $episode; - } - - - public function name(): \SpameriTests\Elastic\Data\Entity\Property\Name - { - return $this->name; - } - - - public function setName(\SpameriTests\Elastic\Data\Entity\Property\Name $name): void - { - $this->name = $name; - } - - - public function alias(): \SpameriTests\Elastic\Data\Entity\Property\Name - { - return $this->alias; - } - - - public function setAlias(\SpameriTests\Elastic\Data\Entity\Property\Name $alias): void - { - $this->alias = $alias; - } - - - public function identification(): \SpameriTests\Elastic\Data\Entity\Video\Identification - { - return $this->identification; - } - - - public function biography(): \SpameriTests\Elastic\Data\Entity\Property\Description - { - return $this->biography; - } - } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Person/CharacterCollectionElastic.php b/tests/SpameriTests/Elastic/Data/Entity/Person/CharacterCollectionElastic.php index 0bb546d4..2601ff54 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Person/CharacterCollectionElastic.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Person/CharacterCollectionElastic.php @@ -7,29 +7,28 @@ class CharacterCollectionElastic extends \Spameri\Elastic\Entity\Collection\Abst public function character( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode = NULL + \SpameriTests\Elastic\Data\Entity\Property\ImdbId|null $episode = NULL, ): Character { /** @var \SpameriTests\Elastic\Data\Entity\Person\Character $character */ foreach ($this->collection() as $character) { if ($episode) { if ( - $character->id()->value() === $id->value() - && $character->episode() - && $character->episode()->value() === $episode->value() + $character->id === $id->value() + && $character->episode->value() === $episode->value() ) { return $character; } } else { - if ($character->id()->value() === $id->value()) { + if ($character->id === $id->value()) { return $character; } } } throw new \Nette\InvalidStateException( - 'Character in video: ' . $id->value() . ' not found.' + 'Character in video: ' . $id->value() . ' not found.', ); } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Person/Job.php b/tests/SpameriTests/Elastic/Data/Entity/Person/Job.php index a62c8e53..46656c91 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Person/Job.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Person/Job.php @@ -37,7 +37,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Name $name, \SpameriTests\Elastic\Data\Entity\Property\Description $description, - ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode + \SpameriTests\Elastic\Data\Entity\Property\ImdbId|null $episode, ) { $this->id = $id; @@ -89,7 +89,7 @@ public function id(): \SpameriTests\Elastic\Data\Entity\Property\ImdbId } - public function episode(): ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId + public function episode(): \SpameriTests\Elastic\Data\Entity\Property\ImdbId|null { return $this->episode; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Person/JobCollectionElastic.php b/tests/SpameriTests/Elastic/Data/Entity/Person/JobCollectionElastic.php index 6391434c..5fee11eb 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Person/JobCollectionElastic.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Person/JobCollectionElastic.php @@ -7,7 +7,7 @@ class JobCollectionElastic extends \Spameri\Elastic\Entity\Collection\AbstractEn public function job( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdbId, - ?\SpameriTests\Elastic\Data\Entity\Property\ImdbId $episode = NULL + \SpameriTests\Elastic\Data\Entity\Property\ImdbId|null $episode = NULL, ): Job { /** @var \SpameriTests\Elastic\Data\Entity\Person\Job $job */ @@ -29,7 +29,7 @@ public function job( } throw new \Nette\InvalidStateException( - 'Job in video: ' . $imdbId->value() . ' not found.' + 'Job in video: ' . $imdbId->value() . ' not found.', ); } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/CountryShort.php b/tests/SpameriTests/Elastic/Data/Entity/Property/CountryShort.php index f8eaf388..d228c5ce 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/CountryShort.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/CountryShort.php @@ -12,7 +12,7 @@ class CountryShort implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value === '' || $value === NULL) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/Description.php b/tests/SpameriTests/Elastic/Data/Entity/Property/Description.php index e0bde170..e8083f08 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/Description.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/Description.php @@ -12,14 +12,14 @@ class Description implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $description + string|null $value, ) { - $this->value = $description; + $this->value = $value; } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/ElasticIdCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Property/ElasticIdCollection.php index 50176fbf..d80d6cfc 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/ElasticIdCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/ElasticIdCollection.php @@ -12,7 +12,7 @@ class ElasticIdCollection implements \Spameri\Elastic\Entity\ValueCollectionInte public function __construct( - \Spameri\Elastic\Entity\Property\ElasticIdInterface ...$collection + \Spameri\Elastic\Entity\Property\ElasticIdInterface ...$collection, ) { $this->collection = $collection; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbId.php b/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbId.php index 06be7bb6..54767faf 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbId.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbId.php @@ -5,28 +5,14 @@ class ImdbId implements \Spameri\Elastic\Entity\ValueInterface { - /** - * @var int - */ - private $value; - - public function __construct( - int $value + private string $value, ) { - if ($value < 1) { - throw new \InvalidArgumentException(); - } - if ($value > 99999999) { - throw new \InvalidArgumentException(); - } - - $this->value = $value; } - public function value(): int + public function value(): string { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbIdCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbIdCollection.php index 2fcee027..356e1f8e 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbIdCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/ImdbIdCollection.php @@ -12,7 +12,7 @@ class ImdbIdCollection implements \Spameri\Elastic\Entity\ValueCollectionInterfa public function __construct( - ImdbId ...$collection + ImdbId ...$collection, ) { $this->collection = []; @@ -23,7 +23,7 @@ public function __construct( public function add( - ImdbId $imdbId + ImdbId $imdbId, ): void { $this->collection[$imdbId->value()] = $imdbId; @@ -31,8 +31,8 @@ public function add( public function find( - ImdbId $imdbId - ): ?ImdbId + ImdbId $imdbId, + ): ImdbId|null { foreach ($this->collection as $value) { if ($imdbId->value() === $value->value()) { @@ -50,7 +50,7 @@ public function keys(): array } - public function first(): ?ImdbId + public function first(): ImdbId|null { $first = \reset($this->collection); diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/Name.php b/tests/SpameriTests/Elastic/Data/Entity/Property/Name.php index 43935a35..a0ceb943 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/Name.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/Name.php @@ -12,7 +12,7 @@ class Name implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $value + string $value, ) { if (\strlen($value) <= 0) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/Text.php b/tests/SpameriTests/Elastic/Data/Entity/Property/Text.php index 746f3a3d..3746528d 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/Text.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/Text.php @@ -12,7 +12,7 @@ class Text implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $value + string $value, ) { $this->value = $value; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/Url.php b/tests/SpameriTests/Elastic/Data/Entity/Property/Url.php index 6e6ed6cf..0fa9c198 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/Url.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/Url.php @@ -12,7 +12,7 @@ class Url implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $value + string $value, ) { if ( ! \Nette\Utils\Validators::isUrl($value)) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Property/Year.php b/tests/SpameriTests/Elastic/Data/Entity/Property/Year.php index ab721446..184eee57 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Property/Year.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Property/Year.php @@ -12,7 +12,7 @@ class Year implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - int $year + int $year, ) { if ($year < 1800) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video.php b/tests/SpameriTests/Elastic/Data/Entity/Video.php index b9635304..e271c7a1 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video.php @@ -2,184 +2,27 @@ namespace SpameriTests\Elastic\Data\Entity; -class Video implements \Spameri\Elastic\Entity\ElasticEntityInterface +class Video extends \Spameri\Elastic\Entity\AbstractElasticEntity { - /** - * @var \Spameri\Elastic\Entity\Property\ElasticIdInterface - */ - private $id; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Identification - */ - private $identification; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Name - */ - private $name; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\Year - */ - private $year; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Technical - */ - private $technical; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Story - */ - private $story; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Details - */ - private $details; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\HighLights - */ - private $highLights; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\Connections - */ - private $connections; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection - */ - private $season; - - /** - * @var \SpameriTests\Elastic\Data\Entity\Video\People - */ - private $people; - - public function __construct( - \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, - \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, - \SpameriTests\Elastic\Data\Entity\Property\Name $name, - \SpameriTests\Elastic\Data\Entity\Property\Year $year, - \SpameriTests\Elastic\Data\Entity\Video\Technical $technical, - \SpameriTests\Elastic\Data\Entity\Video\Story $story, - \SpameriTests\Elastic\Data\Entity\Video\Details $details, - \SpameriTests\Elastic\Data\Entity\Video\HighLights $highLights, - \SpameriTests\Elastic\Data\Entity\Video\Connections $connections, - \SpameriTests\Elastic\Data\Entity\Video\People $people, - \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection $season = NULL + #[\Spameri\Elastic\Mapping\Entity(class: \Spameri\Elastic\Entity\Property\ElasticId::class)] + public \Spameri\Elastic\Entity\Property\ElasticIdInterface $id, + public \SpameriTests\Elastic\Data\Entity\Video\Identification $identification, + public \SpameriTests\Elastic\Data\Entity\Property\Name $name, + public \SpameriTests\Elastic\Data\Entity\Property\Year $year, + public \SpameriTests\Elastic\Data\Entity\Video\Technical $technical, + public \SpameriTests\Elastic\Data\Entity\Video\Story $story, + public \SpameriTests\Elastic\Data\Entity\Video\Details $details, + public \SpameriTests\Elastic\Data\Entity\Video\HighLights $highLights, + public \SpameriTests\Elastic\Data\Entity\Video\Connections $connections, + public \SpameriTests\Elastic\Data\Entity\Video\People $people, + + #[\Spameri\Elastic\Mapping\Collection] + public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $season, ) { - $this->id = $id; - $this->identification = $identification; - $this->name = $name; - $this->year = $year; - $this->technical = $technical; - $this->story = $story; - $this->details = $details; - $this->highLights = $highLights; - $this->connections = $connections; - - if ($season === NULL) { - $season = new \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection(); - } - $this->season = $season; - $this->people = $people; - } - - - public function entityVariables(): array - { - return \get_object_vars($this); - } - - - public function id(): \Spameri\Elastic\Entity\Property\ElasticIdInterface - { - return $this->id; - } - - - public function identification(): \SpameriTests\Elastic\Data\Entity\Video\Identification - { - return $this->identification; - } - - - public function name(): \SpameriTests\Elastic\Data\Entity\Property\Name - { - return $this->name; - } - - - public function rename(\SpameriTests\Elastic\Data\Entity\Property\Name $name): void - { - $this->name = $name; - } - - - public function year(): \SpameriTests\Elastic\Data\Entity\Property\Year - { - return $this->year; - } - - - public function setYear(\SpameriTests\Elastic\Data\Entity\Property\Year $year): void - { - $this->year = $year; - } - - - public function technical(): \SpameriTests\Elastic\Data\Entity\Video\Technical - { - return $this->technical; - } - - - public function setTechnicalFromImdb(\SpameriTests\Elastic\Data\Entity\Video\Technical $technical): void - { - $this->technical = $technical; - } - - - public function story(): \SpameriTests\Elastic\Data\Entity\Video\Story - { - return $this->story; - } - - - public function details(): \SpameriTests\Elastic\Data\Entity\Video\Details - { - return $this->details; - } - - - public function highLights(): \SpameriTests\Elastic\Data\Entity\Video\HighLights - { - return $this->highLights; - } - - - public function connections(): \SpameriTests\Elastic\Data\Entity\Video\Connections - { - return $this->connections; - } - - - public function season(): \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection - { - return $this->season; - } - - - public function people(): \SpameriTests\Elastic\Data\Entity\Video\People - { - return $this->people; + parent::__construct($id); } } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Alias.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Alias.php index 9817eb21..d67e5187 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Alias.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Alias.php @@ -18,7 +18,7 @@ class Alias public function __construct( \SpameriTests\Elastic\Data\Entity\Property\Name $name, - \SpameriTests\Elastic\Data\Entity\Property\CountryShort $country + \SpameriTests\Elastic\Data\Entity\Property\CountryShort $country, ) { $this->name = $name; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections.php index baf723e7..1edf37c2 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections.php @@ -78,7 +78,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Video\Connections\FollowsCollection $follows, \SpameriTests\Elastic\Data\Entity\Video\Connections\SpunOffCollection $spunOff, \SpameriTests\Elastic\Data\Entity\Video\Connections\VersionOfCollection $versionOf, - \SpameriTests\Elastic\Data\Entity\Video\Connections\EditedFromCollection $editedFrom + \SpameriTests\Elastic\Data\Entity\Video\Connections\EditedFromCollection $editedFrom, ) { $this->followed = $followed; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedFrom.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedFrom.php index c3f70f6a..b65c1354 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedFrom.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedFrom.php @@ -18,7 +18,7 @@ class EditedFrom implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedInto.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedInto.php index 02b4b9b5..cd011ac8 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedInto.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/EditedInto.php @@ -18,7 +18,7 @@ class EditedInto implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Featured.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Featured.php index 437e858e..a74d7e6f 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Featured.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Featured.php @@ -18,7 +18,7 @@ class Featured implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Followed.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Followed.php index 97a8ffb0..eff96461 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Followed.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Followed.php @@ -18,7 +18,7 @@ class Followed implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Follows.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Follows.php index 8aa71a32..c03b009d 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Follows.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Follows.php @@ -18,7 +18,7 @@ class Follows implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Reference.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Reference.php index b2eb392a..c0d9a7bb 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Reference.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Reference.php @@ -18,7 +18,7 @@ class Reference implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Referenced.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Referenced.php index a472b8b3..2347e4c8 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Referenced.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Referenced.php @@ -18,7 +18,7 @@ class Referenced implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Remade.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Remade.php index 3e3ca84a..4243296e 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Remade.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Remade.php @@ -18,7 +18,7 @@ class Remade implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpinOff.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpinOff.php index 811d0264..b16d3100 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpinOff.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpinOff.php @@ -18,7 +18,7 @@ class SpinOff implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Spoofed.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Spoofed.php index babf3df9..b848b4cd 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Spoofed.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/Spoofed.php @@ -18,7 +18,7 @@ class Spoofed implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpunOff.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpunOff.php index b79ad4c0..b8053091 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpunOff.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/SpunOff.php @@ -18,7 +18,7 @@ class SpunOff implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/VersionOf.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/VersionOf.php index 485ee63c..ac5c4506 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/VersionOf.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Connections/VersionOf.php @@ -18,7 +18,7 @@ class VersionOf implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details.php index a8a26210..292e1691 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details.php @@ -30,7 +30,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Video\Details\GenreCollection $genres, \SpameriTests\Elastic\Data\Entity\Video\Details\AliasCollectionElastic $aliases, \SpameriTests\Elastic\Data\Entity\Video\Details\ReleaseCollectionElastic $releases, - \SpameriTests\Elastic\Data\Entity\Video\Details\Ratings $ratings + \SpameriTests\Elastic\Data\Entity\Video\Details\Ratings $ratings, ) { $this->genres = $genres; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Alias.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Alias.php index f700ef5d..6411c6f0 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Alias.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Alias.php @@ -18,7 +18,7 @@ class Alias implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\CountryShort $country, - \SpameriTests\Elastic\Data\Entity\Property\Text $name + \SpameriTests\Elastic\Data\Entity\Property\Text $name, ) { $this->country = $country; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Genre.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Genre.php index 35782f0b..73fb4acf 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Genre.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Genre.php @@ -12,7 +12,7 @@ class Genre implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $value + string $value, ) { if ($value === '') { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/GenreCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/GenreCollection.php index 6a3e790e..81591aee 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/GenreCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/GenreCollection.php @@ -12,7 +12,7 @@ class GenreCollection implements \Spameri\Elastic\Entity\ValueCollectionInterfac public function __construct( - Genre ...$collection + Genre ...$collection, ) { $this->collection = []; @@ -29,7 +29,7 @@ public function getIterator(): \ArrayIterator public function add( - Genre $genre + Genre $genre, ): void { $this->collection[$genre->value()] = $genre; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Ratings.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Ratings.php index 9dd030ad..8c5ba3a7 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Ratings.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Ratings.php @@ -12,7 +12,7 @@ class Ratings implements \Spameri\Elastic\Entity\EntityInterface public function __construct( - RatingsCount $imdbRatings + RatingsCount $imdbRatings, ) { $this->imdbRatings = $imdbRatings; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/RatingsCount.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/RatingsCount.php index b8c39524..5df97f22 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/RatingsCount.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/RatingsCount.php @@ -12,7 +12,7 @@ class RatingsCount implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?int $value + int|null $value, ) { if ($value === NULL) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Release.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Release.php index fd9b4b0f..4a568899 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Release.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Details/Release.php @@ -24,7 +24,7 @@ class Release implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\CountryShort $country, \Spameri\Elastic\Entity\Property\Date $date, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->country = $country; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights.php index 5ee04f58..6e829bcb 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights.php @@ -48,7 +48,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Video\HighLights\QuoteCollection $quotes, \SpameriTests\Elastic\Data\Entity\Video\HighLights\LocationCollection $locations, \SpameriTests\Elastic\Data\Entity\Video\HighLights\AlternateVersionCollection $alternateVersions, - \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCreditCollection $companyCredit + \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCreditCollection $companyCredit, ) { $this->trivia = $trivia; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/AlternateVersion.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/AlternateVersion.php index 2b7d9915..22bf10cd 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/AlternateVersion.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/AlternateVersion.php @@ -12,7 +12,7 @@ class AlternateVersion implements \Spameri\Elastic\Entity\EntityInterface public function __construct( - \SpameriTests\Elastic\Data\Entity\Property\Text $text + \SpameriTests\Elastic\Data\Entity\Property\Text $text, ) { $this->text = $text; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit.php index 539862b1..7366605f 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit.php @@ -18,7 +18,7 @@ class CompanyCredit implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\Text $group, - \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCredit\CompanyCollection $company + \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCredit\CompanyCollection $company, ) { $this->group = $group; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit/Company.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit/Company.php index 4ab33119..6daf7bbf 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit/Company.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CompanyCredit/Company.php @@ -24,7 +24,7 @@ class Company implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Text $name, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CrazyCredit.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CrazyCredit.php index d98fa95c..f1b74cf3 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CrazyCredit.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/CrazyCredit.php @@ -24,7 +24,7 @@ class CrazyCredit implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Text $text, - Relevancy $relevancy + Relevancy $relevancy, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Goof.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Goof.php index 513aa71c..3ed5be32 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Goof.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Goof.php @@ -24,7 +24,7 @@ class Goof implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Text $text, - Relevancy $relevancy + Relevancy $relevancy, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Location.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Location.php index 6a0d8bc3..a7dd0c49 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Location.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Location.php @@ -18,7 +18,7 @@ class Location implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\Text $name, - \SpameriTests\Elastic\Data\Entity\Property\Text $note + \SpameriTests\Elastic\Data\Entity\Property\Text $note, ) { $this->name = $name; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Quote.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Quote.php index 6bf8393c..3e098f64 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Quote.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Quote.php @@ -24,7 +24,7 @@ class Quote implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Text $text, - Relevancy $relevancy + Relevancy $relevancy, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Relevancy.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Relevancy.php index 3919e50e..2f3981c6 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Relevancy.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Relevancy.php @@ -12,7 +12,7 @@ class Relevancy implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - int $value + int $value, ) { if ($value < 0) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Trivia.php b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Trivia.php index 2e57ab21..1e509b1b 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Trivia.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/HighLights/Trivia.php @@ -24,7 +24,7 @@ class Trivia implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\Text $text, - Relevancy $relevancy + Relevancy $relevancy, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Identification.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Identification.php index 7bdd3b50..d044a283 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Identification.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Identification.php @@ -5,19 +5,10 @@ class Identification implements \Spameri\Elastic\Entity\EntityInterface { - /** - * @var \SpameriTests\Elastic\Data\Entity\Property\ImdbId - * @type(keyword) - * @analyzer(keyword) - */ - private $imdb; - - public function __construct( - \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb + public \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb, ) { - $this->imdb = $imdb; } @@ -32,10 +23,4 @@ public function entityVariables(): array return \get_object_vars($this); } - - public function imdb(): \SpameriTests\Elastic\Data\Entity\Property\ImdbId - { - return $this->imdb; - } - } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/People.php b/tests/SpameriTests/Elastic/Data/Entity/Video/People.php index 7d945c8f..9e8bcd2a 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/People.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/People.php @@ -6,12 +6,12 @@ class People extends \Spameri\Elastic\Entity\Collection\AbstractElasticEntityCol { public function personByImdb( - \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb - ): ?\SpameriTests\Elastic\Data\Entity\Person + \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb, + ): \SpameriTests\Elastic\Data\Entity\Person|null { /** @var \SpameriTests\Elastic\Data\Entity\Person $entity */ foreach ($this->collection() as $entity) { - if ($imdb->value() === $entity->identification()->imdb()->value()) { + if ($imdb->value() === $entity->identification->imdb->value()) { return $entity; } } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Season.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Season.php index facbf275..b07f6264 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Season.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Season.php @@ -18,7 +18,7 @@ class Season implements \Spameri\Elastic\Entity\EntityInterface public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $number, - \SpameriTests\Elastic\Data\Entity\Video\Season\EpisodeCollection $episodes + \SpameriTests\Elastic\Data\Entity\Video\Season\EpisodeCollection $episodes, ) { $this->number = $number; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Season/Episode.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Season/Episode.php index 7eaed63e..90bd397a 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Season/Episode.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Season/Episode.php @@ -30,7 +30,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Property\ImdbId $id, \SpameriTests\Elastic\Data\Entity\Property\ImdbId $number, \SpameriTests\Elastic\Data\Entity\Property\Name $name, - \SpameriTests\Elastic\Data\Entity\Property\Description $description + \SpameriTests\Elastic\Data\Entity\Property\Description $description, ) { $this->id = $id; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Season/EpisodeCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Season/EpisodeCollection.php index 4ed713ed..023ef435 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Season/EpisodeCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Season/EpisodeCollection.php @@ -5,7 +5,7 @@ class EpisodeCollection extends \Spameri\Elastic\Entity\Collection\AbstractEntityCollection { - public function episode(\SpameriTests\Elastic\Data\Entity\Property\ImdbId $id): ?Episode + public function episode(\SpameriTests\Elastic\Data\Entity\Property\ImdbId $id): Episode|null { /** @var \SpameriTests\Elastic\Data\Entity\Video\Season\Episode $episode */ foreach ($this->collection() as $episode) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/SeasonCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/SeasonCollection.php index 4b04e24d..7754e782 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/SeasonCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/SeasonCollection.php @@ -5,7 +5,7 @@ class SeasonCollection extends \Spameri\Elastic\Entity\Collection\AbstractEntityCollection { - public function season(\SpameriTests\Elastic\Data\Entity\Property\ImdbId $id): ?Season + public function season(\SpameriTests\Elastic\Data\Entity\Property\ImdbId $id): Season|null { /** @var \SpameriTests\Elastic\Data\Entity\Video\Season $season */ foreach ($this->collection() as $season) { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story.php index d56ce42d..90238dbc 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story.php @@ -36,7 +36,7 @@ public function __construct( \SpameriTests\Elastic\Data\Entity\Video\Story\TagLineCollection $tagLines, \SpameriTests\Elastic\Data\Entity\Video\Story\PlotSummaryCollection $plots, \SpameriTests\Elastic\Data\Entity\Video\Story\KeyWordCollection $keyWord, - ?\SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis $synopsis = NULL + \SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis|null $synopsis = NULL, ) { $this->description = $description; @@ -66,7 +66,7 @@ public function description(): \SpameriTests\Elastic\Data\Entity\Property\Descri public function changeDescription( - \SpameriTests\Elastic\Data\Entity\Property\Description $description + \SpameriTests\Elastic\Data\Entity\Property\Description $description, ): void { $this->description = $description; @@ -86,14 +86,14 @@ public function plots(): \SpameriTests\Elastic\Data\Entity\Video\Story\PlotSumma public function setSynopsis( - ?\SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis $synopsis + \SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis|null $synopsis, ): void { $this->synopsis = $synopsis; } - public function synopsis(): ?\SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis + public function synopsis(): \SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis|null { return $this->synopsis; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWord.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWord.php index fd6144c5..b3dbfaf9 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWord.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWord.php @@ -12,7 +12,7 @@ class KeyWord implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $value + string $value, ) { if ($value === '') { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWordCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWordCollection.php index cb214cdd..4dcaa993 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWordCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/KeyWordCollection.php @@ -12,7 +12,7 @@ class KeyWordCollection implements \Spameri\Elastic\Entity\ValueCollectionInterf public function __construct( - KeyWord ...$entities + KeyWord ...$entities, ) { $this->collection = []; @@ -23,7 +23,7 @@ public function __construct( public function add( - KeyWord $keyWord + KeyWord $keyWord, ): void { $this->collection[$keyWord->value()] = $keyWord; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummary.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummary.php index f1472b0e..5906681e 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummary.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummary.php @@ -12,7 +12,7 @@ class PlotSummary implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $plot + string $plot, ) { if ($plot === '') { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummaryCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummaryCollection.php index 2e90d2fc..5e867f88 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummaryCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/PlotSummaryCollection.php @@ -12,7 +12,7 @@ class PlotSummaryCollection implements \Spameri\Elastic\Entity\ValueCollectionIn public function __construct( - PlotSummary ...$collection + PlotSummary ...$collection, ) { $this->collection = []; @@ -23,14 +23,14 @@ public function __construct( public function add( - PlotSummary $plotSummary + PlotSummary $plotSummary, ): void { $this->collection[\md5($plotSummary->value())] = $plotSummary; } - public function first(): ?PlotSummary + public function first(): PlotSummary|null { $first = \reset($this->collection); diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/Synopsis.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/Synopsis.php index 2b79c531..f24e2498 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/Synopsis.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/Synopsis.php @@ -12,14 +12,14 @@ class Synopsis implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { $this->value = $value; } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLine.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLine.php index 2717dfde..f19f0381 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLine.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLine.php @@ -12,7 +12,7 @@ class TagLine implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - string $tagLine + string $tagLine, ) { if ($tagLine === '') { diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLineCollection.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLineCollection.php index 20d55480..35488cab 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLineCollection.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Story/TagLineCollection.php @@ -12,7 +12,7 @@ class TagLineCollection implements \Spameri\Elastic\Entity\ValueCollectionInterf public function __construct( - \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine ...$collection + \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine ...$collection, ) { $this->collection = []; @@ -23,7 +23,7 @@ public function __construct( public function add( - \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine $tagLine + \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine $tagLine, ): void { $this->collection[\md5($tagLine->value())] = $tagLine; diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical.php index bea2a0ac..e39c390f 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical.php @@ -52,15 +52,15 @@ class Technical implements \Spameri\Elastic\Entity\EntityInterface public function __construct( - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Camera $camera = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Runtime $runtime = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Color $color = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Ratio $ratio = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Laboratory $laboratory = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\FilmLength $filmLength = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\NegativeFormat $negativeFormat = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\CineProcess $cineProcess = NULL, - ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Printed $printed = NULL + \SpameriTests\Elastic\Data\Entity\Video\Technical\Camera|null $camera = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\Runtime|null $runtime = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\Color|null $color = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\Ratio|null $ratio = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\Laboratory|null $laboratory = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\FilmLength|null $filmLength = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\NegativeFormat|null $negativeFormat = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\CineProcess|null $cineProcess = NULL, + \SpameriTests\Elastic\Data\Entity\Video\Technical\Printed|null $printed = NULL, ) { $this->camera = $camera; @@ -93,55 +93,55 @@ public function key(): string } - public function camera(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Camera + public function camera(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Camera|null { return $this->camera; } - public function runtime(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Runtime + public function runtime(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Runtime|null { return $this->runtime; } - public function color(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Color + public function color(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Color|null { return $this->color; } - public function ratio(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Ratio + public function ratio(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Ratio|null { return $this->ratio; } - public function laboratory(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Laboratory + public function laboratory(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Laboratory|null { return $this->laboratory; } - public function filmLength(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\FilmLength + public function filmLength(): \SpameriTests\Elastic\Data\Entity\Video\Technical\FilmLength|null { return $this->filmLength; } - public function negativeFormat(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\NegativeFormat + public function negativeFormat(): \SpameriTests\Elastic\Data\Entity\Video\Technical\NegativeFormat|null { return $this->negativeFormat; } - public function cineProcess(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\CineProcess + public function cineProcess(): \SpameriTests\Elastic\Data\Entity\Video\Technical\CineProcess|null { return $this->cineProcess; } - public function printed(): ?\SpameriTests\Elastic\Data\Entity\Video\Technical\Printed + public function printed(): \SpameriTests\Elastic\Data\Entity\Video\Technical\Printed|null { return $this->printed; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Camera.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Camera.php index c0e70633..a1890cdb 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Camera.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Camera.php @@ -12,7 +12,7 @@ class Camera implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/CineProcess.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/CineProcess.php index 1c58bfd5..c01ca58d 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/CineProcess.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/CineProcess.php @@ -12,7 +12,7 @@ class CineProcess implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Color.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Color.php index 62f3905e..f5bbb6c9 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Color.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Color.php @@ -12,7 +12,7 @@ class Color implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/FilmLength.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/FilmLength.php index 05eb138c..8beb5414 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/FilmLength.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/FilmLength.php @@ -12,7 +12,7 @@ class FilmLength implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Laboratory.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Laboratory.php index 67e74e55..e52a4059 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Laboratory.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Laboratory.php @@ -12,7 +12,7 @@ class Laboratory implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/NegativeFormat.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/NegativeFormat.php index 3a514601..0fcd64ec 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/NegativeFormat.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/NegativeFormat.php @@ -12,7 +12,7 @@ class NegativeFormat implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Printed.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Printed.php index 962f997b..3047f50e 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Printed.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Printed.php @@ -12,7 +12,7 @@ class Printed implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Ratio.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Ratio.php index e58389a8..8351952e 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Ratio.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Ratio.php @@ -12,7 +12,7 @@ class Ratio implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?string $value + string|null $value, ) { if ($value !== NULL && \strlen($value) > 255) { @@ -23,7 +23,7 @@ public function __construct( } - public function value(): ?string + public function value(): string|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Runtime.php b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Runtime.php index 7e02c58f..b2f5c4b3 100644 --- a/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Runtime.php +++ b/tests/SpameriTests/Elastic/Data/Entity/Video/Technical/Runtime.php @@ -12,7 +12,7 @@ class Runtime implements \Spameri\Elastic\Entity\ValueInterface public function __construct( - ?int $value + int|null $value, ) { if ($value < 0) { @@ -26,7 +26,7 @@ public function __construct( } - public function value(): ?int + public function value(): int|null { return $this->value; } diff --git a/tests/SpameriTests/Elastic/Data/Model/PersonCollectionFactory.php b/tests/SpameriTests/Elastic/Data/Model/PersonCollectionFactory.php index e9e55f87..a29f571f 100644 --- a/tests/SpameriTests/Elastic/Data/Model/PersonCollectionFactory.php +++ b/tests/SpameriTests/Elastic/Data/Model/PersonCollectionFactory.php @@ -12,13 +12,13 @@ class PersonCollectionFactory implements \Spameri\Elastic\Factory\CollectionFact public function create( \Spameri\Elastic\Model\ServiceInterface $service, array $elasticIds = [], - \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection + \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface { return new \SpameriTests\Elastic\Data\Model\PersonCollection( $service, $elasticIds, - ... $entityCollection + ... $entityCollection, ); } diff --git a/tests/SpameriTests/Elastic/Data/Model/PersonFactory.php b/tests/SpameriTests/Elastic/Data/Model/PersonFactory.php index 065acef4..af2b09f8 100644 --- a/tests/SpameriTests/Elastic/Data/Model/PersonFactory.php +++ b/tests/SpameriTests/Elastic/Data/Model/PersonFactory.php @@ -8,20 +8,23 @@ class PersonFactory implements \Spameri\Elastic\Factory\EntityFactoryInterface /** * @return \Generator<\SpameriTests\Elastic\Data\Entity\Person> */ - public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit): \Generator + public function create( + \Spameri\ElasticQuery\Response\Result\Hit $hit, + string|null $class = null, + ): \Generator { yield new \SpameriTests\Elastic\Data\Entity\Person( - new \Spameri\Elastic\Entity\Property\ElasticId($hit->id()), - new \SpameriTests\Elastic\Data\Entity\Video\Identification( - $hit->getValue('identification.imdb') + id: new \Spameri\Elastic\Entity\Property\ElasticId($hit->id()), + identification: new \SpameriTests\Elastic\Data\Entity\Video\Identification( + $hit->getValue('identification.imdb'), ), - new \SpameriTests\Elastic\Data\Entity\Property\Name($hit->getValue('name')), - new \SpameriTests\Elastic\Data\Entity\Property\Description($hit->getValue('description')), - new \Spameri\Elastic\Entity\Property\Date($hit->getValue('birth')), - new \Spameri\Elastic\Entity\Property\Date($hit->getValue('death')), - new \SpameriTests\Elastic\Data\Entity\Property\Name($hit->getValue('alias')), - new \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic(), - new \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic() + name: new \SpameriTests\Elastic\Data\Entity\Property\Name($hit->getValue('name')), + description: new \SpameriTests\Elastic\Data\Entity\Property\Description($hit->getValue('description')), + birth: new \Spameri\Elastic\Entity\Property\Date($hit->getValue('birth')), + death: new \Spameri\Elastic\Entity\Property\Date($hit->getValue('death')), + alias: new \SpameriTests\Elastic\Data\Entity\Property\Name($hit->getValue('alias')), + characters: new \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic(), + jobs: new \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic(), ); } diff --git a/tests/SpameriTests/Elastic/Data/Model/PersonMapping.php b/tests/SpameriTests/Elastic/Data/Model/PersonMapping.php index 54321910..787748a0 100644 --- a/tests/SpameriTests/Elastic/Data/Model/PersonMapping.php +++ b/tests/SpameriTests/Elastic/Data/Model/PersonMapping.php @@ -2,20 +2,9 @@ namespace SpameriTests\Elastic\Data\Model; -class PersonMapping implements \Spameri\Elastic\Settings\IndexConfigInterface +class PersonMapping extends \Spameri\Elastic\Settings\AbstractIndexConfig { - private string $index; - - - public function __construct( - string $index - ) - { - $this->index = $index; - } - - public function provide(): \Spameri\ElasticQuery\Mapping\Settings { return new \Spameri\ElasticQuery\Mapping\Settings($this->index); diff --git a/tests/SpameriTests/Elastic/Data/Model/PersonService.php b/tests/SpameriTests/Elastic/Data/Model/PersonService.php index f58d1cfc..4016b792 100644 --- a/tests/SpameriTests/Elastic/Data/Model/PersonService.php +++ b/tests/SpameriTests/Elastic/Data/Model/PersonService.php @@ -10,7 +10,7 @@ class PersonService extends \Spameri\Elastic\Model\AbstractBaseService * @return string */ public function insert( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\ElasticEntityInterface $entity, ): string { return parent::insert($entity); @@ -22,7 +22,7 @@ public function insert( * @return \Spameri\Elastic\Entity\ElasticEntityInterface|\SpameriTests\Elastic\Data\Entity\Person */ public function get( - \Spameri\Elastic\Entity\Property\ElasticId $id + \Spameri\Elastic\Entity\Property\ElasticId $id, ): \Spameri\Elastic\Entity\ElasticEntityInterface { return parent::get($id); @@ -34,7 +34,7 @@ public function get( * @return \Spameri\Elastic\Entity\ElasticEntityInterface|\SpameriTests\Elastic\Data\Entity\Person */ public function getBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityInterface { return parent::getBy($elasticQuery); @@ -46,7 +46,7 @@ public function getBy( * @return \Spameri\Elastic\Entity\ElasticEntityCollectionInterface<\SpameriTests\Elastic\Data\Entity\Person> */ public function getAllBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface { return parent::getAllBy($elasticQuery); diff --git a/tests/SpameriTests/Elastic/Data/Model/VideoCollectionFactory.php b/tests/SpameriTests/Elastic/Data/Model/VideoCollectionFactory.php index e9e7c05a..9c663825 100644 --- a/tests/SpameriTests/Elastic/Data/Model/VideoCollectionFactory.php +++ b/tests/SpameriTests/Elastic/Data/Model/VideoCollectionFactory.php @@ -12,13 +12,13 @@ class VideoCollectionFactory implements \Spameri\Elastic\Factory\CollectionFacto public function create( \Spameri\Elastic\Model\ServiceInterface $service, array $elasticIds = [], - \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection + \Spameri\Elastic\Entity\ElasticEntityInterface ...$entityCollection, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface { return new \SpameriTests\Elastic\Data\Model\VideoCollection( $service, $elasticIds, - ... $entityCollection + ... $entityCollection, ); } diff --git a/tests/SpameriTests/Elastic/Data/Model/VideoFactory.php b/tests/SpameriTests/Elastic/Data/Model/VideoFactory.php index af88cc7a..092ee716 100644 --- a/tests/SpameriTests/Elastic/Data/Model/VideoFactory.php +++ b/tests/SpameriTests/Elastic/Data/Model/VideoFactory.php @@ -5,26 +5,25 @@ class VideoFactory implements \Spameri\Elastic\Factory\EntityFactoryInterface { - private \SpameriTests\Elastic\Data\Model\PersonService $personService; - - public function __construct( - \SpameriTests\Elastic\Data\Model\PersonService $personService + private \SpameriTests\Elastic\Data\Model\PersonService $personService, ) { - $this->personService = $personService; } /** * @return \Generator<\SpameriTests\Elastic\Data\Entity\Video> */ - public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit): \Generator + public function create( + \Spameri\ElasticQuery\Response\Result\Hit $hit, + string|null $class = null, + ): \Generator { yield new \SpameriTests\Elastic\Data\Entity\Video( new \Spameri\Elastic\Entity\Property\ElasticId($hit->id()), new \SpameriTests\Elastic\Data\Entity\Video\Identification( - new \SpameriTests\Elastic\Data\Entity\Property\ImdbId($hit->getValue('identification.imdb')) + new \SpameriTests\Elastic\Data\Entity\Property\ImdbId($hit->getValue('identification.imdb')), ), new \SpameriTests\Elastic\Data\Entity\Property\Name($hit->getValue('name')), new \SpameriTests\Elastic\Data\Entity\Property\Year($hit->getValue('year')), @@ -32,19 +31,19 @@ public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit): \Generat new \SpameriTests\Elastic\Data\Entity\Video\Story( new \SpameriTests\Elastic\Data\Entity\Property\Description($hit->getValue('story.description')), new \SpameriTests\Elastic\Data\Entity\Video\Story\TagLineCollection( - new \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine($hit->getValue('story.tagline')) + new \SpameriTests\Elastic\Data\Entity\Video\Story\TagLine($hit->getValue('story.tagline')), ), new \SpameriTests\Elastic\Data\Entity\Video\Story\PlotSummaryCollection(), new \SpameriTests\Elastic\Data\Entity\Video\Story\KeyWordCollection(), - new \SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis($hit->getValue('synopsis')) + new \SpameriTests\Elastic\Data\Entity\Video\Story\Synopsis($hit->getValue('synopsis')), ), new \SpameriTests\Elastic\Data\Entity\Video\Details( new \SpameriTests\Elastic\Data\Entity\Video\Details\GenreCollection(), new \SpameriTests\Elastic\Data\Entity\Video\Details\AliasCollectionElastic(), new \SpameriTests\Elastic\Data\Entity\Video\Details\ReleaseCollectionElastic(), new \SpameriTests\Elastic\Data\Entity\Video\Details\Ratings( - new \SpameriTests\Elastic\Data\Entity\Video\Details\RatingsCount(1000) - ) + new \SpameriTests\Elastic\Data\Entity\Video\Details\RatingsCount(1000), + ), ), new \SpameriTests\Elastic\Data\Entity\Video\HighLights( new \SpameriTests\Elastic\Data\Entity\Video\HighLights\TriviaCollection(), @@ -53,7 +52,7 @@ public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit): \Generat new \SpameriTests\Elastic\Data\Entity\Video\HighLights\QuoteCollection(), new \SpameriTests\Elastic\Data\Entity\Video\HighLights\LocationCollection(), new \SpameriTests\Elastic\Data\Entity\Video\HighLights\AlternateVersionCollection(), - new \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCreditCollection() + new \SpameriTests\Elastic\Data\Entity\Video\HighLights\CompanyCreditCollection(), ), new \SpameriTests\Elastic\Data\Entity\Video\Connections( new \SpameriTests\Elastic\Data\Entity\Video\Connections\FollowedCollection(), @@ -67,10 +66,10 @@ public function create(\Spameri\ElasticQuery\Response\Result\Hit $hit): \Generat new \SpameriTests\Elastic\Data\Entity\Video\Connections\FollowsCollection(), new \SpameriTests\Elastic\Data\Entity\Video\Connections\SpunOffCollection(), new \SpameriTests\Elastic\Data\Entity\Video\Connections\VersionOfCollection(), - new \SpameriTests\Elastic\Data\Entity\Video\Connections\EditedFromCollection() + new \SpameriTests\Elastic\Data\Entity\Video\Connections\EditedFromCollection(), ), new \SpameriTests\Elastic\Data\Entity\Video\People($this->personService), - new \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection() + new \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection(), ); } diff --git a/tests/SpameriTests/Elastic/Data/Model/VideoMapping.php b/tests/SpameriTests/Elastic/Data/Model/VideoMapping.php index 8da98a37..5b864d61 100644 --- a/tests/SpameriTests/Elastic/Data/Model/VideoMapping.php +++ b/tests/SpameriTests/Elastic/Data/Model/VideoMapping.php @@ -2,45 +2,34 @@ namespace SpameriTests\Elastic\Data\Model; -class VideoMapping implements \Spameri\Elastic\Settings\IndexConfigInterface +class VideoMapping extends \Spameri\Elastic\Settings\AbstractIndexConfig { - private string $index; - - - public function __construct( - string $index - ) - { - $this->index = $index; - } - - public function provide(): \Spameri\ElasticQuery\Mapping\Settings { $settings = new \Spameri\ElasticQuery\Mapping\Settings($this->index); $nameFields = new \Spameri\ElasticQuery\Mapping\Settings\Mapping\SubFields( 'name', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, ); $nameFields->addMappingField( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'edgeNgram', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, + ), ); $nameFields->addMappingField( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'wordSplit', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, + ), ); $nameFields->addMappingField( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'wordJoin', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, + ), ); $settings->addMappingSubField($nameFields); @@ -49,13 +38,13 @@ public function provide(): \Spameri\ElasticQuery\Mapping\Settings new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'description', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, ), new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'tagLine', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD - ) - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, + ), + ), ); $settings->addMappingFieldObject($story); @@ -64,30 +53,30 @@ public function provide(): \Spameri\ElasticQuery\Mapping\Settings new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'number', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, ), new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'episodes', new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'id', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, ), new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'number', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, ), new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'name', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, ), new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'description', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT - ) - ) - ) - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, + ), + ), + ), + ), ); $settings->addMappingFieldObject($season); @@ -96,52 +85,52 @@ public function provide(): \Spameri\ElasticQuery\Mapping\Settings new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'imdb', - \Spameri\ElasticQuery\Mapping\AllowedValues::TYPE_KEYWORD - ) - ) + \Spameri\ElasticQuery\Mapping\AllowedValues::TYPE_KEYWORD, + ), + ), ); $settings->addMappingFieldObject($identification); $settings->addMappingField( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field( 'year', - \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_LONG - ) + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_LONG, + ), ); $settings->addMappingFieldObject( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'technical', - new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection() - ) + new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection(), + ), ); $settings->addMappingFieldObject( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'details', - new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection() - ) + new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection(), + ), ); $settings->addMappingFieldObject( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'highLights', - new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection() - ) + new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection(), + ), ); $settings->addMappingFieldObject( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'connections', - new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection() - ) + new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection(), + ), ); $settings->addMappingFieldObject( new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject( 'people', - new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection() - ) + new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection(), + ), ); return $settings; diff --git a/tests/SpameriTests/Elastic/Data/Model/VideoService.php b/tests/SpameriTests/Elastic/Data/Model/VideoService.php index fe6f99d2..22381960 100644 --- a/tests/SpameriTests/Elastic/Data/Model/VideoService.php +++ b/tests/SpameriTests/Elastic/Data/Model/VideoService.php @@ -10,7 +10,7 @@ class VideoService extends \Spameri\Elastic\Model\AbstractBaseService * @return string */ public function insert( - \Spameri\Elastic\Entity\ElasticEntityInterface $entity + \Spameri\Elastic\Entity\ElasticEntityInterface $entity, ): string { return parent::insert($entity); @@ -22,7 +22,7 @@ public function insert( * @return \Spameri\Elastic\Entity\ElasticEntityInterface|\SpameriTests\Elastic\Data\Entity\Video */ public function get( - \Spameri\Elastic\Entity\Property\ElasticId $id + \Spameri\Elastic\Entity\Property\ElasticId $id, ): \Spameri\Elastic\Entity\ElasticEntityInterface { return parent::get($id); @@ -35,7 +35,7 @@ public function get( * @throws \Spameri\Elastic\Exception\DocumentNotFound */ public function getBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityInterface { return parent::getBy($elasticQuery); @@ -47,7 +47,7 @@ public function getBy( * @return \Spameri\Elastic\Entity\ElasticEntityCollectionInterface<\SpameriTests\Elastic\Data\Entity\Video> */ public function getAllBy( - \Spameri\ElasticQuery\ElasticQuery $elasticQuery + \Spameri\ElasticQuery\ElasticQuery $elasticQuery, ): \Spameri\Elastic\Entity\ElasticEntityCollectionInterface { return parent::getAllBy($elasticQuery); diff --git a/tests/SpameriTests/Elastic/Factory/EntityFactory.phpt b/tests/SpameriTests/Elastic/Factory/EntityFactory.phpt new file mode 100644 index 00000000..5916c8bf --- /dev/null +++ b/tests/SpameriTests/Elastic/Factory/EntityFactory.phpt @@ -0,0 +1,68 @@ +prepare($person), + position: 0, + index: '', + type: '', + id: 'asd123', + score: 0.0, + version: 0, + ); + + /** @var \SpameriTests\Elastic\Data\Entity\Person $entity */ + $entity = $entityFactory->create($hit, \SpameriTests\Elastic\Data\Entity\Person::class)->current(); + + \Tester\Assert::same($person->id->value(), $entity->id->value()); + \Tester\Assert::same($person->identification->imdb->value(), $entity->identification->imdb->value()); + \Tester\Assert::same($person->name->value(), $entity->name->value()); + \Tester\Assert::same($person->description->value(), $entity->description->value()); + \Tester\Assert::same($person->birth->format('Y-m-d'), $entity->birth->format('Y-m-d')); + \Tester\Assert::null($entity->death); + \Tester\Assert::same($person->alias->value(), $entity->alias->value()); + } + +} + +(new EntityFactory())->run(); diff --git a/tests/SpameriTests/Elastic/Model/Indices/CreateTest.php b/tests/SpameriTests/Elastic/Model/Indices/CreateTest.php index 324566be..a9e93b8b 100644 --- a/tests/SpameriTests/Elastic/Model/Indices/CreateTest.php +++ b/tests/SpameriTests/Elastic/Model/Indices/CreateTest.php @@ -21,60 +21,60 @@ public function testProcess(): void $create = new \Spameri\Elastic\Model\Indices\Create( $this->container->getByType(\Spameri\Elastic\ClientProvider::class), - $this->container->getByType(\Spameri\Elastic\Model\VersionProvider::class) + $this->container->getByType(\Spameri\Elastic\Model\VersionProvider::class), ); $create->execute( \SpameriTests\Elastic\Config::INDEX_CREATE, $videoMapping->provide()->toArray(), - \SpameriTests\Elastic\Config::INDEX_CREATE + \SpameriTests\Elastic\Config::INDEX_CREATE, ); $response = $getMapping->execute(\SpameriTests\Elastic\Config::INDEX_CREATE); if ($versionProvider->provide() < \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7) { \Tester\Assert::true( - isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings'][\SpameriTests\Elastic\Config::INDEX_CREATE]) + isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings'][\SpameriTests\Elastic\Config::INDEX_CREATE]), ); $existingMapping = $response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings'][\SpameriTests\Elastic\Config::INDEX_CREATE]; \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, - $existingMapping['properties']['name']['type'] + $existingMapping['properties']['name']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, - $existingMapping['properties']['name']['fields']['edgeNgram']['type'] + $existingMapping['properties']['name']['fields']['edgeNgram']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, - $existingMapping['properties']['season']['properties']['number']['type'] + $existingMapping['properties']['season']['properties']['number']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, - $existingMapping['properties']['story']['properties']['description']['type'] + $existingMapping['properties']['story']['properties']['description']['type'], ); } else { \Tester\Assert::true( - isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings']) + isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings']), ); $existingMapping = $response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings']; \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, - $existingMapping['properties']['name']['type'] + $existingMapping['properties']['name']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, - $existingMapping['properties']['name']['fields']['edgeNgram']['type'] + $existingMapping['properties']['name']['fields']['edgeNgram']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, - $existingMapping['properties']['season']['properties']['number']['type'] + $existingMapping['properties']['season']['properties']['number']['type'], ); \Tester\Assert::same( \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, - $existingMapping['properties']['story']['properties']['description']['type'] + $existingMapping['properties']['story']['properties']['description']['type'], ); } }