Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
69b92a5
[ContentCreate] Added int cast to ownerId and sectionId strict proper…
alongosz Jul 3, 2025
acd5d2b
[ContentCreate] Defined array shape of ContentCreate::parse `$data` arg
alongosz Jul 3, 2025
2609dd7
[ContentCreate] Added missing `@throws` to ContentCreate::parse method
alongosz Jul 3, 2025
5965545
[UserCreate] Defined array shape of UserCreate::parse `$data` arg
alongosz Jul 3, 2025
7438dbf
[UserCreate] Added int cast to sectionId strict property
alongosz Jul 3, 2025
7f55edc
Added missing type hints to \Ibexa\Rest\Server\Values\RestContentCrea…
alongosz Jul 3, 2025
d839603
[Tests] Replaced literal FQCN usage with `RestContentCreateStruct::cl…
alongosz Jul 3, 2025
040e22c
[Tests] Dropped unnecessary assertions due to strict types changes
alongosz Jul 3, 2025
793efff
[UserGroupCreate] Defined array shape of UserGroupCreate::parse `$dat…
alongosz Jul 3, 2025
7d6b0ce
[UserGroupCreate] Added int cast to sectionId strict property
alongosz Jul 3, 2025
48ec856
[Tests] Defined non-nullable `remoteId` property for Location stub of…
alongosz Jul 3, 2025
46b9e19
[Tests] Fixed non-nullable `parentRemoteId` property for Location stu…
alongosz Jul 3, 2025
862755f
[Tests][PHPUnit] Configured UTC timezone for integration tests
alongosz Jul 3, 2025
c3d690d
Fixed incorrect default value assignment to Query properties in Trash…
alongosz Jul 3, 2025
71981af
[CS] Fixed readability in UserGroupCreate
alongosz Jul 7, 2025
491a90e
[PHPStan] Removed resolved issues from the baseline
alongosz Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions phpunit.integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<php>
<ini name="date.timezone" value="UTC" />
<env name="KERNEL_CLASS" value="Ibexa\Tests\Integration\Rest\IbexaTestKernel" />
<env name="SEARCH_ENGINE" value="legacy" />
<env name="DATABASE_URL" value="sqlite://i@i/test.db" />
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Server/Controller/Trash/TrashItemListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
29 changes: 24 additions & 5 deletions src/lib/Server/Input/Parser/ContentCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)) {
Expand All @@ -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'])) {
Expand Down
26 changes: 25 additions & 1 deletion src/lib/Server/Input/Parser/UserCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
25 changes: 24 additions & 1 deletion src/lib/Server/Input/Parser/UserGroupCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
18 changes: 4 additions & 14 deletions src/lib/Server/Values/RestContentCreateStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
21 changes: 2 additions & 19 deletions tests/lib/Server/Input/Parser/ContentCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading