Skip to content

Commit

Permalink
feat: replace @method in traits with abstract defs (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama committed Jul 19, 2023
1 parent fe4cbcd commit 8efa875
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Added
Changed
- `Connection::waitForOperation` and `Connection::isDoneOperation` has been removed. (#99)
- Update `export-ignore` entries in `.gitattributes` (#104)
- Use abstract definitions on traits instead of relying on `@methods` `@property`. (#120)
- Stop using `call_user_func` (#121)

Fixed
Expand Down
4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ parameters:
path: src/Connection.php
- message: '#^Parameter \#1 \$start of method Illuminate\\Database\\Connection::getElapsedTime\(\) expects int, float given\.$#'
path: src/Connection.php
- message: '#^Parameter \#1 \$start of method Illuminate\\Database\\Connection::getElapsedTime\(\) expects int, float given\.$#'
path: src/Connection.php
count: 1
count: 2
- message: "#^Parameter \\#1 \\$table of method Illuminate\\\\Database\\\\Query\\\\Builder\\:\\:from\\(\\) expects Closure\\|Illuminate\\\\Database\\\\Eloquent\\\\Builder\\|Illuminate\\\\Database\\\\Query\\\\Builder\\|string, Closure\\|Illuminate\\\\Contracts\\\\Database\\\\Query\\\\Expression\\|Illuminate\\\\Database\\\\Query\\\\Builder\\|string given\\.$#"
path: src/Connection.php
- message: '#^Method Colopl\\Spanner\\Connection::select\(\) should return array but returns mixed\.$#'
Expand Down
8 changes: 5 additions & 3 deletions src/Concerns/ManagesDataDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
use function json_encode;
use function trigger_deprecation;

/**
* @method Database getSpannerDatabase()
*/
trait ManagesDataDefinitions
{
/**
* @return Database
*/
abstract public function getSpannerDatabase(): Database;

/**
* @deprecated use runDdlBatch() instead
* @param string $ddl
Expand Down
8 changes: 5 additions & 3 deletions src/Concerns/ManagesMutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
use Illuminate\Database\Events\TransactionCommitted;
use Illuminate\Support\Arr;

/**
* @method Database|Transaction getDatabaseContext()
*/
trait ManagesMutations
{
/**
* @return Database|Transaction
*/
abstract protected function getDatabaseContext(): Database|Transaction;

/**
* @param string $table
* @param array $dataSet
Expand Down
10 changes: 6 additions & 4 deletions src/Concerns/ManagesPartitionedDml.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

use Google\Cloud\Spanner\Database;

/**
* @method Database getSpannerDatabase()
*/
trait ManagesPartitionedDml
{
/**
* @return Database
*/
abstract public function getSpannerDatabase(): Database;

/**
* Run an SQL statement as partitioned DML and get the number of rows affected.
*
* @param string $query
* @param array<mixed> $bindings
* @param array<array-key, mixed> $bindings
* @return int
*/
public function runPartitionedDml($query, $bindings = [])
Expand Down
9 changes: 5 additions & 4 deletions src/Concerns/ManagesSessionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
use ReflectionException;
use ReflectionObject;

/**
* @property Database|null $spannerDatabase
* @method Database getSpannerDatabase()
*/
trait ManagesSessionPool
{
use EmulatorTrait;

/**
* @return Database
*/
abstract public function getSpannerDatabase(): Database;

/**
* @return void
*/
Expand Down
13 changes: 6 additions & 7 deletions src/Concerns/ManagesStaleReads.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

use Colopl\Spanner\TimestampBound\TimestampBoundInterface;
use Generator;
use Throwable;

trait ManagesStaleReads
{
/**
* @param string $query
* @param array<string, mixed> $bindings
* @param array<array-key, mixed> $bindings
* @param TimestampBoundInterface|null $timestampBound
* @return Generator<int, list<mixed>|null>
*/
Expand All @@ -48,10 +47,10 @@ public function cursorWithTimestampBound($query, $bindings = [], TimestampBoundI
}

/**
* @param string $query
* @param array $bindings
* @param string $query
* @param array<array-key, mixed> $bindings
* @param TimestampBoundInterface|null $timestampBound
* @return array
* @return list<array<array-key, mixed>|null>
*/
public function selectWithTimestampBound($query, $bindings = [], TimestampBoundInterface $timestampBound = null): array
{
Expand All @@ -62,9 +61,9 @@ public function selectWithTimestampBound($query, $bindings = [], TimestampBoundI

/**
* @param string $query
* @param array<mixed> $bindings
* @param array<array-key, mixed> $bindings
* @param TimestampBoundInterface|null $timestampBound
* @return array<mixed>|null
* @return array<array-key, mixed>|null
*/
public function selectOneWithTimestampBound($query, $bindings = [], TimestampBoundInterface $timestampBound = null): ?array
{
Expand Down
1 change: 0 additions & 1 deletion src/Concerns/ManagesTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Closure;
use Exception;
use Google\Cloud\Core\Exception\AbortedException;
use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Spanner\Database;
use Google\Cloud\Spanner\Transaction;
use Throwable;
Expand Down

0 comments on commit 8efa875

Please sign in to comment.