Skip to content

Commit 00938fe

Browse files
committed
refactor: 'propertyNames' to 'propertyKeys'
+ handle undefined propertyKey in 'getProperty()' => null
1 parent a58b905 commit 00938fe

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/Entities/Database.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Database extends Entity
1414
protected string $objectType = "";
1515
protected array $rawTitle = [];
1616
protected array $rawProperties = [];
17-
protected array $propertyNames = [];
17+
protected array $propertyKeys = [];
1818
protected DateTime $createdTime;
1919
protected DateTime $lastEditedTime;
2020

@@ -57,7 +57,7 @@ private function fillProperties(): void
5757
{
5858
if (Arr::exists($this->responseData, 'properties')) {
5959
$this->rawProperties = $this->responseData['properties'];
60-
$this->propertyNames = array_keys($this->rawProperties);
60+
$this->propertyKeys = array_keys($this->rawProperties);
6161
}
6262
}
6363

@@ -88,9 +88,9 @@ public function getRawProperties(): array
8888
return $this->rawProperties;
8989
}
9090

91-
public function getPropertyNames(): array
91+
public function getPropertyKeys(): array
9292
{
93-
return $this->propertyNames;
93+
return $this->propertyKeys;
9494
}
9595

9696
public function getCreatedTime(): DateTime

src/Entities/Page.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Page extends Entity
1515
protected string $objectType = "";
1616
protected array $rawProperties = [];
1717
protected array $propertyMap = [];
18+
protected array $propertyKeys = [];
1819
protected Collection $properties;
1920
protected DateTime $createdTime;
2021
protected DateTime $lastEditedTime;
@@ -54,6 +55,7 @@ private function fillProperties(): void
5455
$this->properties->add($property);
5556
$this->propertyMap[$propertyKey] = $property;
5657
}
58+
$this->propertyKeys = array_keys($this->rawProperties);
5759
}
5860
}
5961

@@ -83,10 +85,12 @@ public function getProperties(): Collection
8385
return $this->properties;
8486
}
8587

86-
public function getProperty(string $propertyName): ?Property
88+
public function getProperty(string $propertyKey): ?Property
8789
{
88-
//TODO:Handle undefined propertyNames (exception/null/?)
89-
return $this->propertyMap[$propertyName];
90+
if(!isset($this->propertyMap[$propertyKey])){
91+
return null;
92+
}
93+
return $this->propertyMap[$propertyKey];
9094
}
9195

9296
public function getObjectType(): string
@@ -99,9 +103,9 @@ public function getRawProperties(): array
99103
return $this->rawProperties;
100104
}
101105

102-
public function getPropertyNames(): array
106+
public function getPropertyKeys(): array
103107
{
104-
return array_keys($this->rawProperties);
108+
return $this->propertyKeys;
105109
}
106110

107111
public function getCreatedTime(): DateTime

src/Entities/Properties/Number.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class Number extends Property
1818
protected function fillFromRaw(): void
1919
{
2020
parent::fillFromRaw();
21-
// if (!is_array($this->rawContent))
22-
// throw HandlingException::instance("The property-type is number, however the raw data-structure does not represent this type (= array of items). Please check the raw response-data.");
23-
2421
$this->fillNumber();
2522
}
2623

0 commit comments

Comments
 (0)