diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php index 6918295..50278a6 100644 --- a/src/Endpoints/Page.php +++ b/src/Endpoints/Page.php @@ -41,17 +41,19 @@ public function __construct(Notion $notion, string $pageId) public function property(string $propertyId): Property|EntityCollection { $response = $this->get( - $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . rawurlencode(rawurldecode($propertyId))) + $this->url(Endpoint::PAGES.'/'.$this->pageId.'/'.'properties'.'/'.rawurlencode(rawurldecode($propertyId))) ); $rawContent = $response->json(); - if($rawContent['object'] === 'list'){ - if(count($rawContent['results']) === 0) return new EntityCollection(); + if ($rawContent['object'] === 'list') { + if (count($rawContent['results']) === 0) { + return new EntityCollection(); + } $type = $rawContent['results'][0]['type']; - return match($type){ + return match ($type) { 'people' => new UserCollection($rawContent), default => new EntityCollection($rawContent) }; diff --git a/src/Entities/Collections/UserCollection.php b/src/Entities/Collections/UserCollection.php index 2e36ff5..2f364a3 100644 --- a/src/Entities/Collections/UserCollection.php +++ b/src/Entities/Collections/UserCollection.php @@ -14,9 +14,8 @@ protected function collectChildren(): void { $this->collection = new Collection(); foreach ($this->rawResults as $userChild) { - //TODO: create a new type for 'people' (outer layer for user) - if($userChild['type'] === 'people') { + if ($userChild['type'] === 'people') { $userChild = $userChild['people']; } diff --git a/src/Entities/Properties/Property.php b/src/Entities/Properties/Property.php index 386081f..e86687b 100644 --- a/src/Entities/Properties/Property.php +++ b/src/Entities/Properties/Property.php @@ -74,7 +74,7 @@ public function __construct(string $title = null) */ protected function setResponseData(array $responseData): void { - if (!Arr::exists($responseData, 'id')) { + if (! Arr::exists($responseData, 'id')) { throw HandlingException::instance('invalid json-array for property: no id provided'); } $this->responseData = $responseData; @@ -88,7 +88,7 @@ protected function setResponseData(array $responseData): void */ protected function setObjectResponseData(array $responseData): void { - if (!Arr::exists($responseData, 'object') || !Arr::exists($responseData, 'id')) { + if (! Arr::exists($responseData, 'object') || ! Arr::exists($responseData, 'id')) { throw HandlingException::instance('invalid json-array for property: no object or id provided'); } $this->responseData = $responseData; @@ -112,12 +112,14 @@ private function fillContent(): void if (Arr::exists($this->responseData, $this->getType())) { $this->rawContent = $this->responseData[$this->getType()]; $this->content = $this->rawContent; + return; } if (Arr::exists($this->responseData, 'object') && Arr::exists($this->responseData, $this->getObjectType())) { $this->rawContent = $this->responseData[$this->getObjectType()]; $this->content = $this->rawContent; + return; } } @@ -264,7 +266,7 @@ private static function mapTypeToClass(string $type): string case 'relation': $class = str_replace('_', '', ucwords($type, '_')); - return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\' . $class; + return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\'.$class; case 'text': case 'rich_text': // TODO: Depending on the Notion API version. diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index f538425..5205111 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -1,10 +1,6 @@