Skip to content

Commit dbe7eae

Browse files
authored
Collections are non nullable anymore (#24)
* Collections are non nullable anymore
1 parent 31332b5 commit dbe7eae

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

src/Request/StoriesRequest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Storyblok\Api\Request;
1515

16-
use OskarStark\Value\TrimmedNonEmptyString;
1716
use Storyblok\Api\Domain\Value\Dto\Pagination;
1817
use Storyblok\Api\Domain\Value\Dto\SortBy;
1918
use Storyblok\Api\Domain\Value\Dto\Version;
@@ -36,11 +35,11 @@ public function __construct(
3635
public string $language = 'default',
3736
public Pagination $pagination = new Pagination(perPage: self::PER_PAGE),
3837
public ?SortBy $sortBy = null,
39-
public ?FilterCollection $filters = null,
40-
public ?FieldCollection $excludeFields = null,
41-
public ?TagCollection $withTags = null,
42-
public ?IdCollection $excludeIds = null,
43-
public ?RelationCollection $withRelations = null,
38+
public FilterCollection $filters = new FilterCollection(),
39+
public FieldCollection $excludeFields = new FieldCollection(),
40+
public TagCollection $withTags = new TagCollection(),
41+
public IdCollection $excludeIds = new IdCollection(),
42+
public RelationCollection $withRelations = new RelationCollection(),
4443
public ?Version $version = null,
4544
public ?string $searchTerm = null,
4645
) {
@@ -74,23 +73,23 @@ public function toArray(): array
7473
$array['sort_by'] = $this->sortBy->toString();
7574
}
7675

77-
if (null !== $this->filters && $this->filters->count() > 0) {
76+
if ($this->filters->count() > 0) {
7877
$array['filter_query'] = $this->filters->toArray();
7978
}
8079

81-
if (null !== $this->withTags && $this->withTags->count() > 0) {
80+
if ($this->withTags->count() > 0) {
8281
$array['with_tag'] = $this->withTags->toString();
8382
}
8483

85-
if (null !== $this->excludeFields && $this->excludeFields->count() > 0) {
84+
if ($this->excludeFields->count() > 0) {
8685
$array['excluding_fields'] = $this->excludeFields->toString();
8786
}
8887

89-
if (null !== $this->excludeIds && $this->excludeIds->count() > 0) {
88+
if ($this->excludeIds->count() > 0) {
9089
$array['excluding_ids'] = $this->excludeIds->toString();
9190
}
9291

93-
if (null !== $this->withRelations && $this->withRelations->count() > 0) {
92+
if ($this->withRelations->count() > 0) {
9493
$array['resolve_relations'] = $this->withRelations->toString();
9594
}
9695

src/Request/StoryRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public function __construct(
2626
public string $language = 'default',
2727
public ?Version $version = null,
28-
public ?RelationCollection $withRelations = null,
28+
public RelationCollection $withRelations = new RelationCollection(),
2929
) {
3030
Assert::stringNotEmpty($language);
3131
}
@@ -47,7 +47,7 @@ public function toArray(): array
4747
$array['version'] = $this->version->value;
4848
}
4949

50-
if (null !== $this->withRelations && $this->withRelations->count() > 0) {
50+
if ($this->withRelations->count() > 0) {
5151
$array['resolve_relations'] = $this->withRelations->toString();
5252
}
5353

src/StoriesResolvedApi.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ public function all(?StoriesRequest $request = null): StoriesResponse
3636
{
3737
$response = $this->storiesApi->all($request);
3838

39-
if (null === $request
40-
|| null === $request->withRelations
41-
|| 0 === $request->withRelations->count()
42-
) {
39+
if (null === $request || 0 === $request->withRelations->count()) {
4340
return $response;
4441
}
4542

@@ -65,10 +62,7 @@ public function allByContentType(string $contentType, ?StoriesRequest $request =
6562
{
6663
$response = $this->storiesApi->allByContentType($contentType, $request);
6764

68-
if (null === $request
69-
|| null === $request->withRelations
70-
|| 0 === $request->withRelations->count()
71-
) {
65+
if (null === $request || 0 === $request->withRelations->count()) {
7266
return $response;
7367
}
7468

0 commit comments

Comments
 (0)