From 7f25ab0f443a7525c819b9856917fc5d7657f53c Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Tue, 5 Nov 2024 17:59:01 +0900 Subject: [PATCH] feat: better phpstan support part 1 --- phpstan.neon | 1 - src/Schema/Grammar.php | 25 ++++++++++--------------- src/Schema/IndexDefinition.php | 6 ++++++ src/Schema/InterleaveDefinition.php | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 063a0d2..f8cd2e9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,6 @@ parameters: - identifier: missingType.iterableValue - '#^Access to an undefined property Illuminate\\Support\\Fluent.*$#' - '#^Call to an undefined method Illuminate\\Support\\Fluent.*$#' - - '#^Access to an undefined property Colopl\\Spanner\\Schema\\IndexDefinition.*$#' - '#^Return type \(void\) of method .*? should be compatible with return type \(.*?\) of method .*?$#' - message: '#^Method Colopl\\Spanner\\Connection::runPartitionedDml\(\) should return int but returns mixed\.$#' path: src/Concerns/ManagesPartitionedDml.php diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 86c7949..065aca8 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -354,6 +354,7 @@ protected function formatChangeStreamOptions(ChangeStreamDefinition $definition) protected function addInterleaveToTable(Blueprint $blueprint) { if (! is_null($command = $this->getCommandByName($blueprint, 'interleaveInParent'))) { + assert($command instanceof InterleaveDefinition); $schema = ", interleave in parent {$this->wrap($command->table)}"; if (! is_null($command->onDelete)) { $schema .= " on delete {$command->onDelete}"; @@ -402,19 +403,13 @@ public function compileUnique(Blueprint $blueprint, Fluent $command) */ public function compileIndex(Blueprint $blueprint, Fluent $command) { - $columnsAsString = null; - // if index is defined as assoc array, key is treated as column name and value as order // if index is defined as numeric array, then values are read as column names - $keys = array_keys($command->columns); - if (array_keys($keys) !== $keys) { - $columns = []; - foreach ($command->columns as $column => $order) { - $columns[] = $this->wrap($column).' '.$order; - } - $columnsAsString = implode(', ', $columns); - } else { - $columnsAsString = $this->columnize($command->columns); + $columns = []; + foreach ($command->columns as $column => $order) { + $columns[] = is_string($column) + ? $this->wrap($column) . ' ' . $order + : $this->wrap($order); } return sprintf('create %s%sindex %s on %s (%s)%s%s', @@ -422,7 +417,7 @@ public function compileIndex(Blueprint $blueprint, Fluent $command) empty($command->nullFiltered) ? '' :'null_filtered ', $this->wrap($command->index), $this->wrapTable($blueprint), - $columnsAsString, + implode(', ', $columns), $this->addStoringToIndex($command), $this->addInterleaveToIndex($command) ); @@ -457,7 +452,7 @@ protected function addStoringToIndex(Fluent $indexCommand): string /** * @param Blueprint $blueprint - * @param Fluent $command + * @param IndexDefinition $command * @return string * @see https://cloud.google.com/spanner/docs/data-definition-language?hl=en */ @@ -470,7 +465,7 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command) /** * @param Blueprint $blueprint - * @param Fluent $command + * @param IndexDefinition $command * @return string * @see https://cloud.google.com/spanner/docs/data-definition-language?hl=en */ @@ -483,7 +478,7 @@ public function compileDropUnique(Blueprint $blueprint, Fluent $command) * Compile a drop foreign key command. * * @param Blueprint $blueprint - * @param Fluent $command + * @param IndexDefinition $command * @return string */ public function compileDropForeign(Blueprint $blueprint, Fluent $command) diff --git a/src/Schema/IndexDefinition.php b/src/Schema/IndexDefinition.php index 09b2f8a..cdc3a72 100755 --- a/src/Schema/IndexDefinition.php +++ b/src/Schema/IndexDefinition.php @@ -22,6 +22,12 @@ use LogicException; /** + * @property string $indexType + * @property string $index + * @property list|array $columns + * @property string|null $interleaveIn + * @property string|null $nullFiltered + * @property list|null $storing * @method $this interleaveIn(string $table) * @method $this nullFiltered() * @method $this storing(string[] $columns) diff --git a/src/Schema/InterleaveDefinition.php b/src/Schema/InterleaveDefinition.php index dd0ecff..d7ddfae 100755 --- a/src/Schema/InterleaveDefinition.php +++ b/src/Schema/InterleaveDefinition.php @@ -21,6 +21,8 @@ use Illuminate\Support\Fluent; /** + * @property string $table + * @property string|null $onDelete * @method $this onDelete(string $action) Add an ON DELETE action * @extends Fluent */