Skip to content

Commit

Permalink
[CI] Added phpstan (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou authored Dec 19, 2024
1 parent b5d0b32 commit 02d2e58
Show file tree
Hide file tree
Showing 34 changed files with 290 additions and 155 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ jobs:

- name: Run unit test suite
run: composer test

- name: Run PHPStan analysis
run: composer run-script phpstan
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,30 @@
"ibexa/doctrine-schema": "~4.6.0@dev",
"ibexa/design-engine": "~4.6.0@dev",
"ibexa/fieldtype-richtext": "~4.6.0@dev",
"ibexa/phpstan": "~4.6.0@dev",
"ibexa/search": "~4.6.0@dev",
"ibexa/user": "~4.6.0@dev",
"ibexa/http-cache": "~4.6.0@dev",
"phpspec/phpspec": "^7.1",
"ibexa/code-style": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0"
"friendsofphp/php-cs-fixer": "^3.0",
"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": "4.6.x-dev"
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": 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
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
6 changes: 2 additions & 4 deletions spec/QueryFieldServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* @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;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Query as ApiContentQuery;
Expand Down Expand Up @@ -38,7 +38,6 @@ class QueryFieldServiceSpec extends ObjectBehavior
public function let(
SearchService $searchService,
ContentTypeService $contentTypeService,
LocationService $locationService,
QueryTypeRegistry $queryTypeRegistry,
QueryType $queryType
) {
Expand All @@ -60,12 +59,11 @@ public function let(
$contentTypeWithoutPagination = $this->getContentType($parameters, false, 10);
$contentTypeService->loadContentType(self::CONTENT_TYPE_ID_WITHOUT_PAGINATION)->willReturn($contentTypeWithoutPagination);

$locationService->loadLocation(self::LOCATION_ID)->willReturn($location);
$queryTypeRegistry->getQueryType(self::QUERY_TYPE_IDENTIFIER)->willReturn($queryType);
$queryType->getQuery(Argument::any())->willReturn(new ApiQuery());
// @todo this should fail. It does not.
$searchService->findContent(Argument::any())->willReturn($this->searchResult);
$this->beConstructedWith($searchService, $contentTypeService, $locationService, $queryTypeRegistry);
$this->beConstructedWith($searchService, $contentTypeService, $queryTypeRegistry);
}

public function it_is_initializable()
Expand Down
18 changes: 12 additions & 6 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 All @@ -15,6 +16,7 @@
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Contracts\Rest\Exceptions\NotFoundException;
use Ibexa\FieldTypeQuery\QueryFieldService;
use function Ibexa\PolyfillPhp82\iterator_to_array;
use Ibexa\Rest\RequestParser;
use Ibexa\Rest\Server\Values as RestValues;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -50,10 +52,14 @@ public function __construct(
$this->requestParser = $requestParser;
}

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 +95,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()))
);
},
$items
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
Loading

0 comments on commit 02d2e58

Please sign in to comment.