diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index a4dd1e9..eaa8483 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,18 +1,20 @@ ignoreDotFiles(false) ->ignoreVCSIgnored(true) ->in(__DIR__) ; -$config = new PhpCsFixer\Config(); +$config = new Config(); $config ->setRiskyAllowed(true) ->setRules([ - '@PHP81Migration' => true, + '@PHP83Migration' => true, '@PHP80Migration:risky' => true, 'heredoc_indentation' => false, '@PhpCsFixer' => true, diff --git a/LICENSE b/LICENSE index e21b67c..3032254 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License Copyright (c) 2021 Arafat Islam - 2022 Samuel Melrose + 2022 Samuel Melrose Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index cdc795d..1403dab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Laravel Eloquent for Google Datastore -![Latest Stable Version](https://poser.pugx.org/a1comms/eloquent-datastore/v) -![License](https://poser.pugx.org/a1comms/eloquent-datastore/license) +![Latest Stable Version](https://poser.pugx.org/AffordableMobiles/eloquent-datastore/v) +![License](https://poser.pugx.org/AffordableMobiles/eloquent-datastore/license) A package for using Google Datastore as a database driver. @@ -15,7 +15,7 @@ By using this package, you can use `query builder` and `eloquent` to access data You can install the package via composer: ```bash -composer require a1comms/eloquent-datastore +composer require affordablemobiles/eloquent-datastore ``` If you are using Laravel Package Auto-Discovery, you don't need you to manually add the ServiceProvider. @@ -25,7 +25,7 @@ If you are using Laravel Package Auto-Discovery, you don't need you to manually If you don't use auto-discovery, add the below ServiceProvider to the `$providers` array in `config/app.php` file. ```php -A1comms\EloquentDatastore\DatastoreServiceProvider::class, +AffordableMobiles\EloquentDatastore\DatastoreServiceProvider::class, ``` ## Roadmap @@ -59,7 +59,7 @@ You need to add `datastore` connection in `config/database.php` file. ### Access using Eloquent Model -You need to extend `A1comms\EloquentDatastore\Eloquent\Model` class instead of Laravel's default Eloquent model class. +You need to extend `AffordableMobiles\EloquentDatastore\Eloquent\Model` class instead of Laravel's default Eloquent model class. **Example-** ```php @@ -67,7 +67,7 @@ You need to extend `A1comms\EloquentDatastore\Eloquent\Model` class instead of L namespace App\Models; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class Project extends Model { diff --git a/composer.json b/composer.json index 12a5071..522a99c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "a1comms/eloquent-datastore", + "name": "affordablemobiles/eloquent-datastore", "description": "A package for using Google Datastore as a database driver.", "type": "package", "license": "MIT", @@ -7,7 +7,7 @@ "authors": [ { "name": "Samuel Melrose", - "email": "sam.melrose@a1comms.com" + "email": "sam.melrose@affordablemobilels.co.uk" }, { "name": "Appsero", @@ -15,33 +15,33 @@ } ], "require": { - "php": "^8.1", + "php": "^8.3", "ext-json": "*", - "illuminate/support": "^9", - "illuminate/pagination": "^9", - "illuminate/database": "^9", - "illuminate/http": "^9", - "google/cloud-datastore": "^1.13.3", - "rennokki/laravel-eloquent-query-cache": "~3" + "illuminate/support": "~11", + "illuminate/pagination": "~11", + "illuminate/database": "~11", + "illuminate/http": "~11", + "google/cloud-datastore": "^1.28.0", + "affordablemobiles/laravel-eloquent-query-cache": "~11" }, "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^10", "friendsofphp/php-cs-fixer": "^3.6" }, "autoload": { "psr-4": { - "A1comms\\EloquentDatastore\\": "src/" + "AffordableMobiles\\EloquentDatastore\\": "src/" } }, "autoload-dev": { "psr-4": { - "A1comms\\EloquentDatastore\\Tests\\": "tests/" + "AffordableMobiles\\EloquentDatastore\\Tests\\": "tests/" } }, "extra": { "laravel": { "providers": [ - "A1comms\\EloquentDatastore\\DatastoreServiceProvider" + "AffordableMobiles\\EloquentDatastore\\DatastoreServiceProvider" ] } } diff --git a/examples/Http/Controllers/DMLQueryController.php b/examples/Http/Controllers/DMLQueryController.php index f695210..d520154 100644 --- a/examples/Http/Controllers/DMLQueryController.php +++ b/examples/Http/Controllers/DMLQueryController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers; -use A1comms\EloquentDatastore\Eloquent\Collection; +use AffordableMobiles\EloquentDatastore\Eloquent\Collection; use App\Models\People; use Illuminate\Support\Facades\DB; diff --git a/examples/Http/Controllers/Named/QueryController.php b/examples/Http/Controllers/Named/QueryController.php index ed36416..773ce80 100644 --- a/examples/Http/Controllers/Named/QueryController.php +++ b/examples/Http/Controllers/Named/QueryController.php @@ -134,7 +134,7 @@ public function chunk(): void // Process all records returned by a query using a closure, // in pages / chunks, specifying a chunk size of 2 entities at a time. - People::where('last_name', 'Melrose')->chunk(self::CHUNK_SIZE, function ($results, $page) use (&$arr): void { + People::where('last_name', 'Melrose')->chunk(self::CHUNK_SIZE, static function ($results, $page) use (&$arr): void { foreach ($results as $result) { $arr[] = [ 'first_name' => $result->first_name, @@ -154,7 +154,7 @@ public function each(): void // Process all records returned by a query using a closure, // fetched from the DB as chunks of 2 entities at a time, // handled by our closure one record at a time. - People::where('last_name', 'Melrose')->each(function ($result) use (&$arr): void { + People::where('last_name', 'Melrose')->each(static function ($result) use (&$arr): void { $arr[] = [ 'first_name' => $result->first_name, 'last_name' => $result->last_name, diff --git a/examples/Http/Controllers/QueryController.php b/examples/Http/Controllers/QueryController.php index 51c7631..c36cc20 100644 --- a/examples/Http/Controllers/QueryController.php +++ b/examples/Http/Controllers/QueryController.php @@ -133,7 +133,7 @@ public function chunk(): void // Process all records returned by a query using a closure, // in pages / chunks, specifying a chunk size of 2 entities at a time. - People::where('last_name', 'Melrose')->chunk(self::CHUNK_SIZE, function ($results, $page) use (&$arr): void { + People::where('last_name', 'Melrose')->chunk(self::CHUNK_SIZE, static function ($results, $page) use (&$arr): void { foreach ($results as $result) { $arr[] = [ 'first_name' => $result->first_name, @@ -153,7 +153,7 @@ public function each(): void // Process all records returned by a query using a closure, // fetched from the DB as chunks of 2 entities at a time, // handled by our closure one record at a time. - People::where('last_name', 'Melrose')->each(function ($result) use (&$arr): void { + People::where('last_name', 'Melrose')->each(static function ($result) use (&$arr): void { $arr[] = [ 'first_name' => $result->first_name, 'last_name' => $result->last_name, diff --git a/examples/Models/Basket.php b/examples/Models/Basket.php index 7f394f5..ae011ea 100644 --- a/examples/Models/Basket.php +++ b/examples/Models/Basket.php @@ -4,7 +4,7 @@ namespace App\Models; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class Basket extends Model { diff --git a/examples/Models/BasketCached.php b/examples/Models/BasketCached.php index 100f9da..cba6258 100644 --- a/examples/Models/BasketCached.php +++ b/examples/Models/BasketCached.php @@ -4,7 +4,7 @@ namespace App\Models; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class BasketCached extends Model { diff --git a/examples/Models/Named/Basket.php b/examples/Models/Named/Basket.php index 8901575..815987a 100644 --- a/examples/Models/Named/Basket.php +++ b/examples/Models/Named/Basket.php @@ -4,7 +4,7 @@ namespace App\Models\Named; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class Basket extends Model { diff --git a/examples/Models/Named/Order.php b/examples/Models/Named/Order.php index 50ef1c4..3c2af36 100644 --- a/examples/Models/Named/Order.php +++ b/examples/Models/Named/Order.php @@ -4,7 +4,7 @@ namespace App\Models\Named; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; use Illuminate\Database\Eloquent\Casts\AsArrayObject; class Order extends Model diff --git a/examples/Models/Named/People.php b/examples/Models/Named/People.php index df5bd1f..1ddb08d 100644 --- a/examples/Models/Named/People.php +++ b/examples/Models/Named/People.php @@ -4,7 +4,7 @@ namespace App\Models\Named; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class People extends Model { diff --git a/examples/Models/Order.php b/examples/Models/Order.php index 6b5654e..91ab095 100644 --- a/examples/Models/Order.php +++ b/examples/Models/Order.php @@ -4,7 +4,7 @@ namespace App\Models; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; use Illuminate\Database\Eloquent\Casts\AsArrayObject; class Order extends Model diff --git a/examples/Models/People.php b/examples/Models/People.php index 260e4cf..b832474 100644 --- a/examples/Models/People.php +++ b/examples/Models/People.php @@ -4,7 +4,7 @@ namespace App\Models; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; class People extends Model { diff --git a/src/Client/DatastoreClient.php b/src/Client/DatastoreClient.php index 626e96b..63f5575 100644 --- a/src/Client/DatastoreClient.php +++ b/src/Client/DatastoreClient.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Client; +namespace AffordableMobiles\EloquentDatastore\Client; -use DomainException; use Google\Cloud\Datastore\DatastoreClient as BaseDatastoreClient; use Google\Cloud\Datastore\EntityInterface; use Google\Cloud\Datastore\Key; @@ -34,7 +33,7 @@ class DatastoreClient extends BaseDatastoreClient * * @return Key * - * @throws DomainException if a conflict occurs, fail + * @throws \DomainException if a conflict occurs, fail */ public function insert(EntityInterface $entity, array $options = []) { @@ -103,7 +102,7 @@ public function insertBatch(array $entities, array $options = []) * @param array $options [optional] { * Configuration Options * - * @var bool $allowOverwrite Entities must be updated as an entire + * @var bool $allowOverwrite Entities must be updated as an entire * resource. Patch operations are not supported. Because entities * can be created manually, or obtained by a lookup or query, it * is possible to accidentally overwrite an existing record with a @@ -111,11 +110,11 @@ public function insertBatch(array $entities, array $options = []) * safety, this flag must be set to `true` in order to update a * record when the entity provided was not obtained through a * lookup or query. **Defaults to** `false`. - * } + * } * * @return Key * - * @throws DomainException if a conflict occurs, fail + * @throws \DomainException if a conflict occurs, fail */ public function update(EntityInterface $entity, array $options = []) { @@ -146,7 +145,7 @@ public function update(EntityInterface $entity, array $options = []) * @param array $options [optional] { * Configuration Options * - * @var bool $allowOverwrite Entities must be updated as an entire + * @var bool $allowOverwrite Entities must be updated as an entire * resource. Patch operations are not supported. Because entities * can be created manually, or obtained by a lookup or query, it * is possible to accidentally overwrite an existing record with a @@ -154,7 +153,7 @@ public function update(EntityInterface $entity, array $options = []) * safety, this flag must be set to `true` in order to update a * record when the entity provided was not obtained through a * lookup or query. **Defaults to** `false`. - * } + * } * * @return Key[] */ @@ -196,7 +195,7 @@ public function updateBatch(array $entities, array $options = []) * * @return Key The entity key * - * @throws DomainException if a conflict occurs, fail + * @throws \DomainException if a conflict occurs, fail */ public function upsert(EntityInterface $entity, array $options = []) { diff --git a/src/Collection.php b/src/Collection.php index dc4670d..1072eff 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -2,11 +2,10 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore; +namespace AffordableMobiles\EloquentDatastore; use Illuminate\Support\Collection as BaseCollection; use Illuminate\Support\Facades\DB; -use LogicException; class Collection extends BaseCollection { @@ -26,9 +25,9 @@ public function hasNextItems() */ public function delete() { - $this->each(function ($item): void { + $this->each(static function ($item): void { if (empty($item->__key__)) { - throw new LogicException('Unable to create query for collection with mixed types.'); + throw new \LogicException('Unable to create query for collection with mixed types.'); } }); diff --git a/src/Concerns/BuildsQueries.php b/src/Concerns/BuildsQueries.php index e40c5bb..22fbd14 100644 --- a/src/Concerns/BuildsQueries.php +++ b/src/Concerns/BuildsQueries.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Concerns; +namespace AffordableMobiles\EloquentDatastore\Concerns; use Illuminate\Support\LazyCollection; @@ -51,7 +51,7 @@ public function chunk($count, callable $callback): bool * * @param int $chunkSize * - * @return \Illuminate\Support\LazyCollection + * @return LazyCollection * * @throws \InvalidArgumentException */ diff --git a/src/DatastoreConnection.php b/src/DatastoreConnection.php index 25f99b6..10774fe 100644 --- a/src/DatastoreConnection.php +++ b/src/DatastoreConnection.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore; +namespace AffordableMobiles\EloquentDatastore; -use A1comms\EloquentDatastore\Client\DatastoreClient; -use A1comms\EloquentDatastore\Query\Builder; -use A1comms\EloquentDatastore\Query\Grammar; -use A1comms\EloquentDatastore\Query\Processor; -use A1comms\EloquentDatastore\Query\RawExpression; +use AffordableMobiles\EloquentDatastore\Client\DatastoreClient; +use AffordableMobiles\EloquentDatastore\Query\Builder; +use AffordableMobiles\EloquentDatastore\Query\Grammar; +use AffordableMobiles\EloquentDatastore\Query\Processor; +use AffordableMobiles\EloquentDatastore\Query\RawExpression; use Illuminate\Database\Connection; use Illuminate\Support\Traits\ForwardsCalls; @@ -57,9 +57,6 @@ public function __construct($config) /** * Call datastore client methods. - * - * @param $name - * @param $arguments */ public function __call($name, $arguments): void { @@ -68,8 +65,6 @@ public function __call($name, $arguments): void /** * Make datastore client. - * - * @param $config */ public function makeClient($config): self { @@ -90,8 +85,6 @@ public function query(): Builder /** * Set the table. - * - * @param $table */ public function from($table): Builder { @@ -125,8 +118,6 @@ public function getClient(): DatastoreClient /** * Set the datastore client. * - * @param $client - * * @return $this */ public function setClient($client): self @@ -149,8 +140,6 @@ public function table($table, $as = null): Builder /** * Set the table/kind name. - * - * @param $kind */ public function kind($kind): Builder { @@ -165,9 +154,6 @@ public function raw($value): RawExpression return new RawExpression($value); } - /** - * {@inheritDoc} - */ public function disconnect(): void { $this->setClient(null); diff --git a/src/DatastoreServiceProvider.php b/src/DatastoreServiceProvider.php index 0d916ee..6a3074d 100644 --- a/src/DatastoreServiceProvider.php +++ b/src/DatastoreServiceProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore; +namespace AffordableMobiles\EloquentDatastore; use Illuminate\Support\ServiceProvider; @@ -10,8 +10,8 @@ class DatastoreServiceProvider extends ServiceProvider { public function register(): void { - $this->app->resolving('db', function ($db): void { - $db->extend('datastore', function ($config, $name) { + $this->app->resolving('db', static function ($db): void { + $db->extend('datastore', static function ($config, $name) { $config['name'] = $name; return new DatastoreConnection($config); diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 03ff270..1cae0c5 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -2,12 +2,15 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent; +namespace AffordableMobiles\EloquentDatastore\Eloquent; -use A1comms\EloquentDatastore\Concerns\BuildsQueries; -use A1comms\EloquentDatastore\Query\Builder as QueryBuilder; +use AffordableMobiles\EloquentDatastore\Concerns\BuildsQueries; +use AffordableMobiles\EloquentDatastore\Query\Builder as QueryBuilder; +use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Datastore\Key; +use Illuminate\Database\ConnectionInterface; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; class Builder extends EloquentBuilder @@ -25,7 +28,7 @@ public function __construct(QueryBuilder $query) /** * Get Datastore Connection. * - * @return \Illuminate\Database\ConnectionInterface + * @return ConnectionInterface */ public function getConnection() { @@ -35,7 +38,7 @@ public function getConnection() /** * Get Datastore client. * - * @return \Google\Cloud\Datastore\DatastoreClient + * @return DatastoreClient */ public function getClient() { @@ -66,9 +69,6 @@ public function lastCursor() return $this->query->lastCursor(); } - /** - * {@inheritdoc} - */ public function find($id, $columns = []) { $result = $this->query->cacheTags([ @@ -93,7 +93,7 @@ public function find($id, $columns = []) * @param array|\Illuminate\Contracts\Support\Arrayable $ids * @param array $columns * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function findMany($ids, $columns = ['*']) { @@ -140,7 +140,7 @@ public function lookup($key, $columns = []) /** * Get the first record matching the attributes or instantiate it. * - * @return \Illuminate\Database\Eloquent\Model|static + * @return Model|static */ public function firstOrNew(array $attributes = [], array $values = []) { @@ -154,7 +154,7 @@ public function firstOrNew(array $attributes = [], array $values = []) /** * Get the first record matching the attributes or create it. * - * @return \Illuminate\Database\Eloquent\Model|static + * @return Model|static */ public function firstOrCreate(array $attributes = [], array $values = []) { @@ -162,7 +162,7 @@ public function firstOrCreate(array $attributes = [], array $values = []) return $instance; } - return tap($this->newModelInstance(array_merge($attributes, $values)), function ($instance): void { + return tap($this->newModelInstance(array_merge($attributes, $values)), static function ($instance): void { $instance->save(); }); } diff --git a/src/Eloquent/Collection.php b/src/Eloquent/Collection.php index 657d066..071e6f0 100644 --- a/src/Eloquent/Collection.php +++ b/src/Eloquent/Collection.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent; +namespace AffordableMobiles\EloquentDatastore\Eloquent; use Illuminate\Database\Eloquent\Collection as BaseCollection; -use LogicException; class Collection extends BaseCollection { @@ -41,14 +40,14 @@ public function save() $model = $this->prepareBulkQuery(); // Prepare the models for update... - $entities = $this->map(fn ($entity) => $entity->prepareBulkUpsert())->toArray(); + $entities = $this->map(static fn ($entity) => $entity->prepareBulkUpsert())->toArray(); // Remove any empty entries (not dirty)... $rEntities = array_filter($entities); $resultKeys = $model->newQueryWithoutScopes()->_upsert( - array_map(fn ($entity) => $entity['attributes'], $rEntities), - array_map(fn ($entity) => $entity['key'], $rEntities), + array_map(static fn ($entity) => $entity['attributes'], $rEntities), + array_map(static fn ($entity) => $entity['key'], $rEntities), $model->getQueryOptions(), ); @@ -58,7 +57,7 @@ public function save() // This looks complicated as the array of records we actually upserted // in the query might not match our source collection (shorter array length), // as we're only inserting ones that are dirty. - $this->map(function ($entity, $index) use (&$empty, $entities, $resultKeys): void { + $this->map(static function ($entity, $index) use (&$empty, $entities, $resultKeys): void { $id = null; if (empty($entities[$index])) { @@ -101,14 +100,14 @@ protected function prepareBulkQuery() $model = $this->first(); if (!$model) { - throw new LogicException('Unable to create query for empty collection.'); + throw new \LogicException('Unable to create query for empty collection.'); } $class = $model::class; - $this->each(function ($item) use ($class): void { + $this->each(static function ($item) use ($class): void { if (!$item instanceof $class) { - throw new LogicException('Unable to create query for collection with mixed types.'); + throw new \LogicException('Unable to create query for collection with mixed types.'); } }); diff --git a/src/Eloquent/Concerns/FlushQueryCacheObserver.php b/src/Eloquent/Concerns/FlushQueryCacheObserver.php index a4abb7e..173d21a 100644 --- a/src/Eloquent/Concerns/FlushQueryCacheObserver.php +++ b/src/Eloquent/Concerns/FlushQueryCacheObserver.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent\Concerns; +namespace AffordableMobiles\EloquentDatastore\Eloquent\Concerns; -use Exception; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Rennokki\QueryCache\FlushQueryCacheObserver as ParentFlushQueryCacheObserver; @@ -13,10 +13,10 @@ class FlushQueryCacheObserver extends ParentFlushQueryCacheObserver /** * Invalidate the cache for a model. * - * @param null|string $relation - * @param null|\Illuminate\Database\Eloquent\Collection $pivotedModels + * @param null|string $relation + * @param null|Collection $pivotedModels * - * @throws Exception + * @throws \Exception */ protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void { @@ -25,7 +25,7 @@ protected function invalidateCache(Model $model, $relation = null, $pivotedModel $tags = $model->getCacheTagsToInvalidateOnUpdate($relation, $pivotedModels); if (!$tags) { - throw new Exception('Automatic invalidation for '.$class.' works only if at least one tag to be invalidated is specified.'); + throw new \Exception('Automatic invalidation for '.$class.' works only if at least one tag to be invalidated is specified.'); } $class::flushQueryCache($tags); diff --git a/src/Eloquent/Concerns/HasRelationships.php b/src/Eloquent/Concerns/HasRelationships.php index d099b8b..cf5d5f2 100644 --- a/src/Eloquent/Concerns/HasRelationships.php +++ b/src/Eloquent/Concerns/HasRelationships.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent\Concerns; +namespace AffordableMobiles\EloquentDatastore\Eloquent\Concerns; -use A1comms\EloquentDatastore\Relations\BelongsToAncestor; -use A1comms\EloquentDatastore\Relations\HasManyDescendants; +use AffordableMobiles\EloquentDatastore\Relations\BelongsToAncestor; +use AffordableMobiles\EloquentDatastore\Relations\HasManyDescendants; trait HasRelationships { @@ -21,8 +21,6 @@ public function hasManyDescendants(string $related): HasManyDescendants /** * Define an inverse one-to-one or many relationship. - * - * @param null|string $relation */ public function belongsToAncestor(string $related): BelongsToAncestor { diff --git a/src/Eloquent/Concerns/QueriesRelationships.php b/src/Eloquent/Concerns/QueriesRelationships.php index beee477..f7c7216 100644 --- a/src/Eloquent/Concerns/QueriesRelationships.php +++ b/src/Eloquent/Concerns/QueriesRelationships.php @@ -2,9 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent\Concerns; - -use Closure; +namespace AffordableMobiles\EloquentDatastore\Eloquent\Concerns; trait QueriesRelationships { @@ -16,7 +14,7 @@ trait QueriesRelationships * @param mixed $count * @param mixed $boolean */ - public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) + public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', ?\Closure $callback = null) { throw new \LogicException('Not Implemented'); @@ -32,7 +30,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C * @param mixed $count * @param mixed $boolean */ - public function hasMorph($relation, $types, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null) + public function hasMorph($relation, $types, $operator = '>=', $count = 1, $boolean = 'and', ?\Closure $callback = null) { throw new \LogicException('Not Implemented'); diff --git a/src/Eloquent/Concerns/QueryCacheable.php b/src/Eloquent/Concerns/QueryCacheable.php index 40e9115..fef6231 100644 --- a/src/Eloquent/Concerns/QueryCacheable.php +++ b/src/Eloquent/Concerns/QueryCacheable.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent\Concerns; +namespace AffordableMobiles\EloquentDatastore\Eloquent\Concerns; -use A1comms\EloquentDatastore\Query\Builder as QueryBuilder; +use AffordableMobiles\EloquentDatastore\Query\Builder as QueryBuilder; +use Illuminate\Database\Eloquent\Collection; use Rennokki\QueryCache\Traits\QueryCacheable as ParentQueryCacheable; trait QueryCacheable @@ -19,8 +20,8 @@ trait QueryCacheable * When invalidating automatically on update, you can specify * which tags to invalidate. * - * @param null|string $relation - * @param null|\Illuminate\Database\Eloquent\Collection $pivotedModels + * @param null|string $relation + * @param null|Collection $pivotedModels */ public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array { @@ -69,9 +70,6 @@ protected static function getFlushQueryCacheObserver() return FlushQueryCacheObserver::class; } - /** - * {@inheritdoc} - */ protected function newBaseQueryBuilder() { $connection = $this->getConnection(); diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 526070d..77ed8b2 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -2,11 +2,10 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Eloquent; +namespace AffordableMobiles\EloquentDatastore\Eloquent; -use A1comms\EloquentDatastore\Query\Builder as QueryBuilder; +use AffordableMobiles\EloquentDatastore\Query\Builder as QueryBuilder; use Carbon\CarbonInterval; -use DateTimeInterface; use Google\Cloud\Datastore\Key; use Illuminate\Database\Eloquent\Builder as BaseBuilder; use Illuminate\Database\Eloquent\Model as BaseModel; @@ -82,9 +81,6 @@ abstract class Model extends BaseModel */ protected $keyType = 'int'; - /** - * {@inheritdoc} - */ public function getKey($id = false) { if ($id) { @@ -212,7 +208,7 @@ public static function destroy($ids) * * @param mixed $value */ - public function fromDateTime($value): DateTimeInterface + public function fromDateTime($value): \DateTimeInterface { return empty($value) ? $value : $this->asDateTime($value); } @@ -285,17 +281,11 @@ public function save(array $options = []) return $saved; } - /** - * {@inheritdoc} - */ public function newEloquentBuilder($query) { return new Builder($query); } - /** - * {@inheritdoc} - */ public function newCollection(array $models = []) { return new Collection($models); @@ -617,7 +607,7 @@ protected function insertAndSetId(BaseBuilder $query, $attributes): void /** * Perform a model update operation. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param BaseBuilder $query * * @return bool */ @@ -656,9 +646,9 @@ protected function performUpsert(Builder $query) /** * Set the keys for a select query. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param BaseBuilder $query * - * @return \Illuminate\Database\Eloquent\Builder + * @return BaseBuilder */ protected function setKeysForSelectQuery($query) { diff --git a/src/Http/JsonResource.php b/src/Http/JsonResource.php index eb9efee..d7e8828 100644 --- a/src/Http/JsonResource.php +++ b/src/Http/JsonResource.php @@ -2,10 +2,8 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Http; +namespace AffordableMobiles\EloquentDatastore\Http; use Illuminate\Http\Resources\Json\JsonResource as BaseJsonResource; -class JsonResource extends BaseJsonResource -{ -} +class JsonResource extends BaseJsonResource {} diff --git a/src/Pagination/Cursor.php b/src/Pagination/Cursor.php index 1e0d4af..6ee93a8 100644 --- a/src/Pagination/Cursor.php +++ b/src/Pagination/Cursor.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Pagination; +namespace AffordableMobiles\EloquentDatastore\Pagination; use Illuminate\Contracts\Support\Arrayable; -use UnexpectedValueException; class Cursor implements Arrayable { @@ -44,7 +43,7 @@ public function __construct(array $parameters, $pointsToNextItems = true) public function parameter(string $parameterName) { if (!\array_key_exists($parameterName, $this->parameters)) { - throw new UnexpectedValueException("Unable to find parameter [{$parameterName}] in pagination item."); + throw new \UnexpectedValueException("Unable to find parameter [{$parameterName}] in pagination item."); } return $this->parameters[$parameterName]; diff --git a/src/Query/Builder.php b/src/Query/Builder.php index fe4cb9b..26922e2 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query; +namespace AffordableMobiles\EloquentDatastore\Query; -use A1comms\EloquentDatastore\Concerns\BuildsQueries; +use AffordableMobiles\EloquentDatastore\Concerns\BuildsQueries; +use Google\Cloud\Datastore\DatastoreClient; use Google\Cloud\Datastore\Key; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\Query\Builder as BaseBuilder; use Illuminate\Support\Facades\DB; -use InvalidArgumentException; use Rennokki\QueryCache\Contracts\QueryCacheModuleInterface; class Builder extends BaseBuilder implements QueryCacheModuleInterface @@ -34,10 +34,7 @@ class Builder extends BaseBuilder implements QueryCacheModuleInterface protected $ancestor = false; protected $namespaceId; - /** - * {@inheritdoc} - */ - public function __construct(ConnectionInterface $connection, Grammar $grammar = null, Processor $processor = null) + public function __construct(ConnectionInterface $connection, ?Grammar $grammar = null, ?Processor $processor = null) { $this->connection = $connection; // $this->expression = new Expression(); @@ -46,7 +43,7 @@ public function __construct(ConnectionInterface $connection, Grammar $grammar = } /** - * @return \Google\Cloud\Datastore\DatastoreClient + * @return DatastoreClient */ public function getClient() { @@ -56,14 +53,13 @@ public function getClient() /** * Add an "order by" clause to the query. * - * @param * @param string $direction * @param mixed $column */ public function orderBy($column, $direction = 'asc'): self { if (!\in_array($direction, ['asc', 'desc'], true)) { - throw new InvalidArgumentException('Order direction must be "asc" or "desc".'); + throw new \InvalidArgumentException('Order direction must be "asc" or "desc".'); } $this->orders[] = [ diff --git a/src/Query/Concerns/QueriesDatastore.php b/src/Query/Concerns/QueriesDatastore.php index c78cf37..99f6267 100644 --- a/src/Query/Concerns/QueriesDatastore.php +++ b/src/Query/Concerns/QueriesDatastore.php @@ -2,16 +2,18 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query\Concerns; +namespace AffordableMobiles\EloquentDatastore\Query\Concerns; -use A1comms\EloquentDatastore\Client\DatastoreClient; -use A1comms\EloquentDatastore\Collection; -use Closure; +use AffordableMobiles\EloquentDatastore\Client\DatastoreClient; +use AffordableMobiles\EloquentDatastore\Collection; use Google\Cloud\Core\ExponentialBackoff; use Google\Cloud\Datastore\Key; use Google\Cloud\Datastore\Query\Query; +use Illuminate\Contracts\Pagination\CursorPaginator; use Illuminate\Database\Query\Builder as BaseBuilder; +use Illuminate\Pagination\Cursor; use Illuminate\Support\Arr; +use Illuminate\Support\LazyCollection; trait QueriesDatastore { @@ -51,9 +53,6 @@ public function lookup($key, $columns = ['*']) }); } - /** - * {@inheritdoc} - */ public function get($columns = ['*']) { return $this->onceWithColumns(Arr::wrap($columns), function () { @@ -155,9 +154,6 @@ public function keysOnly() return $this->keys(); } - /** - * {@inheritdoc} - */ public function delete($key = null) { if (null === $key) { @@ -177,9 +173,6 @@ public function delete($key = null) return (new ExponentialBackoff(6, [DatastoreClient::class, 'shouldRetry']))->execute([$this->getClient(), 'deleteBatch'], [$keys]); } - /** - * {@inheritdoc} - */ public function insert(array $values, $options = []) { if (empty($this->from)) { @@ -316,12 +309,12 @@ public function _upsert(array $values, $keys, $options = []) * * This is more efficient on larger data-sets, etc. * - * @param null|int $perPage - * @param array $columns - * @param string $cursorName - * @param null|\Illuminate\Pagination\Cursor|string $cursor + * @param null|int $perPage + * @param array $columns + * @param string $cursorName + * @param null|Cursor|string $cursor * - * @return \Illuminate\Contracts\Pagination\CursorPaginator + * @return CursorPaginator */ public function cursorPaginate($perPage = 15, $columns = ['*'], $cursorName = 'cursor', $cursor = null) { @@ -331,7 +324,7 @@ public function cursorPaginate($perPage = 15, $columns = ['*'], $cursorName = 'c /** * Get a lazy collection for the given query. * - * @return \Illuminate\Support\LazyCollection + * @return LazyCollection */ public function cursor() { @@ -371,7 +364,7 @@ public function count($columns = '*') * * @return $this */ - public function whereNested(Closure $callback, $boolean = 'and') + public function whereNested(\Closure $callback, $boolean = 'and') { $callback($this); @@ -721,28 +714,28 @@ public function addNestedWhereQuery($query, $boolean = 'and') return false; } - public function whereExists(Closure $callback, $boolean = 'and', $not = false) + public function whereExists(\Closure $callback, $boolean = 'and', $not = false) { throw new \LogicException('Not Implemented'); return false; } - public function orWhereExists(Closure $callback, $not = false) + public function orWhereExists(\Closure $callback, $not = false) { throw new \LogicException('Not Implemented'); return false; } - public function whereNotExists(Closure $callback, $boolean = 'and') + public function whereNotExists(\Closure $callback, $boolean = 'and') { throw new \LogicException('Not Implemented'); return false; } - public function orWhereNotExists(Closure $callback) + public function orWhereNotExists(\Closure $callback) { throw new \LogicException('Not Implemented'); @@ -861,7 +854,7 @@ public function orHaving($column, $operator = null, $value = null) return false; } - public function havingNested(Closure $callback, $boolean = 'and') + public function havingNested(\Closure $callback, $boolean = 'and') { throw new \LogicException('Not Implemented'); @@ -987,14 +980,14 @@ public function getCountForPagination($columns = ['*']) return false; } - public function existsOr(Closure $callback) + public function existsOr(\Closure $callback) { throw new \LogicException('Not Implemented'); return false; } - public function doesntExistOr(Closure $callback) + public function doesntExistOr(\Closure $callback) { throw new \LogicException('Not Implemented'); diff --git a/src/Query/Concerns/QueryCacheModule.php b/src/Query/Concerns/QueryCacheModule.php index 6d62053..827e604 100644 --- a/src/Query/Concerns/QueryCacheModule.php +++ b/src/Query/Concerns/QueryCacheModule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query\Concerns; +namespace AffordableMobiles\EloquentDatastore\Query\Concerns; use Google\Cloud\Datastore\Key; use Illuminate\Support\Arr; @@ -21,7 +21,7 @@ trait QueryCacheModule * * @return array */ - public function getFromQueryCache(string $method = 'get', array $columns = ['*'], string|Key $id = null) + public function getFromQueryCache(string $method = 'get', array $columns = ['*'], null|Key|string $id = null) { if (null === $this->columns) { $this->columns = $columns; @@ -47,7 +47,7 @@ public function getFromQueryCache(string $method = 'get', array $columns = ['*'] * * @return \Closure */ - public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], string|Key $id = null) + public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], null|Key|string $id = null) { return function () use ($method, $columns, $id) { $this->avoidCache = true; @@ -85,7 +85,7 @@ public function recacheFindQuery(string $id, array $attributes) $key = $this->getCacheKey('find', $id); $cache = $this->getCache(); - $callback = fn () => $attributes; + $callback = static fn () => $attributes; $time = $this->getCacheFor(); @@ -99,7 +99,7 @@ public function recacheFindQuery(string $id, array $attributes) /** * Generate the plain unique cache key for the query. */ - public function generatePlainCacheKey(string $method = 'get', string $id = null, string $appends = null): string + public function generatePlainCacheKey(string $method = 'get', ?string $id = null, ?string $appends = null): string { $name = $this->connection->getName(); diff --git a/src/Query/Expression.php b/src/Query/Expression.php index e919709..3ff5240 100644 --- a/src/Query/Expression.php +++ b/src/Query/Expression.php @@ -2,8 +2,6 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query; +namespace AffordableMobiles\EloquentDatastore\Query; -class Expression extends \Illuminate\Database\Query\Expression -{ -} +class Expression extends \Illuminate\Database\Query\Expression {} diff --git a/src/Query/Grammar.php b/src/Query/Grammar.php index 8186a15..3464767 100644 --- a/src/Query/Grammar.php +++ b/src/Query/Grammar.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query; +namespace AffordableMobiles\EloquentDatastore\Query; use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar; diff --git a/src/Query/Processor.php b/src/Query/Processor.php index ae5db88..0613b1b 100644 --- a/src/Query/Processor.php +++ b/src/Query/Processor.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query; +namespace AffordableMobiles\EloquentDatastore\Query; -use A1comms\EloquentDatastore\Collection; +use AffordableMobiles\EloquentDatastore\Collection; use Google\Cloud\Datastore\Key; use Illuminate\Database\Query\Processors\Processor as BaseProcessor; @@ -13,8 +13,6 @@ class Processor extends BaseProcessor /** * Process Datastore Results. * - * @param $builder - * @param $results * @param null|mixed $excludeKey * * @return mixed diff --git a/src/Query/RawExpression.php b/src/Query/RawExpression.php index a340974..127a173 100644 --- a/src/Query/RawExpression.php +++ b/src/Query/RawExpression.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Query; +namespace AffordableMobiles\EloquentDatastore\Query; class RawExpression { diff --git a/src/Relations/BelongsToAncestor.php b/src/Relations/BelongsToAncestor.php index 8a0d10a..f7783d3 100644 --- a/src/Relations/BelongsToAncestor.php +++ b/src/Relations/BelongsToAncestor.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Relations; +namespace AffordableMobiles\EloquentDatastore\Relations; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\Relation; @@ -16,7 +16,7 @@ class BelongsToAncestor extends Relation * * @param array $columns * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function get($columns = ['*']) { @@ -119,7 +119,7 @@ public function create(array $attributes = []) /** * Create a Collection of new instances of the related model. * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function createMany(iterable $records) { @@ -208,8 +208,6 @@ public function addEagerConstraints(array $models): void /** * Get the results of the relationship. * - * @param mixed $columns - * * @return mixed */ public function getResults() diff --git a/src/Relations/HasManyDescendants.php b/src/Relations/HasManyDescendants.php index 747551c..506d1fe 100644 --- a/src/Relations/HasManyDescendants.php +++ b/src/Relations/HasManyDescendants.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace A1comms\EloquentDatastore\Relations; +namespace AffordableMobiles\EloquentDatastore\Relations; -use A1comms\EloquentDatastore\Eloquent\Model; +use AffordableMobiles\EloquentDatastore\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\Relation; @@ -67,7 +67,7 @@ public function firstOrCreate(array $attributes = [], array $values = []) */ public function updateOrCreate(array $attributes, array $values = []) { - return tap($this->firstOrNew($attributes), function ($instance) use ($values): void { + return tap($this->firstOrNew($attributes), static function ($instance) use ($values): void { $instance->fill($values); $instance->save(); @@ -140,7 +140,7 @@ public function create(array $attributes = []) /** * Create a Collection of new instances of the related model. * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function createMany(iterable $records) { @@ -170,7 +170,7 @@ public function touch(): void $modelCollection = $this->getResults(); // Touch the timestamps but don't // update anything individually... - $modelCollection->map(fn ($entity) => $entity->updateTimestamps()); + $modelCollection->map(static fn ($entity) => $entity->updateTimestamps()); // Perform a bulk upsert for better performance // on Datastore... $modelCollection->save(); @@ -266,7 +266,7 @@ public function getResults($columns = ['*']) * * @param array $columns * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function get($columns = ['*']) {