Skip to content

Commit db1fa13

Browse files
committed
fix types in collections, add getter for objectType (database/page)
1 parent d32646d commit db1fa13

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

src/Entities/Collections/BlockCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class BlockCollection extends EntityCollection
1313
{
14-
protected function collectChildren()
14+
protected function collectChildren() : void
1515
{
1616
$this->collection = new Collection();
1717
foreach ($this->rawResults as $blockChild) {

src/Entities/Collections/DatabaseCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class DatabaseCollection extends EntityCollection
1313
{
14-
protected function collectChildren()
14+
protected function collectChildren() : void
1515
{
1616
$this->collection = new Collection();
1717
foreach ($this->rawResults as $databaseChild) {

src/Entities/Collections/PageCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class PageCollection extends EntityCollection
1313
{
14-
protected function collectChildren()
14+
protected function collectChildren() : void
1515
{
1616
$this->collection = new Collection();
1717
foreach ($this->rawResults as $pageChild) {

src/Entities/Collections/UserCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class UserCollection extends EntityCollection
1313
{
14-
protected function collectChildren()
14+
protected function collectChildren() : void
1515
{
1616
$this->collection = new Collection();
1717
foreach ($this->rawResults as $userChild) {

src/Entities/Database.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class Database extends Entity
1212
{
1313
protected string $title = "";
14+
protected string $objectType = "";
1415
protected array $rawTitle = [];
1516
protected array $rawProperties = [];
1617
protected DateTime $createdTime;
@@ -29,26 +30,40 @@ private function fillFromRaw()
2930
{
3031
$this->fillId();
3132
$this->fillTitle();
33+
$this->fillObjectType();
3234
$this->fillProperties();
3335
$this->fillCreatedTime();
3436
$this->fillLastEditedTime();
3537
}
3638

37-
private function fillTitle() : void
39+
private function fillTitle(): void
3840
{
3941
if (Arr::exists($this->responseData, 'title') && is_array($this->responseData['title'])) {
4042
$this->title = Arr::first($this->responseData['title'], null, ['plain_text' => ''])['plain_text'];
4143
$this->rawTitle = $this->responseData['title'];
4244
}
4345
}
4446

45-
private function fillProperties() : void
47+
private function fillObjectType(): void
48+
{
49+
if (Arr::exists($this->responseData, 'object')) {
50+
$this->objectType = $this->responseData['object'];
51+
}
52+
}
53+
54+
private function fillProperties(): void
4655
{
4756
if (Arr::exists($this->responseData, 'properties')) {
4857
$this->rawProperties = $this->responseData['properties'];
4958
}
5059
}
5160

61+
public function getObjectType(): string
62+
{
63+
return $this->objectType;
64+
}
65+
66+
5267
public function getTitle(): string
5368
{
5469
return $this->title;

src/Entities/Page.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class Page extends Entity
1313
{
1414
protected string $title = "";
15+
protected string $objectType = "";
1516
protected array $rawProperties = [];
1617
protected Collection $propertyCollection;
1718
protected DateTime $createdTime;
@@ -28,12 +29,20 @@ protected function setResponseData(array $responseData): void
2829
private function fillFromRaw(): void
2930
{
3031
$this->fillId();
32+
$this->fillObjectType();
3133
$this->fillProperties();
32-
$this->fillTitle();
34+
$this->fillTitle(); //!Warning: call after 'fillProperties', since title is included within properties
3335
$this->fillCreatedTime();
3436
$this->fillLastEditedTime();
3537
}
3638

39+
private function fillObjectType(): void
40+
{
41+
if (Arr::exists($this->responseData, 'object')) {
42+
$this->type = $this->responseData['object'];
43+
}
44+
}
45+
3746
private function fillProperties(): void
3847
{
3948
if (Arr::exists($this->responseData, 'properties')) {
@@ -45,6 +54,7 @@ private function fillProperties(): void
4554
}
4655
}
4756

57+
4858
private function fillTitle(): void
4959
{
5060
$titleProperty = $this->propertyCollection->filter(function ($property) {
@@ -81,6 +91,11 @@ public function getProperty(string $propertyName): ?Property
8191
return $property;
8292
}
8393

94+
public function getObjectType(): string
95+
{
96+
return $this->objectType;
97+
}
98+
8499
public function getRawProperties(): array
85100
{
86101
return $this->rawProperties;

0 commit comments

Comments
 (0)