Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #170

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions src/Endpoints/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
3 changes: 1 addition & 2 deletions src/Entities/Collections/UserCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
8 changes: 5 additions & 3 deletions src/Entities/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions tests/RecordedEndpointPageTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

use Carbon\Carbon;
use FiveamCode\LaravelNotionApi\Entities\Collections\CommentCollection;
use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
use FiveamCode\LaravelNotionApi\Entities\Comment;
use FiveamCode\LaravelNotionApi\Entities\Entity;
use FiveamCode\LaravelNotionApi\Entities\Properties\Property;
use Illuminate\Support\Facades\Http;

Expand Down