Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,648 changes: 294 additions & 1,354 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

36 changes: 8 additions & 28 deletions src/bundle/ApiLoader/BoostFactorProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,23 @@
namespace Ibexa\Bundle\Solr\ApiLoader;

use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface;
use Ibexa\Solr\FieldMapper\BoostFactorProvider;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* BoostFactorProvider service factory takes into account boost factor semantic configuration.
*/
class BoostFactorProviderFactory
readonly class BoostFactorProviderFactory
{
private ContainerInterface $container;

private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;

/**
* @var string
*/
private $defaultConnection;

/**
* @var string
*/
private $boostFactorProviderClass;

/**
* @param string $defaultConnection
* @param string $boostFactorProviderClass
*/
public function __construct(
ContainerInterface $container,
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
$defaultConnection,
$boostFactorProviderClass
private ContainerInterface $container,
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
private string $defaultConnection,
private string $boostFactorProviderClass
) {
$this->container = $container;
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
$this->defaultConnection = $defaultConnection;
$this->boostFactorProviderClass = $boostFactorProviderClass;
}

public function buildService()
public function buildService(): BoostFactorProvider
{
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();

Expand All @@ -54,6 +33,7 @@ public function buildService()
$connection = $repositoryConfig['search']['connection'];
}

/** @var \Ibexa\Solr\FieldMapper\BoostFactorProvider */
return new $this->boostFactorProviderClass(
$this->container->getParameter(
"ibexa.solr.connection.{$connection}.boost_factor_map_id"
Expand Down
26 changes: 8 additions & 18 deletions src/bundle/ApiLoader/IndexingDepthProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,20 @@
namespace Ibexa\Bundle\Solr\ApiLoader;

use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface;
use Ibexa\Solr\FieldMapper\IndexingDepthProvider;
use Symfony\Component\DependencyInjection\ContainerInterface;

class IndexingDepthProviderFactory
readonly class IndexingDepthProviderFactory
{
private ContainerInterface $container;

private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;

private string $defaultConnection;

private string $indexingDepthProviderClass;

public function __construct(
ContainerInterface $container,
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
string $defaultConnection,
string $indexingDepthProviderClass
private ContainerInterface $container,
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
private string $defaultConnection,
private string $indexingDepthProviderClass
) {
$this->container = $container;
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
$this->defaultConnection = $defaultConnection;
$this->indexingDepthProviderClass = $indexingDepthProviderClass;
}

public function buildService()
public function buildService(): IndexingDepthProvider
{
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();

Expand All @@ -42,6 +31,7 @@ public function buildService()
$connection = $repositoryConfig['search']['connection'];
}

/** @var \Ibexa\Solr\FieldMapper\IndexingDepthProvider */
return new $this->indexingDepthProviderClass(
$this->container->getParameter(
"ibexa.solr.connection.{$connection}.indexing_depth.map"
Expand Down
52 changes: 12 additions & 40 deletions src/bundle/ApiLoader/SolrEngineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,22 @@
use Ibexa\Solr\Gateway\GatewayRegistry;
use Ibexa\Solr\ResultExtractor;

class SolrEngineFactory
readonly class SolrEngineFactory
{
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;

/** @var string */
private $defaultConnection;

/** @var string */
private $searchEngineClass;

private GatewayRegistry $gatewayRegistry;

private CoreFilterRegistry $coreFilterRegistry;

private Handler $contentHandler;

private DocumentMapper $documentMapper;

private ResultExtractor $contentResultExtractor;

private ResultExtractor $locationResultExtractor;

public function __construct(
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
$defaultConnection,
$searchEngineClass,
GatewayRegistry $gatewayRegistry,
CoreFilterRegistry $coreFilterRegistry,
Handler $contentHandler,
DocumentMapper $documentMapper,
ResultExtractor $contentResultExtractor,
ResultExtractor $locationResultExtractor
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
private string $defaultConnection,
private string $searchEngineClass,
private GatewayRegistry $gatewayRegistry,
private CoreFilterRegistry $coreFilterRegistry,
private Handler $contentHandler,
private DocumentMapper $documentMapper,
private ResultExtractor $contentResultExtractor,
private ResultExtractor $locationResultExtractor
) {
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
$this->defaultConnection = $defaultConnection;
$this->searchEngineClass = $searchEngineClass;
$this->gatewayRegistry = $gatewayRegistry;
$this->coreFilterRegistry = $coreFilterRegistry;
$this->contentHandler = $contentHandler;
$this->documentMapper = $documentMapper;
$this->contentResultExtractor = $contentResultExtractor;
$this->locationResultExtractor = $locationResultExtractor;
}

public function buildEngine()
public function buildEngine(): \Ibexa\Solr\Handler
{
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();

Expand All @@ -67,6 +38,7 @@ public function buildEngine()
$gateway = $this->gatewayRegistry->getGateway($connection);
$coreFilter = $this->coreFilterRegistry->getCoreFilter($connection);

/** @var \Ibexa\Solr\Handler */
return new $this->searchEngineClass(
$gateway,
$this->contentHandler,
Expand Down
45 changes: 18 additions & 27 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@

class Configuration implements ConfigurationInterface
{
public const SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT = 10;
public const SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES = 3;

protected $rootNodeName;
public const int SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT = 10;
public const int SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES = 3;

/**
* Holds default endpoint values.
*
* @var array
* @var array<string, string|int|null>
*/
protected $defaultEndpointValues = [
protected array $defaultEndpointValues = [
'scheme' => 'http',
'host' => '127.0.0.1',
'port' => 8983,
Expand All @@ -32,14 +30,15 @@ class Configuration implements ConfigurationInterface
'path' => '/solr',
];

protected $metaFieldNames = [
/** @var list<string> */
protected array $metaFieldNames = [
'name',
'text',
];

public function __construct($rootNodeName)
{
$this->rootNodeName = $rootNodeName;
public function __construct(
protected string $rootNodeName
) {
}

public function getConfigTreeBuilder(): TreeBuilder
Expand All @@ -58,7 +57,7 @@ public function getConfigTreeBuilder(): TreeBuilder
/**
* Adds endpoints definition.
*/
protected function addEndpointsSection(ArrayNodeDefinition $node)
protected function addEndpointsSection(ArrayNodeDefinition $node): void
{
$node->children()
->arrayNode('endpoints')
Expand Down Expand Up @@ -103,7 +102,7 @@ protected function addEndpointsSection(ArrayNodeDefinition $node)
*
* @throws \RuntimeException
*/
protected function addConnectionsSection(ArrayNodeDefinition $node)
protected function addConnectionsSection(ArrayNodeDefinition $node): void
{
$node->children()
->scalarNode('default_connection')
Expand All @@ -116,11 +115,7 @@ protected function addConnectionsSection(ArrayNodeDefinition $node)
->prototype('array')
->beforeNormalization()
->ifTrue(
static function ($v): bool {
return
!empty($v['mapping']) && !\is_array($v['mapping'])
;
}
static fn ($v): bool => !empty($v['mapping']) && !\is_array($v['mapping'])
)
->then(
static function (array $v) {
Expand All @@ -136,16 +131,12 @@ static function (array $v) {
->end()
->beforeNormalization()
->ifTrue(
static function ($v): bool {
return
empty($v['entry_endpoints']) &&
(
!empty($v['mapping']['translations']) ||
!empty($v['mapping']['default']) ||
!empty($v['mapping']['main_translations'])
)
;
}
static fn ($v): bool => empty($v['entry_endpoints']) &&
(
!empty($v['mapping']['translations']) ||
!empty($v['mapping']['default']) ||
!empty($v['mapping']['main_translations'])
)
)
->then(
// If entry endpoints are not provided use mapping endpoints
Expand Down
5 changes: 3 additions & 2 deletions src/bundle/DependencyInjection/IbexaSolrExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class IbexaSolrExtension extends ConfigurableExtension

public const string GATEWAY_UPDATE_SERIALIZER_TAG = 'ibexa.solr.gateway.serializer.update';

#[\Override]
public function getAlias(): string
{
return 'ibexa_solr';
Expand Down Expand Up @@ -125,10 +126,9 @@ protected function processConnectionConfiguration(ContainerBuilder $container, a
$config['default_connection']
);
} elseif (!empty($config['connections'])) {
reset($config['connections']);
$container->setParameter(
"{$alias}.default_connection",
key($config['connections'])
array_key_first($config['connections'])
);
}

Expand Down Expand Up @@ -265,6 +265,7 @@ protected function defineEndpoint(ContainerBuilder $container, string $alias, ar
/**
* @param array<array<mixed>> $config
*/
#[\Override]
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
return new Configuration($this->getAlias());
Expand Down
1 change: 1 addition & 0 deletions src/bundle/IbexaSolrBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new CoreFilterRegistryPass());
}

#[\Override]
public function getContainerExtension(): ?ExtensionInterface
{
if (!isset($this->extension)) {
Expand Down
26 changes: 6 additions & 20 deletions src/contracts/DocumentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@ interface DocumentMapper
{
/**
* Identifier of Content documents.
*
* @var string
*/
public const DOCUMENT_TYPE_IDENTIFIER_CONTENT = 'content';
public const string DOCUMENT_TYPE_IDENTIFIER_CONTENT = 'content';

/**
* Identifier of Location documents.
*
* @var string
*/
public const DOCUMENT_TYPE_IDENTIFIER_LOCATION = 'location';
public const string DOCUMENT_TYPE_IDENTIFIER_LOCATION = 'location';

/**
* Maps given Content and it's Locations to a collection of nested Documents,
* one per translation.
*
* Each Content Document contains nested Documents representing it's Locations.
*
* @return \Ibexa\Contracts\Core\Search\Document[]
* @return list<\Ibexa\Contracts\Core\Search\Document>
*/
public function mapContentBlock(Content $content);
public function mapContentBlock(Content $content): array;

/**
* Generates the Solr backend document ID for Content object.
Expand All @@ -49,13 +45,8 @@ public function mapContentBlock(Content $content);
* of all Content's documents (there will be one document per translation).
* The above is useful when targeting all Content's documents, without
* the knowledge of it's translations.
*
* @param int|string $contentId
* @param string $languageCode
*
* @return string
*/
public function generateContentDocumentId($contentId, $languageCode = null);
public function generateContentDocumentId(int $contentId, ?string $languageCode = null): string;

/**
* Generates the Solr backend document ID for Location object.
Expand All @@ -64,11 +55,6 @@ public function generateContentDocumentId($contentId, $languageCode = null);
* of all Location's documents (there will be one document per translation).
* The above is useful when targeting all Location's documents, without
* the knowledge of it's Content's translations.
*
* @param int|string $locationId
* @param string $languageCode
*
* @return string
*/
public function generateLocationDocumentId($locationId, $languageCode = null);
public function generateLocationDocumentId(int $locationId, ?string $languageCode = null): string;
}
8 changes: 3 additions & 5 deletions src/contracts/FieldMapper/ContentFieldMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ abstract class ContentFieldMapper
{
/**
* Indicates if the mapper accepts the given $content for mapping.
*
* @return bool
*/
abstract public function accept(SPIContent $content);
abstract public function accept(SPIContent $content): bool;

/**
* Maps given $content to an array of search fields.
*
* @return \Ibexa\Contracts\Core\Search\Field[]
* @return list<\Ibexa\Contracts\Core\Search\Field>
*/
abstract public function mapFields(SPIContent $content);
abstract public function mapFields(SPIContent $content): array;
}
Loading
Loading