Skip to content

Commit b6d8b19

Browse files
authored
IBX-9727: Added missing strict types and adapted the codebase to PHP 8.3 (#101)
1 parent ec78a0b commit b6d8b19

File tree

231 files changed

+1630
-3799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+1630
-3799
lines changed

phpstan-baseline.neon

Lines changed: 294 additions & 1354 deletions
Large diffs are not rendered by default.

src/bundle/ApiLoader/BoostFactorProviderFactory.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,26 @@
88
namespace Ibexa\Bundle\Solr\ApiLoader;
99

1010
use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface;
11+
use Ibexa\Solr\FieldMapper\BoostFactorProvider;
1112
use Symfony\Component\DependencyInjection\ContainerInterface;
1213

1314
/**
1415
* BoostFactorProvider service factory takes into account boost factor semantic configuration.
1516
*/
16-
class BoostFactorProviderFactory
17+
readonly class BoostFactorProviderFactory
1718
{
18-
private ContainerInterface $container;
19-
20-
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;
21-
22-
/**
23-
* @var string
24-
*/
25-
private $defaultConnection;
26-
27-
/**
28-
* @var string
29-
*/
30-
private $boostFactorProviderClass;
31-
3219
/**
33-
* @param string $defaultConnection
34-
* @param string $boostFactorProviderClass
20+
* @param class-string<\Ibexa\Solr\FieldMapper\BoostFactorProvider> $boostFactorProviderClass
3521
*/
3622
public function __construct(
37-
ContainerInterface $container,
38-
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
39-
$defaultConnection,
40-
$boostFactorProviderClass
23+
private ContainerInterface $container,
24+
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
25+
private string $defaultConnection,
26+
private string $boostFactorProviderClass
4127
) {
42-
$this->container = $container;
43-
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
44-
$this->defaultConnection = $defaultConnection;
45-
$this->boostFactorProviderClass = $boostFactorProviderClass;
4628
}
4729

48-
public function buildService()
30+
public function buildService(): BoostFactorProvider
4931
{
5032
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();
5133

@@ -55,7 +37,7 @@ public function buildService()
5537
}
5638

5739
return new $this->boostFactorProviderClass(
58-
$this->container->getParameter(
40+
(array)$this->container->getParameter(
5941
"ibexa.solr.connection.{$connection}.boost_factor_map_id"
6042
)
6143
);

src/bundle/ApiLoader/IndexingDepthProviderFactory.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,23 @@
99
namespace Ibexa\Bundle\Solr\ApiLoader;
1010

1111
use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface;
12+
use Ibexa\Solr\FieldMapper\IndexingDepthProvider;
1213
use Symfony\Component\DependencyInjection\ContainerInterface;
1314

14-
class IndexingDepthProviderFactory
15+
readonly class IndexingDepthProviderFactory
1516
{
16-
private ContainerInterface $container;
17-
18-
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;
19-
20-
private string $defaultConnection;
21-
22-
private string $indexingDepthProviderClass;
23-
17+
/**
18+
* @param class-string<\Ibexa\Solr\FieldMapper\IndexingDepthProvider> $indexingDepthProviderClass
19+
*/
2420
public function __construct(
25-
ContainerInterface $container,
26-
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
27-
string $defaultConnection,
28-
string $indexingDepthProviderClass
21+
private ContainerInterface $container,
22+
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
23+
private string $defaultConnection,
24+
private string $indexingDepthProviderClass
2925
) {
30-
$this->container = $container;
31-
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
32-
$this->defaultConnection = $defaultConnection;
33-
$this->indexingDepthProviderClass = $indexingDepthProviderClass;
3426
}
3527

36-
public function buildService()
28+
public function buildService(): IndexingDepthProvider
3729
{
3830
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();
3931

@@ -43,10 +35,10 @@ public function buildService()
4335
}
4436

4537
return new $this->indexingDepthProviderClass(
46-
$this->container->getParameter(
38+
(array)$this->container->getParameter(
4739
"ibexa.solr.connection.{$connection}.indexing_depth.map"
4840
),
49-
$this->container->getParameter(
41+
(int)$this->container->getParameter(
5042
"ibexa.solr.connection.{$connection}.indexing_depth.default"
5143
)
5244
);

src/bundle/ApiLoader/SolrEngineFactory.php

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,25 @@
1414
use Ibexa\Solr\Gateway\GatewayRegistry;
1515
use Ibexa\Solr\ResultExtractor;
1616

17-
class SolrEngineFactory
17+
readonly class SolrEngineFactory
1818
{
19-
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;
20-
21-
/** @var string */
22-
private $defaultConnection;
23-
24-
/** @var string */
25-
private $searchEngineClass;
26-
27-
private GatewayRegistry $gatewayRegistry;
28-
29-
private CoreFilterRegistry $coreFilterRegistry;
30-
31-
private Handler $contentHandler;
32-
33-
private DocumentMapper $documentMapper;
34-
35-
private ResultExtractor $contentResultExtractor;
36-
37-
private ResultExtractor $locationResultExtractor;
38-
19+
/**
20+
* @param class-string<\Ibexa\Solr\Handler> $searchEngineClass
21+
*/
3922
public function __construct(
40-
RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
41-
$defaultConnection,
42-
$searchEngineClass,
43-
GatewayRegistry $gatewayRegistry,
44-
CoreFilterRegistry $coreFilterRegistry,
45-
Handler $contentHandler,
46-
DocumentMapper $documentMapper,
47-
ResultExtractor $contentResultExtractor,
48-
ResultExtractor $locationResultExtractor
23+
private RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
24+
private string $defaultConnection,
25+
private string $searchEngineClass,
26+
private GatewayRegistry $gatewayRegistry,
27+
private CoreFilterRegistry $coreFilterRegistry,
28+
private Handler $contentHandler,
29+
private DocumentMapper $documentMapper,
30+
private ResultExtractor $contentResultExtractor,
31+
private ResultExtractor $locationResultExtractor
4932
) {
50-
$this->repositoryConfigurationProvider = $repositoryConfigurationProvider;
51-
$this->defaultConnection = $defaultConnection;
52-
$this->searchEngineClass = $searchEngineClass;
53-
$this->gatewayRegistry = $gatewayRegistry;
54-
$this->coreFilterRegistry = $coreFilterRegistry;
55-
$this->contentHandler = $contentHandler;
56-
$this->documentMapper = $documentMapper;
57-
$this->contentResultExtractor = $contentResultExtractor;
58-
$this->locationResultExtractor = $locationResultExtractor;
5933
}
6034

61-
public function buildEngine()
35+
public function buildEngine(): \Ibexa\Solr\Handler
6236
{
6337
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();
6438

src/bundle/DependencyInjection/Configuration.php

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313

1414
class Configuration implements ConfigurationInterface
1515
{
16-
public const SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT = 10;
17-
public const SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES = 3;
18-
19-
protected $rootNodeName;
16+
public const int SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT = 10;
17+
public const int SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES = 3;
2018

2119
/**
2220
* Holds default endpoint values.
2321
*
24-
* @var array
22+
* @var array<string, string|int|null>
2523
*/
26-
protected $defaultEndpointValues = [
24+
protected array $defaultEndpointValues = [
2725
'scheme' => 'http',
2826
'host' => '127.0.0.1',
2927
'port' => 8983,
@@ -32,14 +30,15 @@ class Configuration implements ConfigurationInterface
3230
'path' => '/solr',
3331
];
3432

35-
protected $metaFieldNames = [
33+
/** @var list<string> */
34+
protected array $metaFieldNames = [
3635
'name',
3736
'text',
3837
];
3938

40-
public function __construct($rootNodeName)
41-
{
42-
$this->rootNodeName = $rootNodeName;
39+
public function __construct(
40+
protected string $rootNodeName
41+
) {
4342
}
4443

4544
public function getConfigTreeBuilder(): TreeBuilder
@@ -58,7 +57,7 @@ public function getConfigTreeBuilder(): TreeBuilder
5857
/**
5958
* Adds endpoints definition.
6059
*/
61-
protected function addEndpointsSection(ArrayNodeDefinition $node)
60+
protected function addEndpointsSection(ArrayNodeDefinition $node): void
6261
{
6362
$node->children()
6463
->arrayNode('endpoints')
@@ -103,7 +102,7 @@ protected function addEndpointsSection(ArrayNodeDefinition $node)
103102
*
104103
* @throws \RuntimeException
105104
*/
106-
protected function addConnectionsSection(ArrayNodeDefinition $node)
105+
protected function addConnectionsSection(ArrayNodeDefinition $node): void
107106
{
108107
$node->children()
109108
->scalarNode('default_connection')
@@ -116,11 +115,7 @@ protected function addConnectionsSection(ArrayNodeDefinition $node)
116115
->prototype('array')
117116
->beforeNormalization()
118117
->ifTrue(
119-
static function ($v): bool {
120-
return
121-
!empty($v['mapping']) && !\is_array($v['mapping'])
122-
;
123-
}
118+
static fn ($v): bool => !empty($v['mapping']) && !\is_array($v['mapping'])
124119
)
125120
->then(
126121
static function (array $v) {
@@ -136,16 +131,12 @@ static function (array $v) {
136131
->end()
137132
->beforeNormalization()
138133
->ifTrue(
139-
static function ($v): bool {
140-
return
141-
empty($v['entry_endpoints']) &&
142-
(
143-
!empty($v['mapping']['translations']) ||
144-
!empty($v['mapping']['default']) ||
145-
!empty($v['mapping']['main_translations'])
146-
)
147-
;
148-
}
134+
static fn ($v): bool => empty($v['entry_endpoints']) &&
135+
(
136+
!empty($v['mapping']['translations']) ||
137+
!empty($v['mapping']['default']) ||
138+
!empty($v['mapping']['main_translations'])
139+
)
149140
)
150141
->then(
151142
// If entry endpoints are not provided use mapping endpoints

src/bundle/DependencyInjection/IbexaSolrExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class IbexaSolrExtension extends ConfigurableExtension
7171

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

74+
#[\Override]
7475
public function getAlias(): string
7576
{
7677
return 'ibexa_solr';
@@ -125,10 +126,9 @@ protected function processConnectionConfiguration(ContainerBuilder $container, a
125126
$config['default_connection']
126127
);
127128
} elseif (!empty($config['connections'])) {
128-
reset($config['connections']);
129129
$container->setParameter(
130130
"{$alias}.default_connection",
131-
key($config['connections'])
131+
array_key_first($config['connections'])
132132
);
133133
}
134134

@@ -265,6 +265,7 @@ protected function defineEndpoint(ContainerBuilder $container, string $alias, ar
265265
/**
266266
* @param array<array<mixed>> $config
267267
*/
268+
#[\Override]
268269
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
269270
{
270271
return new Configuration($this->getAlias());

src/bundle/IbexaSolrBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function build(ContainerBuilder $container): void
3636
$container->addCompilerPass(new CoreFilterRegistryPass());
3737
}
3838

39+
#[\Override]
3940
public function getContainerExtension(): ?ExtensionInterface
4041
{
4142
if (!isset($this->extension)) {

src/contracts/DocumentMapper.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,23 @@ interface DocumentMapper
2020
{
2121
/**
2222
* Identifier of Content documents.
23-
*
24-
* @var string
2523
*/
26-
public const DOCUMENT_TYPE_IDENTIFIER_CONTENT = 'content';
24+
public const string DOCUMENT_TYPE_IDENTIFIER_CONTENT = 'content';
2725

2826
/**
2927
* Identifier of Location documents.
30-
*
31-
* @var string
3228
*/
33-
public const DOCUMENT_TYPE_IDENTIFIER_LOCATION = 'location';
29+
public const string DOCUMENT_TYPE_IDENTIFIER_LOCATION = 'location';
3430

3531
/**
3632
* Maps given Content and it's Locations to a collection of nested Documents,
3733
* one per translation.
3834
*
3935
* Each Content Document contains nested Documents representing it's Locations.
4036
*
41-
* @return \Ibexa\Contracts\Core\Search\Document[]
37+
* @return list<\Ibexa\Contracts\Core\Search\Document>
4238
*/
43-
public function mapContentBlock(Content $content);
39+
public function mapContentBlock(Content $content): array;
4440

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

6051
/**
6152
* Generates the Solr backend document ID for Location object.
@@ -64,11 +55,6 @@ public function generateContentDocumentId($contentId, $languageCode = null);
6455
* of all Location's documents (there will be one document per translation).
6556
* The above is useful when targeting all Location's documents, without
6657
* the knowledge of it's Content's translations.
67-
*
68-
* @param int|string $locationId
69-
* @param string $languageCode
70-
*
71-
* @return string
7258
*/
73-
public function generateLocationDocumentId($locationId, $languageCode = null);
59+
public function generateLocationDocumentId(int $locationId, ?string $languageCode = null): string;
7460
}

src/contracts/FieldMapper/ContentFieldMapper.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ abstract class ContentFieldMapper
1818
{
1919
/**
2020
* Indicates if the mapper accepts the given $content for mapping.
21-
*
22-
* @return bool
2321
*/
24-
abstract public function accept(SPIContent $content);
22+
abstract public function accept(SPIContent $content): bool;
2523

2624
/**
2725
* Maps given $content to an array of search fields.
2826
*
29-
* @return \Ibexa\Contracts\Core\Search\Field[]
27+
* @return list<\Ibexa\Contracts\Core\Search\Field>
3028
*/
31-
abstract public function mapFields(SPIContent $content);
29+
abstract public function mapFields(SPIContent $content): array;
3230
}

0 commit comments

Comments
 (0)