diff --git a/src/Console/Commands/MakeNotionModel.php b/src/Console/Commands/MakeNotionModel.php index d95aa29..799075b 100644 --- a/src/Console/Commands/MakeNotionModel.php +++ b/src/Console/Commands/MakeNotionModel.php @@ -30,7 +30,6 @@ class MakeNotionModel extends Command */ public function handle() { - $databaseId = $this->argument('database_id'); $databaseName = $this->argument('database_name'); @@ -39,10 +38,10 @@ public function handle() $this->info("Fetching structure of {$databaseId} database from Notion..."); $databaseStruct = $notion->databases()->find($databaseId); - $phpDocsProperties = ""; - $visibleArray = ""; - $propertyTypeMape = ""; - $propertyTitleMap = ""; + $phpDocsProperties = ''; + $visibleArray = ''; + $propertyTypeMape = ''; + $propertyTitleMap = ''; if ($databaseName === null) { $databaseName = Str::singular(Str::studly(Str::slug($databaseStruct->getTitle(), '_'))); @@ -53,8 +52,8 @@ public function handle() $propType = $reflection->getReturnType() ?? 'mixed'; $notionPropType = Str::studly(Str::slug($propertyInfo->getType(), '_')); - if ($reflection->getReturnType() !== null && !$propType->isBuiltin()) { - $propType = '\\' . $propType->getName(); + if ($reflection->getReturnType() !== null && ! $propType->isBuiltin()) { + $propType = '\\'.$propType->getName(); } $propName = Str::slug($propertyInfo->getTitle(), '_'); @@ -62,8 +61,6 @@ public function handle() $visibleArray .= " '$propName',\n"; } - - $contents = "info("Model for database {$this->argument('database_id')} has been created at 'app/NotionModels/$databaseName.php' ."); + return 0; } } diff --git a/src/LaravelNotionApiServiceProvider.php b/src/LaravelNotionApiServiceProvider.php index 9650f93..bcb1162 100644 --- a/src/LaravelNotionApiServiceProvider.php +++ b/src/LaravelNotionApiServiceProvider.php @@ -17,7 +17,7 @@ public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../config/config.php' => config_path('laravel-notion-api.php'), + __DIR__.'/../config/config.php' => config_path('laravel-notion-api.php'), ], 'config'); $this->commands([ @@ -32,7 +32,7 @@ public function boot() public function register() { // Automatically apply the package configuration - $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-notion-api'); + $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-notion-api'); $this->app->singleton(Notion::class, function () { return new Notion(config('laravel-notion-api.notion-api-token'), config('laravel-notion-api.version')); diff --git a/src/Models/NotionModel.php b/src/Models/NotionModel.php index f4e49bf..d9ad872 100644 --- a/src/Models/NotionModel.php +++ b/src/Models/NotionModel.php @@ -2,19 +2,12 @@ namespace FiveamCode\LaravelNotionApi\Models; -use FiveamCode\LaravelNotionApi\Endpoints\Database; -use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection; use FiveamCode\LaravelNotionApi\Entities\Page; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Notion; -use FiveamCode\LaravelNotionApi\Query\Filters\Filter; -use FiveamCode\LaravelNotionApi\Query\Filters\Operators; -use FiveamCode\LaravelNotionApi\Query\Sorting; use FiveamCode\LaravelNotionApi\Query\StartCursor; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Request; -use Illuminate\Support\Str; class NotionModel { @@ -44,7 +37,7 @@ class NotionModel public static $cacheDurationInSeconds = 0; /** - * @var boolean + * @var bool */ public static $convertPropsToText = false; @@ -52,7 +45,6 @@ class NotionModel public Page $page; - public function __construct($databaseId = null) { if ($databaseId == null) { @@ -60,11 +52,11 @@ public function __construct($databaseId = null) } } - public static function createInstance(){ + public static function createInstance() + { return new static(); } - /** * @return string */ @@ -77,7 +69,7 @@ public static function databaseId(): string } /** - * @return + * @return */ public static function notionInstance(): Notion { @@ -105,8 +97,6 @@ public static function all() return self::query()->get(); } - - /** * @return ?static */ @@ -142,5 +132,4 @@ public static function getNextCursor(): ?string { return self::$nextCursor; } - } diff --git a/src/Models/NotionQueryBuilder.php b/src/Models/NotionQueryBuilder.php index bbed8cd..56db5f6 100644 --- a/src/Models/NotionQueryBuilder.php +++ b/src/Models/NotionQueryBuilder.php @@ -5,13 +5,11 @@ use FiveamCode\LaravelNotionApi\Endpoints\Database; use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection; use FiveamCode\LaravelNotionApi\Entities\Page; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use Illuminate\Support\Collection; -use FiveamCode\LaravelNotionApi\Notion; use FiveamCode\LaravelNotionApi\Query\Filters\Filter; use FiveamCode\LaravelNotionApi\Query\Filters\Operators; use FiveamCode\LaravelNotionApi\Query\StartCursor; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; @@ -24,7 +22,6 @@ class NotionQueryBuilder private $modelClass = null; - public ?Database $endpoint = null; public ?Collection $filters = null; public ?Collection $sortings = null; @@ -41,7 +38,8 @@ public function __construct($class) public function pluck($value, $key = null): Collection { $pageCollection = $this->internalQuery(); - return $pageCollection->pluck('props.' . $value, $key !== null ? 'props.' . $key : null); + + return $pageCollection->pluck('props.'.$value, $key !== null ? 'props.'.$key : null); } private function queryToNotion(int $limit = 100): PageCollection @@ -110,7 +108,6 @@ public function get() return $this->internalQuery(); } - /** * @return string */ @@ -132,23 +129,24 @@ public function getAllAsJson() public function propsToText() { $this->localConvertPropsToText = true; + return $this; } - public function offset($offset) { $this->endpoint->offset($offset); + return $this; } public function limit($offset) { $this->endpoint->limit($offset); + return $this; } - public function orderBy($property, $direction = 'asc') { if ($this->sortings == null) { @@ -218,7 +216,7 @@ public function where($property, $operator, $value = null) $this->filters->add( Filter::textFilter($property, $operator, $value) ); - } else if (is_numeric($value)) { + } elseif (is_numeric($value)) { $this->filters->add( Filter::numberFilter($property, $operator, $value) ); @@ -231,8 +229,6 @@ public function where($property, $operator, $value = null) return $this; } - - public function paginate($pageSize = 100) { $this->endpoint->limit($pageSize); @@ -244,7 +240,6 @@ public function paginate($pageSize = 100) $result = $this->internalQuery(); - return [ 'per_page' => $pageSize, 'next_cursor' => $result->getRawNextCursor(), @@ -262,9 +257,9 @@ private function cacheKey(): string { $postCacheKey = ''; if ($this->nextCursor !== null) { - $postCacheKey = '-' . $this->nextCursor->__toString(); + $postCacheKey = '-'.$this->nextCursor->__toString(); } - return $this->modelClass::$preCacheKey . $this->modelClass::$databaseId . $postCacheKey; + return $this->modelClass::$preCacheKey.$this->modelClass::$databaseId.$postCacheKey; } }