Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.6'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	src/bundle/Controller/QueryFieldRestController.php
#	src/lib/Persistence/Legacy/Content/FieldValue/Converter/QueryConverter.php
#	src/lib/QueryFieldPaginationService.php
  • Loading branch information
ViniTou committed Dec 19, 2024
2 parents 87c5596 + 02d2e58 commit ba53431
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 138 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ jobs:

- name: Run unit test suite
run: composer test

- name: Run PHPStan analysis
run: composer run-script phpstan
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,27 @@
"ibexa/fieldtype-richtext": "~5.0.x-dev",
"ibexa/http-cache": "~5.0.x-dev",
"ibexa/notifications": "~5.0.x-dev",
"ibexa/phpstan": "~5.0.0@dev",
"ibexa/search": "~5.0.x-dev",
"ibexa/user": "~5.0.x-dev",
"phpspec/phpspec": "^7.1"
"phpspec/phpspec": "^7.1",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-symfony": "^2.0"
},
"scripts": {
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"test": "phpspec run --format=pretty"
"test": "phpspec run --format=pretty",
"phpstan": "phpstan analyse"
},
"extra": {
"branch-alias": {
"dev-main": "5.0.x-dev"
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"php-http/discovery": false
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": false
}
}
139 changes: 139 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
parameters:
ignoreErrors:
-
message: '#^Parameter \#1 \$href of method Ibexa\\Rest\\RequestParser\:\:parseHref\(\) expects string, string\|null given\.$#'
identifier: argument.type
count: 1
path: src/bundle/Controller/QueryFieldRestController.php

-
message: '#^Parameter \#1 \$locationId of method Ibexa\\Contracts\\Core\\Repository\\LocationService\:\:loadLocation\(\) expects int, int\|null given\.$#'
identifier: argument.type
count: 1
path: src/bundle/Controller/QueryFieldRestController.php

-
message: '#^Argument of an invalid type array\|bool\|float\|int\|string\|null supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php

-
message: '#^Cannot access offset \(int\|string\) on non\-empty\-array\|bool\|float\|int\|string\|null\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php

-
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(int\|string\)\: bool\)\|null, Closure\(mixed\)\: \(0\|1\|false\) given\.$#'
identifier: argument.type
count: 1
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php

-
message: '#^Parameter \#1 \$queryTypeIdentifier of method Ibexa\\Bundle\\FieldTypeQuery\\DependencyInjection\\Compiler\\QueryTypesListPass\:\:buildQueryTypeName\(\) expects string, int\|string given\.$#'
identifier: argument.type
count: 1
path: src/bundle/DependencyInjection/Compiler/QueryTypesListPass.php

-
message: '#^Parameter \#1 \$input of static method Symfony\\Component\\Yaml\\Yaml\:\:parse\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeQueryExtension.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:__construct\(\) has parameter \$views with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/ContentView/QueryResultsInjector.php

-
message: '#^Property Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:\$queryFieldService \(Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldLocationService&Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\) does not accept Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\.$#'
identifier: assign.propertyType
count: 1
path: src/lib/ContentView/QueryResultsInjector.php

-
message: '#^Property Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:\$views type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/ContentView/QueryResultsInjector.php

-
message: '#^Property Ibexa\\FieldTypeQuery\\ExceptionSafeQueryFieldService\:\:\$inner \(Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldLocationService&Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\) does not accept Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\.$#'
identifier: assign.propertyType
count: 1
path: src/lib/ExceptionSafeQueryFieldService.php

-
message: '#^Class Ibexa\\FieldTypeQuery\\FieldType\\Form\\QueryFieldFormType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/FieldType/Form/QueryFieldFormType.php

-
message: '#^Generator expects key type string, string\|null given\.$#'
identifier: generator.keyType
count: 1
path: src/lib/FieldType/Mapper/QueryFormMapper.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\FieldType\\Mapper\\QueryFormMapper\:\:mapFieldDefinitionForm\(\) has parameter \$fieldDefinitionForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/FieldType/Mapper/QueryFormMapper.php

-
message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\StorageFieldValue\:\:\$dataText \(string\) does not accept array\|bool\|float\|int\|string\|null\.$#'
identifier: assign.propertyType
count: 1
path: src/lib/Persistence/Legacy/Content/FieldValue/Converter/QueryConverter.php

-
message: '#^Anonymous function should return Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Content but returns Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\.$#'
identifier: return.type
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:isExpression\(\) has parameter \$expression with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:prepareQuery\(\) has parameter \$extraParameters with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveExpression\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveExpression\(\) has parameter \$variables with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) has parameter \$expressions with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) has parameter \$variables with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/QueryFieldService.php

-
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/QueryFieldService.php
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/ibexa/phpstan/extension.neon

parameters:
ignoreErrors:
-
message: "#^Cannot call method (log|debug|info|notice|warning|error|critical|alert|emergency)\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
level: 8
paths:
- src
treatPhpDocTypesAsCertain: false
17 changes: 11 additions & 6 deletions src/bundle/Controller/QueryFieldRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Ibexa\Contracts\Rest\Exceptions\NotFoundException;
use Ibexa\Contracts\Rest\UriParser\UriParserInterface;
use Ibexa\FieldTypeQuery\QueryFieldService;
use function Ibexa\PolyfillPhp82\iterator_to_array;
use Ibexa\Rest\Server\Values as RestValues;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -50,10 +51,14 @@ public function __construct(
$this->uriParser = $uriParser;
}

public function getResults(Request $request, $contentId, $versionNumber, $fieldDefinitionIdentifier): RestValues\ContentList
{
$offset = (int)$request->query->get('offset', 0);
$limit = (int)$request->query->get('limit', -1);
public function getResults(
Request $request,
int $contentId,
int $versionNumber,
string $fieldDefinitionIdentifier
): RestValues\ContentList {
$offset = (int)$request->query->get('offset', '0');
$limit = (int)$request->query->get('limit', '-1');

if ($request->query->has('location')) {
$location = $this->loadLocationByPath($request);
Expand Down Expand Up @@ -89,10 +94,10 @@ function (Content $content) {
$this->locationService->loadLocation($content->contentInfo->mainLocationId),
$content,
$this->getContentType($content->contentInfo),
$this->contentService->loadRelations($content->getVersionInfo())
iterator_to_array($this->contentService->loadRelations($content->getVersionInfo()))

Check failure on line 97 in src/bundle/Controller/QueryFieldRestController.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.3)

Call to an undefined method Ibexa\Contracts\Core\Repository\ContentService::loadRelations().

Check failure on line 97 in src/bundle/Controller/QueryFieldRestController.php

View workflow job for this annotation

GitHub Actions / Unit tests (8.3)

Unable to resolve the template type T in call to function Ibexa\PolyfillPhp82\iterator_to_array
);
},
$items
iterator_to_array($items)
),
$this->queryFieldService->countContentItems($content, $fieldDefinitionIdentifier)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ class ConfigurableFieldDefinitionMapperPass implements CompilerPassInterface
{
public const PARAMETER = 'ibexa.graphql.schema.content.mapping.field_definition_type';

public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasParameter(self::PARAMETER)) {
return;
}

$parameter = $container->getParameter(self::PARAMETER);
if (!is_array($parameter)) {
return;
}
$parameter['ezcontentquery'] = [
'definition_type' => 'QueryFieldDefinition',
'value_resolver' => 'resolver("QueryFieldValue", [field, content])',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FieldDefinitionIdentifierViewMatcherPass implements CompilerPassInterface
private const LONG_IDENTIFIER = '@' . FieldDefinitionIdentifierMatcher::class;
private const SHORT_IDENTIFIER = 'Identifier\FieldDefinition';

public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$configKeys = array_filter(
array_keys($container->getParameterBag()->all()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct()
$this->nameConverter = new CamelCaseToSnakeCaseNameConverter();
}

public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->has(ArrayQueryTypeRegistry::class) || !$container->has(QueryFormMapper::class)) {
return;
Expand All @@ -48,12 +48,8 @@ public function process(ContainerBuilder $container)

/**
* Builds a human readable name out of a query type identifier.
*
* @param $queryTypeIdentifier
*
* @return string
*/
private function buildQueryTypeName($queryTypeIdentifier)
private function buildQueryTypeName(string $queryTypeIdentifier): string
{
return ucfirst(
str_replace('_', ' ', $this->nameConverter->normalize($queryTypeIdentifier))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class IbexaFieldTypeQueryExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
Expand All @@ -33,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->addContentViewConfig($container);
}

public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
$this->prependFieldTemplateConfig($container);
$this->prependJMSTranslationConfig($container);
Expand All @@ -47,6 +47,9 @@ public function prepend(ContainerBuilder $container)
protected function addContentViewConfig(ContainerBuilder $container): void
{
$contentViewDefaults = $container->getParameter('ibexa.site_access.config.default.content_view_defaults');
if (!is_array($contentViewDefaults)) {
return;
}
$contentViewDefaults['content_query_field'] = [
'default' => [
'template' => '@IbexaFieldTypeQuery/content/contentquery.html.twig',
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/IbexaFieldTypeQueryBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final class IbexaFieldTypeQueryBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new Compiler\QueryTypesListPass());
$container->addCompilerPass(new Compiler\ConfigurableFieldDefinitionMapperPass());
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/QueryFieldLocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ interface QueryFieldLocationService
/**
* Returns the query results for the given location.
*
* @return iterable An iterable that yields Content items.
* @return iterable<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
*/
public function loadContentItemsForLocation(Location $location, string $fieldDefinitionIdentifier): iterable;

/**
* Returns a slice of the query results for the given location.
*
* @return iterable An iterable that yields Content items.
* @return iterable<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
*/
public function loadContentItemsSliceForLocation(Location $location, string $fieldDefinitionIdentifier, int $offset, int $limit): iterable;

Expand Down
16 changes: 0 additions & 16 deletions src/contracts/QueryFieldServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ interface QueryFieldServiceInterface
/**
* Executes the query without pagination and returns the content items.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $content
* @param string $fieldDefinitionIdentifier
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Content[]
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
Expand All @@ -29,33 +26,20 @@ public function loadContentItems(Content $content, string $fieldDefinitionIdenti
/**
* Counts the total results of a query.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content
* @param string $fieldDefinitionIdentifier
*
* @return int
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function countContentItems(Content $content, string $fieldDefinitionIdentifier): int;

/**
* Executes a paginated query and return the requested content items slice.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content
* @param string $fieldDefinitionIdentifier
* @param int $offset
* @param int $limit
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Content[]
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function loadContentItemsSlice(Content $content, string $fieldDefinitionIdentifier, int $offset, int $limit): iterable;

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content
* @param string $fieldDefinitionIdentifier
*
* @return int The page size, or 0 if pagination is disabled.
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
Expand Down
Loading

0 comments on commit ba53431

Please sign in to comment.