Skip to content

Commit

Permalink
IBX-8470: Upgraded codebase to Symfony 6 (#50)
Browse files Browse the repository at this point in the history
* Bumped Symfony packages requirements to ^6.4
* [CS] Upgraded Ibexa Code Style to ~2.0.0
* [Tests] Fixed incorrect usage of expectException
* Upgraded Symfony Forms extension points code
* Upgraded Symfony Bundle extension points code
* Upgraded Ibexa Core extension points code
* Improved SearchFacetsExtension Twig extension code
* [PHPStan] Removed resolved issues from the baseline
* Changed ContentTypeChoiceLoader constructor to use property promotion
* [Composer] Bumped Pagerfanta to v3
* Updated phpstan baseline

---------

Co-authored-by: Konrad Oboza <[email protected]>
Co-authored-by: Adam Wójs <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2025
1 parent e3cdfdf commit 0089459
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 130 deletions.
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
"require": {
"php": " >=8.3",
"ibexa/core": "~5.0.x-dev",
"pagerfanta/pagerfanta": "^2.1",
"symfony/config": "^5.0",
"symfony/dependency-injection": "^5.0",
"symfony/event-dispatcher": "^5.0",
"symfony/form": "^5.0",
"symfony/http-foundation": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/serializer": "^5.4"
"pagerfanta/pagerfanta": "^3.6.2",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
"symfony/form": "^6.4",
"symfony/http-foundation": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/serializer": "^6.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"ibexa/code-style": "^1.0",
"ibexa/code-style": "~2.0.0",
"ibexa/doctrine-schema": "~5.0.x-dev",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"phpstan/phpstan": "^1.10",
Expand Down
55 changes: 10 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\DependencyInjection\\\\Configuration\\\\Parser\\\\Search\\:\\:addSemanticConfig\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/DependencyInjection/Configuration/Parser/Search.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\DependencyInjection\\\\Configuration\\\\Parser\\\\Search\\:\\:mapConfig\\(\\) has parameter \\$scopeSettings with no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/DependencyInjection/Configuration/Parser/Search.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\DependencyInjection\\\\IbexaSearchExtension\\:\\:load\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaSearchExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\ChoiceLoader\\\\ConfiguredLanguagesChoiceLoader\\:\\:getChoiceList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Form/ChoiceLoader/ConfiguredLanguagesChoiceLoader.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\ChoiceLoader\\\\ContentTypeChoiceLoader\\:\\:getChoiceList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Form/ChoiceLoader/ContentTypeChoiceLoader.php

-
message: "#^Parameter \\#1 \\$array of function usort expects TArray of array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\>, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -180,11 +160,6 @@ parameters:
count: 1
path: src/bundle/Form/DataTransformer/UsersTransformer.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\ContentTypeChoiceType\\:\\:configureOptions\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/ContentTypeChoiceType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\DateIntervalType\\:\\:buildForm\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -200,43 +175,28 @@ parameters:
count: 1
path: src/bundle/Form/Type/SearchType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\SearchType\\:\\:configureOptions\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/SearchType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\SearchUsersType\\:\\:buildForm\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/SearchUsersType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\SearchUsersType\\:\\:configureOptions\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/SearchUsersType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\SectionChoiceType\\:\\:configureOptions\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/SectionChoiceType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\Form\\\\Type\\\\UserType\\:\\:buildForm\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Form/Type/UserType.php

-
message: "#^Method Ibexa\\\\Bundle\\\\Search\\\\IbexaSearchBundle\\:\\:build\\(\\) has no return type specified\\.$#"
message: "#^Method Ibexa\\\\Contracts\\\\Search\\\\Mapper\\\\SearchHitToContentSuggestionMapperInterface\\:\\:map\\(\\) has parameter \\$searchHit with generic class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Search\\\\SearchHit but does not specify its types\\: T$#"
count: 1
path: src/bundle/IbexaSearchBundle.php
path: src/contracts/Mapper/SearchHitToContentSuggestionMapperInterface.php

-
message: "#^Cannot access offset int on iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\>\\.$#"
message: "#^Method Ibexa\\\\Search\\\\Mapper\\\\PagerSearchContentToDataMapper\\:\\:map\\(\\) has parameter \\$pager with generic class Pagerfanta\\\\Pagerfanta but does not specify its types\\: T$#"
count: 1
path: src/lib/Mapper/PagerSearchContentToDataMapper.php

-
message: "#^Method Ibexa\\\\Search\\\\Mapper\\\\PagerSearchContentToDataMapper\\:\\:map\\(\\) has parameter \\$pager with generic class Pagerfanta\\\\Pagerfanta but does not specify its types\\: T$#"
message: "#^PHPDoc tag @var for variable \\$searchHit contains generic class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Search\\\\SearchHit but does not specify its types\\: T$#"
count: 1
path: src/lib/Mapper/PagerSearchContentToDataMapper.php

Expand All @@ -246,7 +206,12 @@ parameters:
path: src/lib/Mapper/PagerSearchContentToDataMapper.php

-
message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Search\\\\SearchHit\\:\\:\\$score \\(float\\) on left side of \\?\\? is not nullable\\.$#"
message: "#^Method Ibexa\\\\Search\\\\Mapper\\\\SearchHitToContentSuggestionMapper\\:\\:map\\(\\) has parameter \\$searchHit with generic class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Search\\\\SearchHit but does not specify its types\\: T$#"
count: 1
path: src/lib/Mapper/SearchHitToContentSuggestionMapper.php

-
message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Search\\\\SearchHit\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ValueObject\\>\\:\\:\\$score \\(float\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: src/lib/Mapper/SearchHitToContentSuggestionMapper.php

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

class Search extends AbstractParser
{
/**
* Adds semantic configuration definition.
*
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
public function addSemanticConfig(NodeBuilder $nodeBuilder): void
{
$nodeBuilder
->arrayNode('search')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

class SearchView extends View
{
public const NODE_KEY = 'search_view';
public const INFO = 'Template for displaying main search form and results';
public const string NODE_KEY = 'search_view';
public const string INFO = 'Template for displaying main search form and results';
}
10 changes: 4 additions & 6 deletions src/bundle/DependencyInjection/IbexaSearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@

class IbexaSearchExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container)
/**
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}

/**
* Allow an extension to prepend the extension configurations.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container): void
{
$this->prependJMSTranslation($container);
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prependJMSTranslation(ContainerBuilder $container): void
{
$container->prependExtensionConfig('jms_translation', [
Expand Down
30 changes: 8 additions & 22 deletions src/bundle/Form/ChoiceLoader/ConfiguredLanguagesChoiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,37 @@
use Ibexa\Contracts\Core\Repository\LanguageService;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

class ConfiguredLanguagesChoiceLoader implements ChoiceLoaderInterface
{
/** @var \Ibexa\Contracts\Core\Repository\LanguageService */
private $languageService;
private LanguageService $languageService;

/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;
private ConfigResolverInterface $configResolver;

/**
* @param \Ibexa\Contracts\Core\Repository\LanguageService $languageService
* @param \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface $configResolver
*/
public function __construct(LanguageService $languageService, ConfigResolverInterface $configResolver)
{
$this->languageService = $languageService;
$this->configResolver = $configResolver;
}

/**
* {@inheritdoc}
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Language[]
*/
public function getChoiceList(): array
{
return $this->getPriorityOrderedLanguages();
}

/**
* {@inheritdoc}
*/
public function loadChoiceList(callable $value = null)
public function loadChoiceList(callable $value = null): ChoiceListInterface
{
$choices = $this->getChoiceList();

return new ArrayChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, callable $value = null)
public function loadChoicesForValues(array $values, callable $value = null): array
{
// Optimize
$values = array_filter($values);
Expand All @@ -63,10 +52,7 @@ public function loadChoicesForValues(array $values, callable $value = null)
return $this->loadChoiceList($value)->getChoicesForValues($values);
}

/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, callable $value = null)
public function loadValuesForChoices(array $choices, callable $value = null): array
{
// Optimize
$choices = array_filter($choices);
Expand All @@ -78,7 +64,7 @@ public function loadValuesForChoices(array $choices, callable $value = null)
}

/**
* Sort languages based on siteaccess languages order.
* Sort languages based on SiteAccess languages order.
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Language[]
*/
Expand Down
36 changes: 9 additions & 27 deletions src/bundle/Form/ChoiceLoader/ContentTypeChoiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,19 @@
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

class ContentTypeChoiceLoader implements ChoiceLoaderInterface
{
/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
protected $contentTypeService;

/** @var \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface */
private $userLanguagePreferenceProvider;

/**
* @param \Ibexa\Contracts\Core\Repository\ContentTypeService $contentTypeService
* @param \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider
*/
public function __construct(ContentTypeService $contentTypeService, UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider)
{
$this->contentTypeService = $contentTypeService;
$this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider;
public function __construct(
protected ContentTypeService $contentTypeService,
private readonly UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider
) {
}

/**
* {@inheritdoc}
* @return array<string, iterable<\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType>>
*/
public function getChoiceList(): array
{
Expand All @@ -52,20 +43,14 @@ public function getChoiceList(): array
return $contentTypesList;
}

/**
* {@inheritdoc}
*/
public function loadChoiceList(callable $value = null)
public function loadChoiceList(callable $value = null): ChoiceListInterface
{
$choices = $this->getChoiceList();

return new ArrayChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, callable $value = null)
public function loadChoicesForValues(array $values, callable $value = null): array
{
// Optimize
$values = array_filter($values);
Expand All @@ -76,10 +61,7 @@ public function loadChoicesForValues(array $values, callable $value = null)
return $this->loadChoiceList($value)->getChoicesForValues($values);
}

/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, callable $value = null)
public function loadValuesForChoices(array $choices, callable $value = null): array
{
// Optimize
$choices = array_filter($choices);
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/IbexaSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Search;

Expand All @@ -15,7 +16,7 @@

class IbexaSearchBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
/** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $core */
$core = $container->getExtension('ibexa');
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Twig/Extension/SearchFacetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getFilters(): array
return [
new TwigFilter(
'ibexa_choices_as_facets',
[$this, 'getChoicesAsFacets']
$this->getChoicesAsFacets(...)
),
];
}
Expand All @@ -46,7 +46,7 @@ public function getChoicesAsFacets(

if ($comparator === null) {
$comparator = static function (ChoiceView $choice, TermAggregationResultEntry $term): bool {
return $choice->data == $term->getKey();
return $choice->data === $term->getKey();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function testOnContentSuggestionWithException(): void
$event = new BuildSuggestionCollectionEvent($query);

$this->loggerMock
->expects($this->once())
->expects(self::once())
->method('error');

$subscriber->onBuildSuggestionCollectionEvent($event);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/QueryType/SearchQueryTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGetQuery(
->method('supports')
->willReturnMap($returnMap);

$this->assertEquals($expectedQuery, $this->queryType->getQuery($parameters));
self::assertEquals($expectedQuery, $this->queryType->getQuery($parameters));
}

/**
Expand Down
Loading

0 comments on commit 0089459

Please sign in to comment.