Skip to content

Commit 0d56ab0

Browse files
committed
IBX-8470: Fixed phpstan issues after upgrade
1 parent 1db8298 commit 0d56ab0

File tree

6 files changed

+65
-142
lines changed

6 files changed

+65
-142
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,6 @@ parameters:
1010
count: 1
1111
path: src/bundle/Command/GeneratePlatformSchemaCommand.php
1212

13-
-
14-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\Command\\\\GeneratePlatformSchemaCommand\\:\\:configure\\(\\) has no return type specified\\.$#"
15-
count: 1
16-
path: src/bundle/Command/GeneratePlatformSchemaCommand.php
17-
18-
-
19-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\Compiler\\\\FieldInputHandlersPass\\:\\:process\\(\\) has no return type specified\\.$#"
20-
count: 1
21-
path: src/bundle/DependencyInjection/Compiler/FieldInputHandlersPass.php
22-
23-
-
24-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\Compiler\\\\RichTextInputConvertersPass\\:\\:process\\(\\) has no return type specified\\.$#"
25-
count: 1
26-
path: src/bundle/DependencyInjection/Compiler/RichTextInputConvertersPass.php
27-
28-
-
29-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\Compiler\\\\SchemaDomainIteratorsPass\\:\\:process\\(\\) has no return type specified\\.$#"
30-
count: 1
31-
path: src/bundle/DependencyInjection/Compiler/SchemaDomainIteratorsPass.php
32-
33-
-
34-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\Compiler\\\\SchemaWorkersPass\\:\\:process\\(\\) has no return type specified\\.$#"
35-
count: 1
36-
path: src/bundle/DependencyInjection/Compiler/SchemaWorkersPass.php
37-
3813
-
3914
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\GraphQL\\\\SchemaProvider\\:\\:getSchemaConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
4015
count: 1
@@ -100,11 +75,6 @@ parameters:
10075
count: 1
10176
path: src/bundle/DependencyInjection/IbexaGraphQLExtension.php
10277

103-
-
104-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\IbexaGraphQLExtension\\:\\:prepend\\(\\) has no return type specified\\.$#"
105-
count: 1
106-
path: src/bundle/DependencyInjection/IbexaGraphQLExtension.php
107-
10878
-
10979
message: "#^Parameter \\#1 \\$configDir of method Ibexa\\\\Bundle\\\\GraphQL\\\\DependencyInjection\\\\IbexaGraphQLExtension\\:\\:getGraphQLConfig\\(\\) expects string, array\\|bool\\|float\\|int\\|string\\|null given\\.$#"
11080
count: 1
@@ -115,11 +85,6 @@ parameters:
11585
count: 1
11686
path: src/bundle/DependencyInjection/IbexaGraphQLExtension.php
11787

118-
-
119-
message: "#^Method Ibexa\\\\Bundle\\\\GraphQL\\\\IbexaGraphQLBundle\\:\\:build\\(\\) has no return type specified\\.$#"
120-
count: 1
121-
path: src/bundle/IbexaGraphQLBundle.php
122-
12388
-
12489
message: "#^Method Ibexa\\\\Contracts\\\\GraphQL\\\\Mutation\\\\InputHandler\\\\FieldType\\\\RichText\\\\RichTextInputConverter\\:\\:convertToXml\\(\\) has parameter \\$text with no type specified\\.$#"
12590
count: 1
@@ -540,56 +505,11 @@ parameters:
540505
count: 1
541506
path: src/lib/Relay/NodeResolver.php
542507

543-
-
544-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$edges\\.$#"
545-
count: 1
546-
path: src/lib/Relay/PageAwareConnection.php
547-
548-
-
549-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$pageInfo\\.$#"
550-
count: 1
551-
path: src/lib/Relay/PageAwareConnection.php
552-
553-
-
554-
message: "#^Access to protected property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\:\\:\\$totalCount\\.$#"
555-
count: 1
556-
path: src/lib/Relay/PageAwareConnection.php
557-
558-
-
559-
message: "#^Method Ibexa\\\\GraphQL\\\\Relay\\\\PageAwareConnection\\:\\:__construct\\(\\) has parameter \\$edges with no value type specified in iterable type array\\.$#"
560-
count: 1
561-
path: src/lib/Relay/PageAwareConnection.php
562-
563-
-
564-
message: "#^Parameter \\#2 \\$pageInfo of class Ibexa\\\\GraphQL\\\\Relay\\\\PageAwareConnection constructor expects Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface, Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\PageInfoInterface\\|null given\\.$#"
565-
count: 1
566-
path: src/lib/Relay/PageAwareConnection.php
567-
568-
-
569-
message: "#^Property Ibexa\\\\GraphQL\\\\Relay\\\\PageAwareConnection\\:\\:\\$totalCount \\(int\\) does not accept GraphQL\\\\Executor\\\\Promise\\\\Promise\\|int\\|null\\.$#"
570-
count: 1
571-
path: src/lib/Relay/PageAwareConnection.php
572-
573-
-
574-
message: "#^Access to an undefined property Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\ConnectionInterface\\:\\:\\$sliceSize\\.$#"
575-
count: 1
576-
path: src/lib/Relay/SearchResolver.php
577-
578508
-
579509
message: "#^Method Ibexa\\\\GraphQL\\\\Relay\\\\SearchResolver\\:\\:searchContent\\(\\) has parameter \\$args with no type specified\\.$#"
580510
count: 1
581511
path: src/lib/Relay/SearchResolver.php
582512

583-
-
584-
message: "#^Method Ibexa\\\\GraphQL\\\\Relay\\\\SearchResolver\\:\\:searchContent\\(\\) should return Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection but returns Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\ConnectionInterface\\.$#"
585-
count: 1
586-
path: src/lib/Relay/SearchResolver.php
587-
588-
-
589-
message: "#^Method Ibexa\\\\GraphQL\\\\Relay\\\\SearchResolver\\:\\:searchContent\\(\\) should return Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection but returns null\\.$#"
590-
count: 1
591-
path: src/lib/Relay/SearchResolver.php
592-
593513
-
594514
message: "#^Method Ibexa\\\\GraphQL\\\\Resolver\\\\ContentResolver\\:\\:findContentByType\\(\\) has no return type specified\\.$#"
595515
count: 1
@@ -980,16 +900,6 @@ parameters:
980900
count: 1
981901
path: src/lib/Resolver/ItemResolver.php
982902

983-
-
984-
message: "#^Method Ibexa\\\\GraphQL\\\\Resolver\\\\ItemResolver\\:\\:resolveItemsOfTypeAsConnection\\(\\) should return Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection but returns GraphQL\\\\Executor\\\\Promise\\\\Promise\\|Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection\\.$#"
985-
count: 1
986-
path: src/lib/Resolver/ItemResolver.php
987-
988-
-
989-
message: "#^Property Ibexa\\\\GraphQL\\\\Resolver\\\\ItemResolver\\:\\:\\$contentTypeLoader is never read, only written\\.$#"
990-
count: 1
991-
path: src/lib/Resolver/ItemResolver.php
992-
993903
-
994904
message: "#^Parameter \\#1 \\$location of method Ibexa\\\\GraphQL\\\\Resolver\\\\LocationGuesser\\\\ObjectStorageLocationList\\:\\:addLocation\\(\\) expects Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ValueObject given\\.$#"
995905
count: 1
@@ -1065,16 +975,6 @@ parameters:
1065975
count: 1
1066976
path: src/lib/Resolver/LocationResolver.php
1067977

1068-
-
1069-
message: "#^PHPDoc tag @return with type Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection is incompatible with native type Ibexa\\\\GraphQL\\\\Relay\\\\PageAwareConnection\\.$#"
1070-
count: 1
1071-
path: src/lib/Resolver/LocationResolver.php
1072-
1073-
-
1074-
message: "#^Parameter \\#1 \\$connection of static method Ibexa\\\\GraphQL\\\\Relay\\\\PageAwareConnection\\:\\:fromConnection\\(\\) expects Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection, GraphQL\\\\Executor\\\\Promise\\\\Promise\\|Overblog\\\\GraphQLBundle\\\\Relay\\\\Connection\\\\Output\\\\Connection given\\.$#"
1075-
count: 1
1076-
path: src/lib/Resolver/LocationResolver.php
1077-
1078978
-
1079979
message: "#^Method Ibexa\\\\GraphQL\\\\Resolver\\\\ObjectStateGroupResolver\\:\\:resolveObjectStateGroups\\(\\) should return array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ObjectState\\\\ObjectStateGroup\\> but returns iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ObjectState\\\\ObjectStateGroup\\>\\.$#"
1080980
count: 1

src/lib/Relay/DomainConnectionBuilder.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/lib/Relay/PageAwareConnection.php

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,62 @@
77

88
namespace Ibexa\GraphQL\Relay;
99

10+
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
11+
use GraphQL\Executor\Promise\Promise;
1012
use Overblog\GraphQLBundle\Definition\Argument;
1113
use Overblog\GraphQLBundle\Relay\Connection\ConnectionBuilder;
14+
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
15+
use Overblog\GraphQLBundle\Relay\Connection\EdgeInterface;
1216
use Overblog\GraphQLBundle\Relay\Connection\Output\Connection;
1317
use Overblog\GraphQLBundle\Relay\Connection\PageInfoInterface;
1418

19+
/**
20+
* @phpstan-template T
21+
*/
1522
final class PageAwareConnection
1623
{
17-
/** @var \Overblog\GraphQLBundle\Relay\Connection\Output\Edge[] */
18-
public $edges = [];
24+
/** @var iterable<\Overblog\GraphQLBundle\Relay\Connection\EdgeInterface<T>> */
25+
public iterable $edges = [];
1926

20-
/** @var \Overblog\GraphQLBundle\Relay\Connection\PageInfoInterface */
21-
public $pageInfo;
27+
public PageInfoInterface $pageInfo;
2228

2329
/** @var int */
24-
public $totalCount;
30+
public int $totalCount;
2531

2632
/** @var Page[] */
27-
public $pages;
33+
public array $pages;
2834

29-
public function __construct(array $edges, PageInfoInterface $pageInfo)
35+
/**
36+
* @param iterable<\Overblog\GraphQLBundle\Relay\Connection\EdgeInterface<T>> $edges
37+
*/
38+
public function __construct(iterable $edges, PageInfoInterface $pageInfo)
3039
{
3140
$this->edges = $edges;
3241
$this->pageInfo = $pageInfo;
3342
}
3443

35-
public static function fromConnection(Connection $connection, Argument $args): PageAwareConnection
44+
/**
45+
* @param \GraphQL\Executor\Promise\Promise|\Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface<T> $connection
46+
*
47+
* @return \Ibexa\GraphQL\Relay\PageAwareConnection<T>
48+
*/
49+
public static function fromConnection(ConnectionInterface|Promise $connection, Argument $args): PageAwareConnection
3650
{
37-
$return = new self($connection->edges, $connection->pageInfo);
38-
$return->totalCount = $connection->totalCount;
51+
$connection = self::resolvePromise(
52+
$connection,
53+
fn($resolved) => $resolved instanceof ConnectionInterface,
54+
'Resolved result is not a ConnectionInterface'
55+
);
56+
57+
$return = new self($connection->getEdges(), $connection->getPageInfo());
58+
59+
$totalCount = self::resolvePromise(
60+
$connection->getTotalCount(),
61+
fn($resolved) => is_int($resolved) || is_null($resolved),
62+
'Resolved result is not an int or null'
63+
);
64+
65+
$return->totalCount = (int)$totalCount;
3966

4067
$return->pages = [];
4168

@@ -49,4 +76,18 @@ public static function fromConnection(Connection $connection, Argument $args): P
4976

5077
return $return;
5178
}
79+
80+
private static function resolvePromise(mixed $value, callable $validator, string $errorMessage): mixed
81+
{
82+
if ($value instanceof Promise) {
83+
$promiseAdapter = new SyncPromiseAdapter();
84+
$resolvedValue = $promiseAdapter->wait($value);
85+
86+
if (!$validator($resolvedValue)) {
87+
throw new \UnexpectedValueException($errorMessage);
88+
}
89+
return $resolvedValue;
90+
}
91+
return $value;
92+
}
5293
}

src/lib/Relay/SearchResolver.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1212
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit;
1313
use Overblog\GraphQLBundle\Relay\Connection\ConnectionBuilder;
14+
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
1415

1516
class SearchResolver
1617
{
@@ -27,11 +28,11 @@ public function __construct(SearchService $searchService)
2728
/**
2829
* @param $args
2930
*
30-
* @return \Overblog\GraphQLBundle\Relay\Connection\Output\Connection
31+
* @return \Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface<\Ibexa\Contracts\Core\Repository\Values\ValueObject>
3132
*
3233
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
3334
*/
34-
public function searchContent($args)
35+
public function searchContent($args): ConnectionInterface
3536
{
3637
$queryArg = $args['query'];
3738

@@ -48,10 +49,9 @@ public function searchContent($args)
4849
}
4950
}
5051

51-
if (count($criteria) === 0) {
52-
return null;
52+
if (count($criteria) !== 0) {
53+
$query->filter = count($criteria) > 1 ? new Query\Criterion\LogicalAnd($criteria) : $criteria[0];
5354
}
54-
$query->filter = count($criteria) > 1 ? new Query\Criterion\LogicalAnd($criteria) : $criteria[0];
5555
$searchResult = $this->searchService->findContentInfo($query);
5656

5757
$contentItems = array_map(
@@ -62,16 +62,14 @@ static function (SearchHit $hit) {
6262
);
6363

6464
$connectionBuilder = new ConnectionBuilder();
65-
$connection = $connectionBuilder->connectionFromArraySlice(
65+
66+
return $connectionBuilder->connectionFromArraySlice(
6667
$contentItems,
6768
$args,
6869
[
6970
'sliceStart' => 0,
7071
'arrayLength' => $searchResult->totalCount,
7172
]
7273
);
73-
$connection->sliceSize = count($contentItems);
74-
75-
return $connection;
7674
}
7775
}

src/lib/Resolver/ItemResolver.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Ibexa\GraphQL\Resolver;
99

1010
use GraphQL\Error\UserError;
11+
use GraphQL\Executor\Promise\Promise;
1112
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1314
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
@@ -37,9 +38,6 @@ final class ItemResolver
3738
/** @var \Ibexa\GraphQL\DataLoader\ContentLoader */
3839
private $contentLoader;
3940

40-
/** @var \Ibexa\GraphQL\DataLoader\ContentTypeLoader */
41-
private $contentTypeLoader;
42-
4341
/** @var \Ibexa\GraphQL\DataLoader\LocationLoader */
4442
private $locationLoader;
4543

@@ -50,14 +48,12 @@ public function __construct(
5048
TypeResolver $typeResolver,
5149
QueryMapper $queryMapper,
5250
ContentLoader $contentLoader,
53-
ContentTypeLoader $contentTypeLoader,
5451
LocationLoader $locationLoader,
5552
ItemFactory $currentSiteItemFactory
5653
) {
5754
$this->typeResolver = $typeResolver;
5855
$this->queryMapper = $queryMapper;
5956
$this->contentLoader = $contentLoader;
60-
$this->contentTypeLoader = $contentTypeLoader;
6157
$this->locationLoader = $locationLoader;
6258
$this->itemFactory = $currentSiteItemFactory;
6359
}
@@ -99,7 +95,7 @@ public function resolveItem($args): Item
9995
);
10096
} elseif (isset($args['contentId'])) {
10197
$item = $this->itemFactory->fromContent(
102-
$content = $this->contentLoader->findSingle(new Query\Criterion\ContentId($args['contentId']))
98+
$this->contentLoader->findSingle(new Query\Criterion\ContentId($args['contentId']))
10399
);
104100
} elseif (isset($args['remoteId'])) {
105101
$item = $this->itemFactory->fromContent(
@@ -129,7 +125,10 @@ public function resolveItemFieldValue(Item $item, $fieldDefinitionIdentifier, $a
129125
return Field::fromField($item->getContent()->getField($fieldDefinitionIdentifier, $args['language'] ?? null));
130126
}
131127

132-
public function resolveItemsOfTypeAsConnection(string $contentTypeIdentifier, $args): Connection
128+
/**
129+
* @return \GraphQL\Executor\Promise\Promise|\Overblog\GraphQLBundle\Relay\Connection\Output\Connection<\Ibexa\GraphQL\Value\Item>
130+
*/
131+
public function resolveItemsOfTypeAsConnection(string $contentTypeIdentifier, $args): Connection|Promise
133132
{
134133
$query = $args['query'] ?: [];
135134
$query['ContentTypeIdentifier'] = $contentTypeIdentifier;

src/lib/Resolver/LocationResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function resolveLocationById($locationId)
8686
/**
8787
* @param int $locationId
8888
*
89-
* @return \Overblog\GraphQLBundle\Relay\Connection\Output\Connection
89+
* @return \Ibexa\GraphQL\Relay\PageAwareConnection<\Ibexa\Contracts\Core\Repository\Values\Content\Location>
9090
*/
9191
public function resolveLocationChildren($locationId, Argument $args): PageAwareConnection
9292
{

0 commit comments

Comments
 (0)