Skip to content

Commit

Permalink
Merge branch 'feature/phpstan-support-part1' into feature/phpstan-sup…
Browse files Browse the repository at this point in the history
…port-part2
  • Loading branch information
taka-oyama authored Nov 5, 2024
2 parents e2c93f8 + 7f25ab0 commit e9da42e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ parameters:
- src
ignoreErrors:
- identifier: missingType.iterableValue
- '#^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
Expand Down
25 changes: 10 additions & 15 deletions src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -403,27 +404,21 @@ 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',
empty($command->indexType) ? '' : trim($command->indexType).' ',
empty($command->nullFiltered) ? '' :'null_filtered ',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$columnsAsString,
implode(', ', $columns),
$this->addStoringToIndex($command),
$this->addInterleaveToIndex($command)
);
Expand Down Expand Up @@ -458,7 +453,7 @@ protected function addStoringToIndex(Fluent $indexCommand): string

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param IndexDefinition $command
* @return string
* @see https://cloud.google.com/spanner/docs/data-definition-language?hl=en
*/
Expand All @@ -471,7 +466,7 @@ public function compileDropIndex(Blueprint $blueprint, Fluent $command)

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param IndexDefinition $command
* @return string
* @see https://cloud.google.com/spanner/docs/data-definition-language?hl=en
*/
Expand All @@ -484,7 +479,7 @@ public function compileDropUnique(Blueprint $blueprint, Fluent $command)
* Compile a drop foreign key command.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param IndexDefinition $command
* @return string
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
Expand Down
6 changes: 6 additions & 0 deletions src/Schema/IndexDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
use LogicException;

/**
* @property string $indexType
* @property string $index
* @property list<string>|array<string, string> $columns
* @property string|null $interleaveIn
* @property string|null $nullFiltered
* @property list<string>|null $storing
* @method $this interleaveIn(string $table)
* @method $this nullFiltered()
* @method $this storing(string[] $columns)
Expand Down
2 changes: 2 additions & 0 deletions src/Schema/InterleaveDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed>
*/
Expand Down

0 comments on commit e9da42e

Please sign in to comment.