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 #101

Merged
merged 1 commit into from
Feb 2, 2023
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
16 changes: 7 additions & 9 deletions src/Console/Commands/MakeNotionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MakeNotionModel extends Command
*/
public function handle()
{

$databaseId = $this->argument('database_id');
$databaseName = $this->argument('database_name');

Expand All @@ -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(), '_')));
Expand All @@ -53,17 +52,15 @@ 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(), '_');
$phpDocsProperties .= " * @property {$propType} \${$propName} $notionPropType \n";
$visibleArray .= " '$propName',\n";
}



$contents = "<?php
namespace App\NotionModels;

Expand Down Expand Up @@ -93,6 +90,7 @@ class {$databaseName} extends NotionModel

File::put("app/NotionModels/$databaseName.php", $contents);
$this->info("Model for database {$this->argument('database_id')} has been created at 'app/NotionModels/$databaseName.php' .");

return 0;
}
}
4 changes: 2 additions & 2 deletions src/LaravelNotionApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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'));
Expand Down
21 changes: 5 additions & 16 deletions src/Models/NotionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -44,27 +37,26 @@ class NotionModel
public static $cacheDurationInSeconds = 0;

/**
* @var boolean
* @var bool
*/
public static $convertPropsToText = false;

public $props;

public Page $page;


public function __construct($databaseId = null)
{
if ($databaseId == null) {
$databaseId = static::$databaseId;
}
}

public static function createInstance(){
public static function createInstance()
{
return new static();
}


/**
* @return string
*/
Expand All @@ -77,7 +69,7 @@ public static function databaseId(): string
}

/**
* @return
* @return
*/
public static function notionInstance(): Notion
{
Expand Down Expand Up @@ -105,8 +97,6 @@ public static function all()
return self::query()->get();
}



/**
* @return ?static
*/
Expand Down Expand Up @@ -142,5 +132,4 @@ public static function getNextCursor(): ?string
{
return self::$nextCursor;
}

}
23 changes: 9 additions & 14 deletions src/Models/NotionQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +22,6 @@ class NotionQueryBuilder

private $modelClass = null;


public ?Database $endpoint = null;
public ?Collection $filters = null;
public ?Collection $sortings = null;
Expand All @@ -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
Expand Down Expand Up @@ -110,7 +108,6 @@ public function get()
return $this->internalQuery();
}


/**
* @return string
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
);
Expand All @@ -231,8 +229,6 @@ public function where($property, $operator, $value = null)
return $this;
}



public function paginate($pageSize = 100)
{
$this->endpoint->limit($pageSize);
Expand All @@ -244,7 +240,6 @@ public function paginate($pageSize = 100)

$result = $this->internalQuery();


return [
'per_page' => $pageSize,
'next_cursor' => $result->getRawNextCursor(),
Expand All @@ -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;
}
}