Skip to content

Commit

Permalink
Fixed phpstan issues & added rest to baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Dec 18, 2024
1 parent a391bf1 commit f3e322f
Show file tree
Hide file tree
Showing 31 changed files with 123 additions and 146 deletions.
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ includes:
- vendor/phpstan/phpstan-symfony/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
- tests
treatPhpDocTypesAsCertain: false
1 change: 1 addition & 0 deletions spec/ContentView/FieldDefinitionIdentifierMatcherSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\Core\Repository\ContentTypeService;
Expand Down
1 change: 1 addition & 0 deletions spec/ContentView/QueryResultsInjectorSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\FieldTypeQuery\QueryFieldServiceInterface;
Expand Down
1 change: 1 addition & 0 deletions spec/ExceptionSafeQueryFieldServiceSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery;

use Ibexa\Contracts\FieldTypeQuery\QueryFieldServiceInterface;
Expand Down
1 change: 1 addition & 0 deletions spec/GraphQL/ContentQueryFieldDefinitionMapperSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery\GraphQL;

use Ibexa\Contracts\Core\Repository\ContentTypeService;
Expand Down
1 change: 1 addition & 0 deletions spec/GraphQL/QueryFieldResolverSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery\GraphQL;

use Ibexa\Contracts\FieldTypeQuery\QueryFieldServiceInterface;
Expand Down
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.
*/

namespace spec\Ibexa\FieldTypeQuery\Persistence\Legacy\Content\FieldValue\Converter;

use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
Expand Down
1 change: 1 addition & 0 deletions spec/QueryFieldServiceSpec.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.
*/

namespace spec\Ibexa\FieldTypeQuery;

use Ibexa\Contracts\Core\Repository\ContentTypeService;
Expand Down
12 changes: 7 additions & 5 deletions src/bundle/Controller/QueryFieldRestController.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.
*/

namespace Ibexa\Bundle\FieldTypeQuery\Controller;

use Ibexa\Contracts\Core\Repository\ContentService;
Expand Down Expand Up @@ -48,12 +49,13 @@ public function __construct(
$this->contentTypeService = $contentTypeService;
$this->locationService = $locationService;
$this->requestParser = $requestParser;

}

public function getResults(Request $request, $contentId, $versionNumber, $fieldDefinitionIdentifier): RestValues\ContentList
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);
$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 +91,10 @@ function (Content $content) {
$this->locationService->loadLocation($content->contentInfo->mainLocationId),
$content,
$this->getContentType($content->contentInfo),
$this->contentService->loadRelations($content->getVersionInfo())
\Ibexa\PolyfillPhp82\iterator_to_array($this->contentService->loadRelations($content->getVersionInfo()))
);
},
$items
\Ibexa\PolyfillPhp82\iterator_to_array($items)
),
$this->queryFieldService->countContentItems($content, $fieldDefinitionIdentifier)
);
Expand Down
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.
*/

namespace Ibexa\Bundle\FieldTypeQuery\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand All @@ -17,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 @@ -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.
*/

namespace Ibexa\Bundle\FieldTypeQuery\DependencyInjection\Compiler;

use Ibexa\FieldTypeQuery\ContentView\FieldDefinitionIdentifierMatcher;
Expand All @@ -18,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 @@ -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.
*/

namespace Ibexa\Bundle\FieldTypeQuery\DependencyInjection\Compiler;

use Ibexa\Core\QueryType\ArrayQueryTypeRegistry;
Expand All @@ -24,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 @@ -47,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 @@ -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.
*/

namespace Ibexa\Bundle\FieldTypeQuery\DependencyInjection;

use Symfony\Component\Config\FileLocator;
Expand All @@ -16,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 @@ -32,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 @@ -46,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
3 changes: 2 additions & 1 deletion src/bundle/IbexaFieldTypeQueryBundle.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.
*/

namespace Ibexa\Bundle\FieldTypeQuery;

use Ibexa\Bundle\FieldTypeQuery\DependencyInjection\Compiler;
Expand All @@ -12,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
5 changes: 3 additions & 2 deletions src/contracts/QueryFieldLocationService.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.
*/

namespace Ibexa\Contracts\FieldTypeQuery;

use Ibexa\Contracts\Core\Repository\Values\Content\Location;
Expand All @@ -16,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
17 changes: 1 addition & 16 deletions src/contracts/QueryFieldServiceInterface.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.
*/

namespace Ibexa\Contracts\FieldTypeQuery;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;
Expand All @@ -16,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 @@ -28,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
1 change: 1 addition & 0 deletions src/lib/ContentView/FieldDefinitionIdentifierMatcher.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.
*/

namespace Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
Expand Down
14 changes: 9 additions & 5 deletions src/lib/ContentView/QueryResultsInjector.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.
*/

namespace Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\FieldTypeQuery\QueryFieldLocationService;
Expand All @@ -19,7 +20,7 @@

final class QueryResultsInjector implements EventSubscriberInterface
{
/** @var \Ibexa\FieldTypeQuery\QueryFieldService */
/** @var \Ibexa\Contracts\FieldTypeQuery\QueryFieldServiceInterface&\Ibexa\Contracts\FieldTypeQuery\QueryFieldLocationService */
private $queryFieldService;

/** @var array */
Expand Down Expand Up @@ -47,7 +48,7 @@ public static function getSubscribedEvents()
/**
* {@inheritdoc}
*/
public function injectQueryResults(FilterViewParametersEvent $event)
public function injectQueryResults(FilterViewParametersEvent $event): void
{
if ($event->getView()->getViewType() === $this->views['field']) {
$builderParameters = $event->getBuilderParameters();
Expand All @@ -70,20 +71,23 @@ public function injectQueryResults(FilterViewParametersEvent $event)
/**
* @param \Ibexa\Core\MVC\Symfony\View\Event\FilterViewParametersEvent $event
*
* @return iterable
* @return iterable<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
private function buildResults(FilterViewParametersEvent $event): iterable
{
$view = $event->getView();
$location = $view instanceof LocationValueView ? $location = $view->getLocation() : null;
$location = $view instanceof LocationValueView ? $view->getLocation() : null;
$content = $view instanceof ContentValueView ? $view->getContent() : null;

if ($location === null && $content === null) {
throw new \Exception('No content nor location to get query results for');
}
$viewParameters = $event->getBuilderParameters();
$fieldDefinitionIdentifier = $viewParameters['queryFieldDefinitionIdentifier'];

$paginationLimit = $this->queryFieldService->getPaginationConfiguration($content, $fieldDefinitionIdentifier);
$paginationLimit = $this->queryFieldService->getPaginationConfiguration($content ?? $location->getContent(), $fieldDefinitionIdentifier);
$enablePagination = ($viewParameters['enablePagination'] === true);
$disablePagination = ($viewParameters['disablePagination'] === true);

Expand Down
1 change: 1 addition & 0 deletions src/lib/ContentView/QueryResultsPagerFantaAdapter.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.
*/

namespace Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;
Expand Down
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.
*/

namespace Ibexa\FieldTypeQuery\ContentView;

use Ibexa\Contracts\Core\Repository\Values\Content\Location;
Expand Down
Loading

0 comments on commit f3e322f

Please sign in to comment.