diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e938cf0b..ce3b3fbf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -474,18 +474,6 @@ parameters: count: 1 path: src/lib/Server/Controller/Services.php - - - message: '#^Property Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Query\:\:\$limit \(int\) does not accept int\<0, max\>\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/Server/Controller/Trash/TrashItemListController.php - - - - message: '#^Property Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Query\:\:\$offset \(int\) does not accept int\<0, max\>\|null\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/Server/Controller/Trash/TrashItemListController.php - - message: '#^Method Ibexa\\Rest\\Server\\Input\\Parser\\AbstractDestinationLocationParser\:\:parse\(\) has Ibexa\\Contracts\\Rest\\Exceptions\\Parser in PHPDoc @throws tag but it''s not thrown\.$#' identifier: throws.unusedType diff --git a/phpunit.integration.xml b/phpunit.integration.xml index 9f5f82b7..6da218fe 100644 --- a/phpunit.integration.xml +++ b/phpunit.integration.xml @@ -5,6 +5,7 @@ beStrictAboutTodoAnnotatedTests="true" verbose="true"> + diff --git a/src/lib/Server/Controller/Trash/TrashItemListController.php b/src/lib/Server/Controller/Trash/TrashItemListController.php index c40cbee1..ddd6b54b 100644 --- a/src/lib/Server/Controller/Trash/TrashItemListController.php +++ b/src/lib/Server/Controller/Trash/TrashItemListController.php @@ -82,8 +82,8 @@ public function loadTrashItems(Request $request): Trash $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : -1; $query = new Query(); - $query->offset = $offset >= 0 ? $offset : null; - $query->limit = $limit >= 0 ? $limit : null; + $query->offset = max($offset, 0); + $query->limit = max($limit, 0); $trashItems = []; diff --git a/src/lib/Server/Input/Parser/ContentCreate.php b/src/lib/Server/Input/Parser/ContentCreate.php index 4565de3a..0c246982 100644 --- a/src/lib/Server/Input/Parser/ContentCreate.php +++ b/src/lib/Server/Input/Parser/ContentCreate.php @@ -73,10 +73,29 @@ public function __construct( /** * Parse input structure. * - * @param array $data - * @param \Ibexa\Contracts\Rest\Input\ParsingDispatcher $parsingDispatcher + * @param array{ + * LocationCreate: array, + * ContentType: array{_href: string}, + * mainLanguageCode: string, + * Section?: array{_href: string}, + * alwaysAvailable?: bool|string, + * remoteId?: string, + * modificationDate?: string, + * User?: array{_href: string}, + * fields: array{ + * field: array< + * array{ + * fieldDefinitionIdentifier: string, + * fieldValue: mixed, + * languageCode?: string + * } + * > + * } + * } $data * - * @return \Ibexa\Rest\Server\Values\RestContentCreateStruct + * @throws \DateMalformedStringException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ public function parse(array $data, ParsingDispatcher $parsingDispatcher): RestContentCreateStruct { @@ -109,7 +128,7 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher): RestCo throw new Exceptions\Parser("Missing '_href' attribute for the Section element in ContentCreate."); } - $contentCreateStruct->sectionId = $this->uriParser->getAttributeFromUri($data['Section']['_href'], 'sectionId'); + $contentCreateStruct->sectionId = (int)$this->uriParser->getAttributeFromUri($data['Section']['_href'], 'sectionId'); } if (array_key_exists('alwaysAvailable', $data)) { @@ -129,7 +148,7 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher): RestCo throw new Exceptions\Parser("Missing '_href' attribute for the User element in ContentCreate."); } - $contentCreateStruct->ownerId = $this->uriParser->getAttributeFromUri($data['User']['_href'], 'userId'); + $contentCreateStruct->ownerId = (int)$this->uriParser->getAttributeFromUri($data['User']['_href'], 'userId'); } if (!array_key_exists('fields', $data) || !is_array($data['fields']) || !is_array($data['fields']['field'])) { diff --git a/src/lib/Server/Input/Parser/UserCreate.php b/src/lib/Server/Input/Parser/UserCreate.php index 9b5426fa..6eeda13f 100644 --- a/src/lib/Server/Input/Parser/UserCreate.php +++ b/src/lib/Server/Input/Parser/UserCreate.php @@ -57,6 +57,30 @@ public function __construct(UserService $userService, ContentTypeService $conten $this->parserTools = $parserTools; } + /** + * @param array{ + * ContentType?: array{_href: string}, + * mainLanguageCode: string, + * login: string, + * email: string, + * password: string, + * Section?: array{_href: string}, + * remoteId?: string, + * enabled?: bool|string, + * fields: array{ + * field: array< + * array{ + * fieldDefinitionIdentifier: string, + * fieldValue: mixed, + * languageCode?: string + * } + * > + * } + * } $data + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ public function parse(array $data, ParsingDispatcher $parsingDispatcher): UserCreateStruct { $contentType = null; @@ -99,7 +123,7 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher): UserCr throw new Exceptions\Parser("Missing '_href' attribute for the Section element in UserCreate."); } - $userCreateStruct->sectionId = $this->uriParser->getAttributeFromUri($data['Section']['_href'], 'sectionId'); + $userCreateStruct->sectionId = (int)$this->uriParser->getAttributeFromUri($data['Section']['_href'], 'sectionId'); } if (array_key_exists('remoteId', $data)) { diff --git a/src/lib/Server/Input/Parser/UserGroupCreate.php b/src/lib/Server/Input/Parser/UserGroupCreate.php index f276d688..e9b6c963 100644 --- a/src/lib/Server/Input/Parser/UserGroupCreate.php +++ b/src/lib/Server/Input/Parser/UserGroupCreate.php @@ -49,6 +49,26 @@ public function __construct(UserService $userService, ContentTypeService $conten $this->fieldTypeParser = $fieldTypeParser; } + /** + * @param array{ + * ContentType?: array{_href: string}, + * mainLanguageCode: string, + * Section?: array{_href: string}, + * remoteId?: string, + * fields: array{ + * field: array< + * array{ + * fieldDefinitionIdentifier: string, + * fieldValue: mixed, + * languageCode?: string + * } + * > + * } + * } $data + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ public function parse(array $data, ParsingDispatcher $parsingDispatcher): UserGroupCreateStruct { $contentType = null; @@ -73,7 +93,10 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher): UserGr throw new Exceptions\Parser("Missing '_href' attribute for the Section element in UserGroupCreate."); } - $userGroupCreateStruct->sectionId = $this->uriParser->getAttributeFromUri($data['Section']['_href'], 'sectionId'); + $userGroupCreateStruct->sectionId = (int)$this->uriParser->getAttributeFromUri( + $data['Section']['_href'], + 'sectionId' + ); } if (array_key_exists('remoteId', $data)) { diff --git a/src/lib/Server/Values/RestContentCreateStruct.php b/src/lib/Server/Values/RestContentCreateStruct.php index 2e0a3199..114bff07 100644 --- a/src/lib/Server/Values/RestContentCreateStruct.php +++ b/src/lib/Server/Values/RestContentCreateStruct.php @@ -16,25 +16,15 @@ */ class RestContentCreateStruct extends ValueObject { - /** - * @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct - */ - public $contentCreateStruct; + public ContentCreateStruct $contentCreateStruct; - /** - * @var \Ibexa\Contracts\Core\Repository\Values\Content\LocationCreateStruct - */ - public $locationCreateStruct; + public LocationCreateStruct $locationCreateStruct; - /** - * Construct. - * - * @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct $contentCreateStruct - * @param \Ibexa\Contracts\Core\Repository\Values\Content\LocationCreateStruct $locationCreateStruct - */ public function __construct(ContentCreateStruct $contentCreateStruct, LocationCreateStruct $locationCreateStruct) { $this->contentCreateStruct = $contentCreateStruct; $this->locationCreateStruct = $locationCreateStruct; + + parent::__construct(); } } diff --git a/tests/lib/Server/Input/Parser/ContentCreateTest.php b/tests/lib/Server/Input/Parser/ContentCreateTest.php index aebc6f96..8fa446f7 100644 --- a/tests/lib/Server/Input/Parser/ContentCreateTest.php +++ b/tests/lib/Server/Input/Parser/ContentCreateTest.php @@ -19,6 +19,7 @@ use Ibexa\Rest\Input\FieldTypeParser; use Ibexa\Rest\Server\Input\Parser\ContentCreate; use Ibexa\Rest\Server\Input\Parser\LocationCreate; +use Ibexa\Rest\Server\Values\RestContentCreateStruct; use PHPUnit\Framework\MockObject\MockObject; class ContentCreateTest extends BaseTest @@ -57,23 +58,11 @@ public function testParse(): void $result = $contentCreate->parse($inputArray, $this->getParsingDispatcherMock()); self::assertInstanceOf( - '\\Ibexa\\Rest\\Server\\Values\\RestContentCreateStruct', + RestContentCreateStruct::class, $result, 'ContentCreate not created correctly.' ); - self::assertInstanceOf( - '\\Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\ContentCreateStruct', - $result->contentCreateStruct, - 'contentCreateStruct not created correctly.' - ); - - self::assertInstanceOf( - '\\Ibexa\\Contracts\\Core\\Repository\\Values\\ContentType\\ContentType', - $result->contentCreateStruct->contentType, - 'contentType not created correctly.' - ); - self::assertEquals( 13, $result->contentCreateStruct->contentType->id, @@ -86,12 +75,6 @@ public function testParse(): void 'mainLanguageCode not created correctly' ); - self::assertInstanceOf( - '\\Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\LocationCreateStruct', - $result->locationCreateStruct, - 'locationCreateStruct not created correctly.' - ); - self::assertEquals( 4, $result->contentCreateStruct->sectionId, diff --git a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php index 809be94d..9ae7b9e4 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php @@ -62,6 +62,7 @@ public function testVisitLocationAttributesResolvesMainLocation( 'priority' => 1, 'sortField' => ApiLocation::SORT_FIELD_DEPTH, 'sortOrder' => ApiLocation::SORT_ORDER_ASC, + 'remoteId' => 'cefb8160c6e88d8ea5ae1f31e0c201fc', 'parentLocationId' => 42, 'contentInfo' => new ContentInfo([ 'id' => $contentId, diff --git a/tests/lib/Server/Output/ValueObjectVisitor/RestLocationRootNodeTest.php b/tests/lib/Server/Output/ValueObjectVisitor/RestLocationRootNodeTest.php index 13ebe184..dfc9bf7f 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/RestLocationRootNodeTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/RestLocationRootNodeTest.php @@ -36,7 +36,7 @@ public function testVisit() 'invisible' => true, 'explicitlyHidden' => true, 'remoteId' => 'remote-id', - 'parentLocationId' => null, + 'parentLocationId' => 1, 'pathString' => '/1', 'depth' => 3, 'sortField' => Location::SORT_FIELD_PATH,