diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 723545279..74b33e276 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -40,24 +40,24 @@ jobs: - '7.4' - '8.1' - '8.2' + - '8.3' symfony: - - '4.4.*' - '5.4.*' - - '6.2.*' + - '6.3.*' + - '7.0.*' elasticsearch: - '7.11.0' dependencies: - 'highest' - include: - - php: '7.4' - elasticsearch: '7.0.0' - dependencies: 'lowest' - symfony: '4.4.*' exclude: - php: '7.4' - symfony: '6.2.*' - dependencies: 'highest' - elasticsearch: '7.11.0' + symfony: '7.0.*' + - php: '7.4' + symfony: '6.3.*' + - php: '8.0' + symfony: '7.0.*' + - php: '8.1' + symfony: '7.0.*' fail-fast: false steps: - name: 'Checkout' @@ -103,20 +103,29 @@ jobs: - '7.4' - '8.1' - '8.2' + - '8.3' symfony: - - '4.4.*' - '5.4.*' - - '6.2.*' + - '6.3.*' + - '7.0.*' dependencies: - 'highest' include: - php: '7.4' dependencies: 'lowest' - symfony: '4.4.*' + symfony: '5.4.*' exclude: - php: '7.4' - symfony: '6.2.*' - dependencies: 'highest' + symfony: '7.0.*' + - php: '7.4' + symfony: '6.3.*' + - php: '8.0' + symfony: '7.0.*' + - php: '8.1' + symfony: '7.0.*' + - php: '8.1' + symfony: '4.4.*' + fail-fast: false steps: - name: 'Checkout' diff --git a/composer.json b/composer.json index b9a0751e7..77f7c8901 100644 --- a/composer.json +++ b/composer.json @@ -34,38 +34,41 @@ "pagerfanta/pagerfanta": "^2.4 || ^3.0 || ^4.0", "psr/log": "^1.0 || ^2.0 || ^3.0", "ruflin/elastica": "^7.1", - "symfony/console": "^4.4 || ^5.4 || ^6.2", - "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2", - "symfony/property-access": "^4.4 || ^5.4 || ^6.2" + "symfony/console": "^5.4 || ^6.3 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.3 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0", + "symfony/property-access": "^5.4 || ^6.3 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.3 || ^7.0" }, "require-dev": { "doctrine/doctrine-bundle": "^2.1.1", "doctrine/mongodb-odm": "^2.2", "doctrine/orm": "^2.8", - "doctrine/phpcr-odm": "^1.4", + "doctrine/phpcr-odm": "^1.5.3 || ^2.0.0-beta2", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "^3.0", - "jackalope/jackalope-doctrine-dbal": "^1.2", + "jackalope/jackalope-doctrine-dbal": "^1.2 || ^2.0.0-RC1", "jms/serializer": "^3.8", - "jms/serializer-bundle": "^3.5 || ^4.0", - "knplabs/knp-components": "^2.4 || ^3.0", + "jms/serializer-bundle": "^4.0 || ^5.0", + "knplabs/knp-components": "^2.4 || ^3.0 || ^4.0", + "php-cs-fixer/shim": "3.8.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-symfony": "^1.2", "phpunit/phpunit": "^9.5", - "symfony/expression-language": "^4.4 || ^5.4 || ^6.2", - "symfony/messenger": "^4.4 || ^5.4 || ^6.2", - "symfony/serializer": "^4.4 || ^5.4 || ^6.2", - "symfony/twig-bundle": "^4.4 || ^5.4 || ^6.2", - "symfony/web-profiler-bundle": "^4.4 || ^5.4 || ^6.2", - "symfony/yaml": "^4.4 || ^5.4 || ^6.2" + "symfony/expression-language": "^5.4 || ^6.3 || ^7.0", + "symfony/messenger": "^5.4 || ^6.3 || ^7.0", + "symfony/serializer": "^5.4 || ^6.3 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.3 || ^7.0", + "symfony/web-profiler-bundle": "^5.4 || ^6.3 || ^7.0", + "symfony/yaml": "^5.4 || ^6.3 || ^7.0" }, "suggest": { "enqueue/elastica-bundle": "For populating Elasticsearch indexes asynchronously and using significanly less resources. Uses Enqueue.", "symfony/messenger": "For populating Elasticsearch indexes asynchronously and using significanly less resources." }, + "minimum-stability": "RC", + "prefer-stable": true, "autoload": { "psr-4": { "FOS\\ElasticaBundle\\": "src/" @@ -78,8 +81,8 @@ }, "config": { "allow-plugins": { - "phpstan/extension-installer": true, - "ergebnis/composer-normalize": true + "ergebnis/composer-normalize": true, + "phpstan/extension-installer": true } }, "extra": { diff --git a/phpstan.dist.neon b/phpstan.dist.neon index e6771d3f3..cb09a8c75 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -8,6 +8,8 @@ parameters: paths: - src # - tests + excludePaths: + - src/Message/Handler/AsyncPersistPageHandler.php ignoreErrors: - message: /Trying to mock an undefined method/ path: tests/ diff --git a/src/Configuration/ConfigManager.php b/src/Configuration/ConfigManager.php index 998087fd2..e046d0a10 100644 --- a/src/Configuration/ConfigManager.php +++ b/src/Configuration/ConfigManager.php @@ -18,6 +18,7 @@ class ConfigManager implements ManagerInterface { /** * @var IndexConfig[] + * * @phpstan-var array */ private $indexes = []; diff --git a/src/Configuration/IndexConfigInterface.php b/src/Configuration/IndexConfigInterface.php index 6a2392909..9cbc69135 100644 --- a/src/Configuration/IndexConfigInterface.php +++ b/src/Configuration/IndexConfigInterface.php @@ -69,6 +69,7 @@ public function getNumericDetection(): ?bool; /** * @return string|bool|null + * * @phpstan-return ?TDynamic */ public function getDynamic(); diff --git a/src/Configuration/IndexConfigTrait.php b/src/Configuration/IndexConfigTrait.php index 31f4a1583..d4d25c6a4 100644 --- a/src/Configuration/IndexConfigTrait.php +++ b/src/Configuration/IndexConfigTrait.php @@ -48,21 +48,27 @@ trait IndexConfigTrait * An array of settings sent to ElasticSearch when creating the index. * * @var array + * * @phpstan-var TSettings + * * @phpstan-ignore-next-line Ignored because of a bug in PHPStan (https://github.com/phpstan/phpstan/issues/5091) */ private $settings; /** * @var array + * * @phpstan-var TConfig + * * @phpstan-ignore-next-line Ignored because of a bug in PHPStan (https://github.com/phpstan/phpstan/issues/5091) */ private $config; /** * @var array + * * @phpstan-var TMapping + * * @phpstan-ignore-next-line Ignored because of a bug in PHPStan (https://github.com/phpstan/phpstan/issues/5091) */ private $mapping; diff --git a/src/Configuration/Source/ContainerSource.php b/src/Configuration/Source/ContainerSource.php index 93d57e84f..d0f2f5bc2 100644 --- a/src/Configuration/Source/ContainerSource.php +++ b/src/Configuration/Source/ContainerSource.php @@ -25,6 +25,7 @@ class ContainerSource implements SourceInterface * The internal container representation of information. * * @var array + * * @phpstan-var list */ private $configArray; @@ -41,6 +42,7 @@ public function __construct(array $configArray) * Should return all configuration available from the data source. * * @return IndexConfig[] + * * @phpstan-return array */ public function getConfiguration(): array diff --git a/src/Configuration/Source/SourceInterface.php b/src/Configuration/Source/SourceInterface.php index 35de93e53..61dfa805d 100644 --- a/src/Configuration/Source/SourceInterface.php +++ b/src/Configuration/Source/SourceInterface.php @@ -23,6 +23,7 @@ interface SourceInterface * Should return all configuration available from the data source. * * @return \FOS\ElasticaBundle\Configuration\IndexConfig[] + * * @phpstan-return array */ public function getConfiguration(): array; diff --git a/src/Configuration/Source/TemplateContainerSource.php b/src/Configuration/Source/TemplateContainerSource.php index 6b3a4d338..f943708e9 100644 --- a/src/Configuration/Source/TemplateContainerSource.php +++ b/src/Configuration/Source/TemplateContainerSource.php @@ -25,6 +25,7 @@ class TemplateContainerSource implements SourceInterface * The internal container representation of information. * * @var array + * * @phpstan-var list */ private $configArray; @@ -41,6 +42,7 @@ public function __construct(array $configArray) * Should return all configuration available from the data source. * * @return IndexTemplateConfig[] + * * @phpstan-return array */ public function getConfiguration(): array diff --git a/src/Configuration/TypeConfig.php b/src/Configuration/TypeConfig.php index 71f3063bb..594c80608 100644 --- a/src/Configuration/TypeConfig.php +++ b/src/Configuration/TypeConfig.php @@ -21,12 +21,14 @@ class TypeConfig { /** * @var array + * * @phpstan-var TElasticConfig */ private $config; /** * @var array + * * @phpstan-var TMapping */ private $mapping; @@ -38,6 +40,7 @@ class TypeConfig /** * @param TMapping $mapping + * * @phpstan-param TElasticConfig $config */ public function __construct(string $name, array $mapping, array $config = []) diff --git a/src/DataCollector/ElasticaDataCollector.php b/src/DataCollector/ElasticaDataCollector.php index 327cc8c1e..6e883e9df 100644 --- a/src/DataCollector/ElasticaDataCollector.php +++ b/src/DataCollector/ElasticaDataCollector.php @@ -39,17 +39,11 @@ public function collect(Request $request, Response $response, ?\Throwable $excep $this->data['queries'] = $this->logger->getQueries(); } - /** - * @return mixed - */ public function getQueryCount() { return $this->data['nb_queries']; } - /** - * @return mixed - */ public function getQueries() { return $this->data['queries']; diff --git a/src/DependencyInjection/FOSElasticaExtension.php b/src/DependencyInjection/FOSElasticaExtension.php index 906be6db0..0fd274092 100644 --- a/src/DependencyInjection/FOSElasticaExtension.php +++ b/src/DependencyInjection/FOSElasticaExtension.php @@ -41,6 +41,7 @@ class FOSElasticaExtension extends Extension * An array of indexes as configured by the extension. * * @var array + * * @phpstan-var array */ private $indexConfigs = []; @@ -49,6 +50,7 @@ class FOSElasticaExtension extends Extension * An array of index templates as configured by the extension. * * @var array + * * @phpstan-var array */ private $indexTemplateConfigs = []; @@ -721,7 +723,7 @@ private function loadSerializer(array $config, ContainerBuilder $container): voi $serializer = $container->getDefinition('fos_elastica.serializer_callback_prototype'); $serializer->setClass($config['callback_class']); - if (\is_subclass_of($config['callback_class'], ContainerAwareInterface::class)) { + if (\class_exists('Symfony\Component\DependencyInjection\ContainerAwareInterface') && \is_subclass_of($config['callback_class'], ContainerAwareInterface::class)) { $serializer->addMethodCall('setContainer', [new Reference('service_container')]); } } diff --git a/src/Doctrine/AbstractElasticaToModelTransformer.php b/src/Doctrine/AbstractElasticaToModelTransformer.php index 574361447..a2ab964fd 100644 --- a/src/Doctrine/AbstractElasticaToModelTransformer.php +++ b/src/Doctrine/AbstractElasticaToModelTransformer.php @@ -144,9 +144,6 @@ public function hybridTransform(array $elasticaObjects) return $result; } - /** - * {@inheritdoc} - */ public function getIdentifierField(): string { return $this->options['identifier']; diff --git a/src/Doctrine/MongoDBPagerProvider.php b/src/Doctrine/MongoDBPagerProvider.php index c2efa5616..f9fe54036 100644 --- a/src/Doctrine/MongoDBPagerProvider.php +++ b/src/Doctrine/MongoDBPagerProvider.php @@ -37,9 +37,6 @@ public function __construct( $this->registerListenersService = $registerListenersService; } - /** - * {@inheritdoc} - */ public function provide(array $options = []): PagerInterface { $options = \array_replace($this->baseOptions, $options); diff --git a/src/Doctrine/ORMPagerProvider.php b/src/Doctrine/ORMPagerProvider.php index 259a20da9..b23dc35e4 100644 --- a/src/Doctrine/ORMPagerProvider.php +++ b/src/Doctrine/ORMPagerProvider.php @@ -41,9 +41,6 @@ public function __construct( $this->registerListenersService = $registerListenersService; } - /** - * {@inheritdoc} - */ public function provide(array $options = []): PagerInterface { $options = \array_replace($this->baseOptions, $options); diff --git a/src/Doctrine/PHPCRPagerProvider.php b/src/Doctrine/PHPCRPagerProvider.php index f79cd9b04..a3e7718b8 100644 --- a/src/Doctrine/PHPCRPagerProvider.php +++ b/src/Doctrine/PHPCRPagerProvider.php @@ -55,9 +55,6 @@ public function __construct(ManagerRegistry $doctrine, RegisterListenersService $this->registerListenersService = $registerListenersService; } - /** - * {@inheritdoc} - */ public function provide(array $options = []): PagerInterface { $options = \array_replace($this->baseOptions, $options); @@ -73,7 +70,7 @@ public function provide(array $options = []): PagerInterface $repository = $manager->getRepository($this->objectClass); $adapter = new QueryAdapter( - \call_user_func([$repository, $options['query_builder_method']], static::ENTITY_ALIAS) + \call_user_func([$repository, $options['query_builder_method']], self::ENTITY_ALIAS) ); $pager = new PagerfantaPager(new Pagerfanta($adapter)); diff --git a/src/Doctrine/RepositoryManager.php b/src/Doctrine/RepositoryManager.php index bd3cb85f7..572803865 100644 --- a/src/Doctrine/RepositoryManager.php +++ b/src/Doctrine/RepositoryManager.php @@ -35,9 +35,6 @@ public function __construct(ManagerRegistry $managerRegistry, RepositoryManagerI $this->repositoryManager = $repositoryManager; } - /** - * {@inheritdoc} - */ public function addIndex(string $indexName, FinderInterface $finder, ?string $repositoryName = null): void { throw new \LogicException(__METHOD__.' should not be called. Call addIndex on the main repository manager'); @@ -58,7 +55,12 @@ public function getRepository(string $entityName): Repository $realEntityName = $entityName; if (false !== \strpos($entityName, ':')) { [$namespaceAlias, $simpleClassName] = \explode(':', $entityName); - $realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName; + // @link https://github.com/doctrine/persistence/pull/204 + if (\method_exists($this->managerRegistry, 'getAliasNamespace')) { + $realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName; + } else { + $realEntityName = $simpleClassName.'::class'; + } } if (isset($this->entities[$realEntityName])) { diff --git a/src/Elastica/Client.php b/src/Elastica/Client.php index e1808949f..c411834f7 100644 --- a/src/Elastica/Client.php +++ b/src/Elastica/Client.php @@ -49,8 +49,6 @@ class Client extends BaseClient private $stopwatch; /** - * {@inheritdoc} - * * @param array $data * @param array $query */ diff --git a/src/Event/AbstractIndexPopulateEvent.php b/src/Event/AbstractIndexPopulateEvent.php index ec1fcb382..a68b6ae8a 100644 --- a/src/Event/AbstractIndexPopulateEvent.php +++ b/src/Event/AbstractIndexPopulateEvent.php @@ -37,6 +37,7 @@ abstract class AbstractIndexPopulateEvent extends AbstractIndexEvent /** * @var array + * * @phpstan-var TOptions */ protected $options; @@ -67,8 +68,6 @@ public function getOptions(): array /** * @throws \InvalidArgumentException if option does not exist - * - * @return mixed */ public function getOption(string $name) { diff --git a/src/Event/AbstractTransformEvent.php b/src/Event/AbstractTransformEvent.php index 844cfeb63..9672d0b70 100644 --- a/src/Event/AbstractTransformEvent.php +++ b/src/Event/AbstractTransformEvent.php @@ -27,6 +27,7 @@ abstract class AbstractTransformEvent extends Event /** * @var array + * * @phpstan-var TFields */ private $fields; diff --git a/src/Event/PostIndexMappingBuildEvent.php b/src/Event/PostIndexMappingBuildEvent.php index 19fb51f0f..f09acd5dc 100644 --- a/src/Event/PostIndexMappingBuildEvent.php +++ b/src/Event/PostIndexMappingBuildEvent.php @@ -25,6 +25,7 @@ final class PostIndexMappingBuildEvent extends AbstractIndexEvent /** * @var array + * * @phpstan-var TMapping */ private $mapping; diff --git a/src/Event/PreIndexPopulateEvent.php b/src/Event/PreIndexPopulateEvent.php index 19bb61409..2a4d837f7 100644 --- a/src/Event/PreIndexPopulateEvent.php +++ b/src/Event/PreIndexPopulateEvent.php @@ -13,9 +13,6 @@ final class PreIndexPopulateEvent extends AbstractIndexPopulateEvent { - /** - * @param mixed $value - */ public function setOption(string $name, $value): self { $this->options[$name] = $value; diff --git a/src/FOSElasticaBundle.php b/src/FOSElasticaBundle.php index 03fed3ef9..07bd86a2b 100644 --- a/src/FOSElasticaBundle.php +++ b/src/FOSElasticaBundle.php @@ -19,8 +19,6 @@ class FOSElasticaBundle extends Bundle { /** - * {@inheritdoc} - * * @return void */ public function build(ContainerBuilder $container) diff --git a/src/Finder/FinderInterface.php b/src/Finder/FinderInterface.php index 9d72e26f2..b641feaf1 100644 --- a/src/Finder/FinderInterface.php +++ b/src/Finder/FinderInterface.php @@ -30,9 +30,11 @@ interface FinderInterface * Searches for query results within a given limit. * * @param mixed $query Can be a string, an array or an \Elastica\Query object + * * @phpstan-param TQuery $query * * @param int|null $limit How many results to get + * * @phpstan-param TOptions $options * * @return array results diff --git a/src/Finder/PaginatedFinderInterface.php b/src/Finder/PaginatedFinderInterface.php index f773be6ce..44c3518f1 100644 --- a/src/Finder/PaginatedFinderInterface.php +++ b/src/Finder/PaginatedFinderInterface.php @@ -19,8 +19,10 @@ * @phpstan-import-type TQuery from FinderInterface * * @method Pagerfanta findHybridPaginated(mixed $query) Searches for query hybrid results. + * * @phpstan-method Pagerfanta findHybridPaginated(TQuery $query) * @phpstan-method HybridResult[] findHybrid(TQuery $query, ?int $limit = null, array $options = []) + * * @phpstan-import-type TOptions from FinderInterface */ interface PaginatedFinderInterface extends FinderInterface @@ -29,6 +31,7 @@ interface PaginatedFinderInterface extends FinderInterface * Searches for query results and returns them wrapped in a paginator. * * @param mixed $query Can be a string, an array or an \Elastica\Query object + * * @phpstan-param TQuery $query * @phpstan-param TOptions $options * @@ -39,10 +42,11 @@ public function findPaginated($query, array $options = []); /** * Creates a paginator adapter for this query. * - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return PaginatorAdapterInterface */ public function createPaginatorAdapter($query, array $options = []); @@ -50,10 +54,11 @@ public function createPaginatorAdapter($query, array $options = []); /** * Creates a hybrid paginator adapter for this query. * - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return PaginatorAdapterInterface */ public function createHybridPaginatorAdapter($query, array $options = []); @@ -61,10 +66,11 @@ public function createHybridPaginatorAdapter($query, array $options = []); /** * Creates a raw paginator adapter for this query. * - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return PaginatorAdapterInterface */ public function createRawPaginatorAdapter($query, array $options = []); diff --git a/src/Finder/TransformedFinder.php b/src/Finder/TransformedFinder.php index 059860fe6..3294d597f 100644 --- a/src/Finder/TransformedFinder.php +++ b/src/Finder/TransformedFinder.php @@ -38,9 +38,6 @@ public function __construct(SearchableInterface $searchable, ElasticaToModelTran $this->transformer = $transformer; } - /** - * {@inheritdoc} - */ public function find($query, ?int $limit = null, array $options = []) { $results = $this->search($query, $limit, $options); @@ -48,9 +45,6 @@ public function find($query, ?int $limit = null, array $options = []) return $this->transformer->transform($results); } - /** - * {@inheritdoc} - */ public function findHybrid($query, ?int $limit = null, array $options = []) { $results = $this->search($query, $limit, $options); @@ -58,17 +52,11 @@ public function findHybrid($query, ?int $limit = null, array $options = []) return $this->transformer->hybridTransform($results); } - /** - * {@inheritdoc} - */ public function findRaw($query, ?int $limit = null, array $options = []): array { return $this->search($query, $limit, $options); } - /** - * {@inheritdoc} - */ public function findPaginated($query, array $options = []) { $paginatorAdapter = $this->createPaginatorAdapter($query, $options); @@ -76,9 +64,6 @@ public function findPaginated($query, array $options = []) return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter)); } - /** - * {@inheritdoc} - */ public function findHybridPaginated($query, array $options = []) { $paginatorAdapter = $this->createHybridPaginatorAdapter($query, $options); @@ -86,9 +71,6 @@ public function findHybridPaginated($query, array $options = []) return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter)); } - /** - * {@inheritdoc} - */ public function findRawPaginated($query, array $options = []) { $paginatorAdapter = $this->createRawPaginatorAdapter($query, $options); @@ -96,9 +78,6 @@ public function findRawPaginated($query, array $options = []) return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter)); } - /** - * {@inheritdoc} - */ public function createPaginatorAdapter($query, array $options = []) { $query = Query::create($query); @@ -106,9 +85,6 @@ public function createPaginatorAdapter($query, array $options = []) return new TransformedPaginatorAdapter($this->searchable, $query, $options, $this->transformer); } - /** - * {@inheritdoc} - */ public function createHybridPaginatorAdapter($query, array $options = []) { $query = Query::create($query); @@ -116,9 +92,6 @@ public function createHybridPaginatorAdapter($query, array $options = []) return new HybridPaginatorAdapter($this->searchable, $query, $options, $this->transformer); } - /** - * {@inheritdoc} - */ public function createRawPaginatorAdapter($query, array $options = []) { $query = Query::create($query); @@ -127,11 +100,11 @@ public function createRawPaginatorAdapter($query, array $options = []) } /** - * @param mixed $query - * * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return Result[] */ protected function search($query, ?int $limit = null, array $options = []) diff --git a/src/Index/AliasProcessor.php b/src/Index/AliasProcessor.php index fb07ff477..d8b2c74a3 100644 --- a/src/Index/AliasProcessor.php +++ b/src/Index/AliasProcessor.php @@ -180,7 +180,7 @@ private function getAliasedIndex(Client $client, string $aliasName): ?string } if (\count($aliasedIndexes) > 1) { - throw new \RuntimeException(\sprintf('Alias "%s" is used for multiple indexes: ["%s"]. Make sure it\'s'.'either not used or is assigned to one index only', $aliasName, \implode('", "', $aliasedIndexes))); + throw new \RuntimeException(\sprintf('Alias "%s" is used for multiple indexes: ["%s"]. Make sure it\'s either not used or is assigned to one index only', $aliasName, \implode('", "', $aliasedIndexes))); } return \array_shift($aliasedIndexes); diff --git a/src/Logger/ElasticaLogger.php b/src/Logger/ElasticaLogger.php index acb4285d2..e477d08e8 100644 --- a/src/Logger/ElasticaLogger.php +++ b/src/Logger/ElasticaLogger.php @@ -106,9 +106,9 @@ public function getQueries(): array } /** - * {@inheritdoc} - * * @param array $context + * @param mixed $level + * @param mixed $message */ public function log($level, $message, array $context = []): void { diff --git a/src/Message/AsyncPersistPage.php b/src/Message/AsyncPersistPage.php index a87c460cb..f3373ff9a 100644 --- a/src/Message/AsyncPersistPage.php +++ b/src/Message/AsyncPersistPage.php @@ -25,6 +25,7 @@ class AsyncPersistPage /** * @var array + * * @phpstan-var TOptions */ private $options; diff --git a/src/Message/Handler/AsyncPersistPageHandler.php b/src/Message/Handler/AsyncPersistPageHandler.php index 92e7b4497..6902d7cb3 100644 --- a/src/Message/Handler/AsyncPersistPageHandler.php +++ b/src/Message/Handler/AsyncPersistPageHandler.php @@ -13,9 +13,10 @@ use FOS\ElasticaBundle\Message\AsyncPersistPage; use FOS\ElasticaBundle\Persister\AsyncPagerPersister; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; -class AsyncPersistPageHandler implements MessageHandlerInterface +#[AsMessageHandler] +class AsyncPersistPageHandler { private AsyncPagerPersister $persister; diff --git a/src/Paginator/FantaPaginatorAdapter.php b/src/Paginator/FantaPaginatorAdapter.php index 4d0371375..ee7628bea 100644 --- a/src/Paginator/FantaPaginatorAdapter.php +++ b/src/Paginator/FantaPaginatorAdapter.php @@ -15,18 +15,21 @@ /** * @template T + * * @implements AdapterInterface */ class FantaPaginatorAdapter implements AdapterInterface { /** * @var PaginatorAdapterInterface + * * @phpstan-ignore-next-line todo: make PaginatorAdapterInterface generic */ private $adapter; /** * @param PaginatorAdapterInterface $adapter + * * @phpstan-ignore-next-line todo: make PaginatorAdapterInterface generic */ public function __construct(PaginatorAdapterInterface $adapter) diff --git a/src/Paginator/HybridPaginatorAdapter.php b/src/Paginator/HybridPaginatorAdapter.php index a6669413e..49b58a1bd 100644 --- a/src/Paginator/HybridPaginatorAdapter.php +++ b/src/Paginator/HybridPaginatorAdapter.php @@ -34,9 +34,6 @@ public function __construct(SearchableInterface $searchable, Query $query, array $this->transformer = $transformer; } - /** - * {@inheritdoc} - */ public function getResults($offset, $length) { return new HybridPartialResults($this->getElasticaResults($offset, $length), $this->transformer); diff --git a/src/Paginator/HybridPartialResults.php b/src/Paginator/HybridPartialResults.php index ab9bba0fa..1670b3470 100644 --- a/src/Paginator/HybridPartialResults.php +++ b/src/Paginator/HybridPartialResults.php @@ -33,9 +33,8 @@ public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInte } /** - * {@inheritdoc} - * * @return list + * * @phpstan-ignore-next-line */ public function toArray(): array diff --git a/src/Paginator/RawPaginatorAdapter.php b/src/Paginator/RawPaginatorAdapter.php index a7d9ea818..05d8e86d7 100644 --- a/src/Paginator/RawPaginatorAdapter.php +++ b/src/Paginator/RawPaginatorAdapter.php @@ -69,9 +69,6 @@ public function __construct(SearchableInterface $searchable, Query $query, array $this->options = $options; } - /** - * {@inheritdoc} - */ public function getResults($offset, $itemCountPerPage) { return new RawPartialResults($this->getElasticaResults($offset, $itemCountPerPage)); @@ -99,9 +96,6 @@ public function getTotalHits($genuineTotal = false) : $this->totalHits; } - /** - * {@inheritdoc} - */ public function getAggregations() { if (!isset($this->aggregations)) { @@ -111,9 +105,6 @@ public function getAggregations() return $this->aggregations; } - /** - * {@inheritdoc} - */ public function getSuggests() { if (!isset($this->suggests)) { diff --git a/src/Paginator/RawPartialResults.php b/src/Paginator/RawPartialResults.php index 8cb54b57b..ded118bdd 100644 --- a/src/Paginator/RawPartialResults.php +++ b/src/Paginator/RawPartialResults.php @@ -30,8 +30,6 @@ public function __construct(ResultSet $resultSet) } /** - * {@inheritdoc} - * * @return list> */ public function toArray(): array @@ -41,17 +39,11 @@ public function toArray(): array }, $this->resultSet->getResults()); } - /** - * {@inheritdoc} - */ public function getTotalHits(): int { return $this->resultSet->getTotalHits(); } - /** - * {@inheritdoc} - */ public function getAggregations(): array { return $this->resultSet->getAggregations(); diff --git a/src/Paginator/TransformedPaginatorAdapter.php b/src/Paginator/TransformedPaginatorAdapter.php index 070ecfe4d..5008af5fb 100644 --- a/src/Paginator/TransformedPaginatorAdapter.php +++ b/src/Paginator/TransformedPaginatorAdapter.php @@ -34,9 +34,6 @@ public function __construct(SearchableInterface $searchable, Query $query, array $this->transformer = $transformer; } - /** - * {@inheritdoc} - */ public function getResults($offset, $length) { return new TransformedPartialResults($this->getElasticaResults($offset, $length), $this->transformer); diff --git a/src/Paginator/TransformedPartialResults.php b/src/Paginator/TransformedPartialResults.php index abf0a7884..ec2c1251d 100644 --- a/src/Paginator/TransformedPartialResults.php +++ b/src/Paginator/TransformedPartialResults.php @@ -33,6 +33,7 @@ public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInte /** * @return list + * * @phpstan-ignore-next-line */ public function toArray(): array diff --git a/src/Persister/AsyncPagerPersister.php b/src/Persister/AsyncPagerPersister.php index 61152e3d1..ae0b45ec4 100644 --- a/src/Persister/AsyncPagerPersister.php +++ b/src/Persister/AsyncPagerPersister.php @@ -49,9 +49,6 @@ public function __construct( $this->messageBus = $messageBus; } - /** - * {@inheritdoc} - */ public function insert(PagerInterface $pager, array $options = []): void { $pager->setMaxPerPage(empty($options['max_per_page']) ? self::DEFAULT_PAGE_SIZE : $options['max_per_page']); diff --git a/src/Persister/InPlacePagerPersister.php b/src/Persister/InPlacePagerPersister.php index 4766027e0..678df0d5f 100644 --- a/src/Persister/InPlacePagerPersister.php +++ b/src/Persister/InPlacePagerPersister.php @@ -36,9 +36,6 @@ public function __construct(PersisterRegistry $registry, EventDispatcherInterfac $this->dispatcher = $dispatcher; } - /** - * {@inheritdoc} - */ public function insert(PagerInterface $pager, array $options = []) { $pager->setMaxPerPage(empty($options['max_per_page']) ? 100 : $options['max_per_page']); diff --git a/src/Persister/Listener/FilterObjectsListener.php b/src/Persister/Listener/FilterObjectsListener.php index 15fed5e4e..9399a1b01 100644 --- a/src/Persister/Listener/FilterObjectsListener.php +++ b/src/Persister/Listener/FilterObjectsListener.php @@ -47,9 +47,6 @@ public function filterObjects(PreInsertObjectsEvent $event): void $event->setObjects($filtered); } - /** - * {@inheritdoc} - */ public static function getSubscribedEvents(): array { return [ diff --git a/src/Persister/ObjectPersister.php b/src/Persister/ObjectPersister.php index 8f37564cd..8ef9edfb9 100644 --- a/src/Persister/ObjectPersister.php +++ b/src/Persister/ObjectPersister.php @@ -24,6 +24,7 @@ * @author Thibault Duplessis * * @phpstan-type TOptions = array + * * @phpstan-import-type TFields from ModelToElasticaTransformerInterface * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html for TOptions description @@ -44,6 +45,7 @@ class ObjectPersister implements ObjectPersisterInterface protected $objectClass; /** * @var array + * * @phpstan-var TFields */ protected $fields; @@ -53,12 +55,14 @@ class ObjectPersister implements ObjectPersisterInterface protected $logger; /** * @var array + * * @phpstan-var TOptions */ private $options; /** * @param class-string $objectClass + * * @phpstan-param TFields $fields * @phpstan-param TOptions $options */ @@ -71,9 +75,6 @@ public function __construct(Index $index, ModelToElasticaTransformerInterface $t $this->options = $options; } - /** - * {@inheritdoc} - */ public function handlesObject($object): bool { return $object instanceof $this->objectClass; @@ -87,41 +88,26 @@ public function setLogger(LoggerInterface $logger) $this->logger = $logger; } - /** - * {@inheritdoc} - */ public function insertOne($object) { $this->insertMany([$object]); } - /** - * {@inheritdoc} - */ public function replaceOne($object) { $this->replaceMany([$object]); } - /** - * {@inheritdoc} - */ public function deleteOne($object) { $this->deleteMany([$object]); } - /** - * {@inheritdoc} - */ public function deleteById($id, $routing = false) { $this->deleteManyByIdentifiers([$id], $routing); } - /** - * {@inheritdoc} - */ public function insertMany(array $objects) { $documents = []; @@ -135,9 +121,6 @@ public function insertMany(array $objects) } } - /** - * {@inheritdoc} - */ public function replaceMany(array $objects) { $documents = []; @@ -154,9 +137,6 @@ public function replaceMany(array $objects) } } - /** - * {@inheritdoc} - */ public function deleteMany(array $objects) { $documents = []; @@ -170,9 +150,6 @@ public function deleteMany(array $objects) } } - /** - * {@inheritdoc} - */ public function deleteManyByIdentifiers(array $identifiers, $routing = false) { try { diff --git a/src/Persister/ObjectSerializerPersister.php b/src/Persister/ObjectSerializerPersister.php index da36a509e..1bbecfc18 100644 --- a/src/Persister/ObjectSerializerPersister.php +++ b/src/Persister/ObjectSerializerPersister.php @@ -28,12 +28,14 @@ class ObjectSerializerPersister extends ObjectPersister { /** * @var callable + * * @phpstan-var TSerializer */ protected $serializer; /** * @param callable $serializer + * * @phpstan-param TSerializer $serializer */ public function __construct(Index $index, ModelToElasticaTransformerInterface $transformer, string $objectClass, $serializer, array $options = []) diff --git a/src/Persister/PagerPersisterInterface.php b/src/Persister/PagerPersisterInterface.php index c8b7347e9..55b8f50c2 100644 --- a/src/Persister/PagerPersisterInterface.php +++ b/src/Persister/PagerPersisterInterface.php @@ -16,6 +16,7 @@ /** * @phpstan-import-type TOptions from AbstractIndexPopulateEvent + * * @phpstan-type TPagerPersisterOptions = TOptions|array{} */ interface PagerPersisterInterface diff --git a/src/Provider/Indexable.php b/src/Provider/Indexable.php index c1cffb010..4558ba718 100644 --- a/src/Provider/Indexable.php +++ b/src/Provider/Indexable.php @@ -25,6 +25,7 @@ class Indexable implements IndexableInterface * An array of raw configured callbacks for all types. * * @var array + * * @phpstan-var array */ private $callbacks = []; @@ -40,6 +41,7 @@ class Indexable implements IndexableInterface * An array of initialised callbacks. * * @var array + * * @phpstan-var array */ private $initialisedCallbacks = []; @@ -77,6 +79,7 @@ public function isObjectIndexable(string $indexName, object $object): bool * Builds and initialises a callback. * * @return callable|string|ExpressionLanguage|null + * * @phpstan-return TCallbackInternal */ private function buildCallback(string $index, object $object) @@ -124,7 +127,6 @@ private function buildExpressionCallback(string $index, object $object, string $ /** * Retreives a cached callback, or creates a new callback if one is not found. * - * @return mixed * @phpstan-return TCallbackInternal */ private function getCallback(string $index, object $object) @@ -154,7 +156,7 @@ private function getExpressionLanguage(): ?ExpressionLanguage * Returns the variable name to be used to access the object when using the ExpressionLanguage * component to parse and evaluate an expression. * - * @param mixed $object + * @param mixed|null $object */ private function getExpressionVar($object = null): string { diff --git a/src/Provider/PagerProviderInterface.php b/src/Provider/PagerProviderInterface.php index 759d3875f..7ce737227 100644 --- a/src/Provider/PagerProviderInterface.php +++ b/src/Provider/PagerProviderInterface.php @@ -15,6 +15,7 @@ /** * @phpstan-import-type TOptions from AbstractIndexPopulateEvent + * * @phpstan-type TPagerProviderOptions = TOptions|array */ interface PagerProviderInterface diff --git a/src/Provider/PagerfantaPager.php b/src/Provider/PagerfantaPager.php index e11132c32..e8f8437d5 100644 --- a/src/Provider/PagerfantaPager.php +++ b/src/Provider/PagerfantaPager.php @@ -31,49 +31,31 @@ public function __construct(Pagerfanta $pagerfanta) $this->pagerfanta = $pagerfanta; } - /** - * {@inheritdoc} - */ public function getNbResults(): int { return $this->pagerfanta->getNbResults(); } - /** - * {@inheritdoc} - */ public function getNbPages(): int { return $this->pagerfanta->getNbPages(); } - /** - * {@inheritdoc} - */ public function getCurrentPage(): int { return $this->pagerfanta->getCurrentPage(); } - /** - * {@inheritdoc} - */ public function setCurrentPage(int $page) { $this->pagerfanta->setCurrentPage($page); } - /** - * {@inheritdoc} - */ public function getMaxPerPage(): int { return $this->pagerfanta->getMaxPerPage(); } - /** - * {@inheritdoc} - */ public function setMaxPerPage(int $perPage) { $this->pagerfanta->setMaxPerPage($perPage); diff --git a/src/Repository.php b/src/Repository.php index b40b4f79c..479d885aa 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -33,10 +33,11 @@ public function __construct(PaginatedFinderInterface $finder) } /** - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return array */ public function find($query, ?int $limit = null, array $options = []) @@ -45,10 +46,11 @@ public function find($query, ?int $limit = null, array $options = []) } /** - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return list */ public function findHybrid($query, ?int $limit = null, array $options = []) @@ -57,10 +59,11 @@ public function findHybrid($query, ?int $limit = null, array $options = []) } /** - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return \Pagerfanta\Pagerfanta */ public function findPaginated($query, array $options = []) @@ -69,10 +72,11 @@ public function findPaginated($query, array $options = []) } /** - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return Paginator\PaginatorAdapterInterface */ public function createPaginatorAdapter($query, array $options = []) @@ -81,10 +85,11 @@ public function createPaginatorAdapter($query, array $options = []) } /** - * @param mixed $query * @phpstan-param TQuery $query * @phpstan-param TOptions $options * + * @param mixed $query + * * @return Paginator\PaginatorAdapterInterface */ public function createHybridPaginatorAdapter($query, array $options = []) diff --git a/src/Serializer/Callback.php b/src/Serializer/Callback.php index 6d7c53042..27f6b6134 100644 --- a/src/Serializer/Callback.php +++ b/src/Serializer/Callback.php @@ -81,9 +81,6 @@ public function setSerializeNull(bool $serializeNull): self return $this; } - /** - * @param mixed $object - */ public function serialize($object): string { $context = $this->serializer instanceof JMSSerializer ? SerializationContext::create()->enableMaxDepthChecks() : []; diff --git a/src/Transformer/HighlightableModelInterface.php b/src/Transformer/HighlightableModelInterface.php index e49d0c3a9..7df8e4b01 100644 --- a/src/Transformer/HighlightableModelInterface.php +++ b/src/Transformer/HighlightableModelInterface.php @@ -20,8 +20,6 @@ interface HighlightableModelInterface { /** * Returns a unique identifier for the model. - * - * @return mixed */ public function getId(); @@ -29,6 +27,7 @@ public function getId(); * Set ElasticSearch highlight data. * * @param array $highlights array of highlight strings + * * @phpstan-param list $highlights * * @return void diff --git a/src/Transformer/ModelToElasticaAutoTransformer.php b/src/Transformer/ModelToElasticaAutoTransformer.php index 2e9a8746c..b804c5fd8 100644 --- a/src/Transformer/ModelToElasticaAutoTransformer.php +++ b/src/Transformer/ModelToElasticaAutoTransformer.php @@ -23,6 +23,7 @@ * elastica documents ids and doctrine object ids. * * @phpstan-import-type TFields from ModelToElasticaTransformerInterface + * * @phpstan-type TOptions = array{identifier: string, index: string} */ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface @@ -36,6 +37,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf * Optional parameters. * * @var array + * * @phpstan-var TOptions */ protected $options = [ @@ -84,6 +86,7 @@ public function transform(object $object, array $fields): Document * * @param array|\Traversable|\ArrayAccess|null $objects the object to convert * @param array $fields the keys we want to have in the returned array + * * @phpstan-param TFields $fields * * @return array diff --git a/tests/Functional/ProfilerTest.php b/tests/Functional/ProfilerTest.php index f0c69ea22..59b11999f 100644 --- a/tests/Functional/ProfilerTest.php +++ b/tests/Functional/ProfilerTest.php @@ -55,7 +55,10 @@ public function setUp(): void $fragmentHandlerMock = $this->createMock(FragmentHandler::class); $loaderMock = $this->createMock(RuntimeLoaderInterface::class); - $this->twig->addExtension(new CodeExtension('', '', '')); + if (\class_exists('Symfony\Bridge\Twig\Extension\CodeExtension')) { + $this->twig->addExtension(new CodeExtension('', '', '')); + } + $this->twig->addExtension(new RoutingExtension($urlGeneratorMock)); $this->twig->addExtension(new HttpKernelExtension()); @@ -85,6 +88,7 @@ public function testRender($query) 'request' => $request, 'collector' => $this->collector, 'queries' => $this->logger->getQueries(), + 'profile_type' => 'request', ]); $output = \str_replace('"', '"', $output); diff --git a/tests/Functional/app/config/config.yml b/tests/Functional/app/config/config.yml index 5ea4ce562..e871cb8f6 100644 --- a/tests/Functional/app/config/config.yml +++ b/tests/Functional/app/config/config.yml @@ -1,7 +1,6 @@ framework: test: true secret: secret - annotations: ~ services: logger: { class: Psr\Log\NullLogger } diff --git a/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php b/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php index 412dcf1cc..d0a5df9dc 100644 --- a/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php +++ b/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php @@ -63,7 +63,8 @@ protected function setUp(): void 'findBy', 'findOneBy', 'getClassName', - ])->getMock(); + ])->getMock() + ; $this->manager->expects($this->any()) ->method('getRepository') diff --git a/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php b/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php index 664f719ef..a23db113c 100644 --- a/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php +++ b/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php @@ -66,7 +66,8 @@ protected function setUp(): void 'findOneBy', 'getClassName', 'findMany', - ])->getMock(); + ])->getMock() + ; $this->repository->expects($this->any()) ->method('findMany') diff --git a/tests/Unit/Doctrine/RepositoryManagerTest.php b/tests/Unit/Doctrine/RepositoryManagerTest.php index a94884d7c..3faf80fa9 100644 --- a/tests/Unit/Doctrine/RepositoryManagerTest.php +++ b/tests/Unit/Doctrine/RepositoryManagerTest.php @@ -56,15 +56,18 @@ public function testGetRepositoryShouldResolveEntityShortName() $registryMock = $this->createMock(ManagerRegistry::class); $mainManager = $this->createMock(RepositoryManagerInterface::class); - $registryMock->method('getAliasNamespace') - ->with($this->equalTo('FOSElasticaBundle')) - ->willReturn((new \ReflectionClass(NamespacedEntity::class))->getNamespaceName()) - ; + // @link https://github.com/doctrine/persistence/pull/204 + if (\method_exists(ManagerRegistry::class, 'getAliasNamespace')) { + $registryMock->method('getAliasNamespace') + ->with($this->equalTo('FOSElasticaBundle')) + ->willReturn((new \ReflectionClass(NamespacedEntity::class))->getNamespaceName()) + ; - $mainManager->method('getRepository') - ->with($this->equalTo('index')) - ->willReturn(new Repository($finderMock)) - ; + $mainManager->method('getRepository') + ->with($this->equalTo('index')) + ->willReturn(new Repository($finderMock)) + ; + } $manager = new RepositoryManager($registryMock, $mainManager); $manager->addEntity(NamespacedEntity::class, 'index'); diff --git a/tests/Unit/Index/IndexTemplateManagerTest.php b/tests/Unit/Index/IndexTemplateManagerTest.php index e83ea519c..973588e43 100644 --- a/tests/Unit/Index/IndexTemplateManagerTest.php +++ b/tests/Unit/Index/IndexTemplateManagerTest.php @@ -26,8 +26,8 @@ class IndexTemplateManagerTest extends TestCase * Test get index template. * * @param string $name - * @param mixed $expectedTemplate * @param string|null $expectedException + * @param mixed $expectedTemplate * * @return void *