diff --git a/CHANGELOG.md b/CHANGELOG.md index 7450d468..1051b7df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/phpstan.neon b/phpstan.neon index 25bf19cb..859061c2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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\.$#' diff --git a/src/Concerns/ManagesDataDefinitions.php b/src/Concerns/ManagesDataDefinitions.php index 6fed2f5b..9dcca986 100644 --- a/src/Concerns/ManagesDataDefinitions.php +++ b/src/Concerns/ManagesDataDefinitions.php @@ -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 diff --git a/src/Concerns/ManagesMutations.php b/src/Concerns/ManagesMutations.php index 5e96c714..3fdf008a 100644 --- a/src/Concerns/ManagesMutations.php +++ b/src/Concerns/ManagesMutations.php @@ -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 diff --git a/src/Concerns/ManagesPartitionedDml.php b/src/Concerns/ManagesPartitionedDml.php index f69c72f8..271c7d58 100644 --- a/src/Concerns/ManagesPartitionedDml.php +++ b/src/Concerns/ManagesPartitionedDml.php @@ -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 $bindings + * @param array $bindings * @return int */ public function runPartitionedDml($query, $bindings = []) diff --git a/src/Concerns/ManagesSessionPool.php b/src/Concerns/ManagesSessionPool.php index 3474c0d9..7101370a 100644 --- a/src/Concerns/ManagesSessionPool.php +++ b/src/Concerns/ManagesSessionPool.php @@ -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 */ diff --git a/src/Concerns/ManagesStaleReads.php b/src/Concerns/ManagesStaleReads.php index 29fac4de..ef116d68 100644 --- a/src/Concerns/ManagesStaleReads.php +++ b/src/Concerns/ManagesStaleReads.php @@ -19,13 +19,12 @@ use Colopl\Spanner\TimestampBound\TimestampBoundInterface; use Generator; -use Throwable; trait ManagesStaleReads { /** * @param string $query - * @param array $bindings + * @param array $bindings * @param TimestampBoundInterface|null $timestampBound * @return Generator|null> */ @@ -48,10 +47,10 @@ public function cursorWithTimestampBound($query, $bindings = [], TimestampBoundI } /** - * @param string $query - * @param array $bindings + * @param string $query + * @param array $bindings * @param TimestampBoundInterface|null $timestampBound - * @return array + * @return list|null> */ public function selectWithTimestampBound($query, $bindings = [], TimestampBoundInterface $timestampBound = null): array { @@ -62,9 +61,9 @@ public function selectWithTimestampBound($query, $bindings = [], TimestampBoundI /** * @param string $query - * @param array $bindings + * @param array $bindings * @param TimestampBoundInterface|null $timestampBound - * @return array|null + * @return array|null */ public function selectOneWithTimestampBound($query, $bindings = [], TimestampBoundInterface $timestampBound = null): ?array { diff --git a/src/Concerns/ManagesTransactions.php b/src/Concerns/ManagesTransactions.php index f588f7d3..658d9c62 100644 --- a/src/Concerns/ManagesTransactions.php +++ b/src/Concerns/ManagesTransactions.php @@ -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;