Skip to content

Commit

Permalink
feat: better phpstan support part2
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama committed Nov 5, 2024
1 parent 04fb5bc commit e2c93f8
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 38 deletions.
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ parameters:
- src
ignoreErrors:
- 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\.$#'
Expand Down
41 changes: 41 additions & 0 deletions src/Schema/ColumnDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* Copyright 2019 Colopl Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace Colopl\Spanner\Schema;

use Illuminate\Database\Schema\ColumnDefinition as BaseColumnDefinition;

/**
* @property string $name
* @property string $type
* @property string|null $arrayType
* @property bool|null $nullable
* @property bool|null $invisible
* @property mixed $default
* @property int|null $length
* @property int|null $precision
* @property int|null $scale
* @property bool|null $useCurrent
* @property string|null $virtualAs
* @property bool|null $storedAs
*/
class ColumnDefinition extends BaseColumnDefinition
{
}
75 changes: 39 additions & 36 deletions src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function compileCreate(Blueprint $blueprint, Fluent $command)
* Compile an add column command.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param Fluent<string, mixed>&object{ column: ColumnDefinition } $command
* @return list<string>|string
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
Expand All @@ -134,7 +134,7 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
* Compile a change column command into a series of SQL statements.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param Fluent<string, mixed>&object{ column: ColumnDefinition } $command
* @param Connection $connection
* @return list<string>|string
*/
Expand All @@ -155,7 +155,7 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection
* Compile a drop column command.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param Fluent<string, mixed>&object{ columns: list<string> } $command
* @return string[]
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
Expand All @@ -168,7 +168,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command)

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param RowDeletionPolicyDefinition $command
* @return string
*/
public function compileAddRowDeletionPolicy(Blueprint $blueprint, Fluent $command)
Expand All @@ -183,7 +183,7 @@ public function compileAddRowDeletionPolicy(Blueprint $blueprint, Fluent $comman

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param RowDeletionPolicyDefinition $command
* @return string
*/
public function compileReplaceRowDeletionPolicy(Blueprint $blueprint, Fluent $command)
Expand All @@ -198,7 +198,7 @@ public function compileReplaceRowDeletionPolicy(Blueprint $blueprint, Fluent $co

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $command
* @param RowDeletionPolicyDefinition $command
* @return string
*/
public function compileDropRowDeletionPolicy(Blueprint $blueprint, Fluent $command)
Expand Down Expand Up @@ -371,6 +371,7 @@ protected function addInterleaveToTable(Blueprint $blueprint)
protected function addRowDeletionPolicy(Blueprint $blueprint)
{
if (! is_null($command = $this->getCommandByName($blueprint, 'rowDeletionPolicy'))) {
/** @var RowDeletionPolicyDefinition $command */
if ($command->policy === 'olderThan') {
return ', row deletion policy (older_than('.$command->column.', interval '.$command->days.' day))';
}
Expand Down Expand Up @@ -502,6 +503,7 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command)
protected function addPrimaryKeys(Blueprint $blueprint)
{
if (! is_null($primary = $this->getCommandByName($blueprint, 'primary'))) {
/** @var IndexDefinition $primary */
return "primary key ({$this->columnize($primary->columns)})";
}
return '';
Expand Down Expand Up @@ -536,7 +538,7 @@ public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
/**
* Create the column definition for a string type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeString(Fluent $column)
Expand All @@ -547,7 +549,7 @@ protected function typeString(Fluent $column)
/**
* Create the column definition for a char type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeChar(Fluent $column)
Expand All @@ -558,7 +560,7 @@ protected function typeChar(Fluent $column)
/**
* Create the column definition for a text type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeText(Fluent $column)
Expand All @@ -569,7 +571,7 @@ protected function typeText(Fluent $column)
/**
* Create the column definition for a medium text type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeMediumText(Fluent $column)
Expand All @@ -580,7 +582,7 @@ protected function typeMediumText(Fluent $column)
/**
* Create the column definition for a long text type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeLongText(Fluent $column)
Expand All @@ -591,7 +593,7 @@ protected function typeLongText(Fluent $column)
/**
* Create the column definition for a json type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeJson(Fluent $column)
Expand All @@ -602,7 +604,7 @@ protected function typeJson(Fluent $column)
/**
* Create the column definition for a binary type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeBinary(Fluent $column)
Expand All @@ -613,7 +615,7 @@ protected function typeBinary(Fluent $column)
/**
* Create the column definition for a big integer type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeBigInteger(Fluent $column)
Expand All @@ -624,7 +626,7 @@ protected function typeBigInteger(Fluent $column)
/**
* Create the column definition for an integer type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeInteger(Fluent $column)
Expand All @@ -635,7 +637,7 @@ protected function typeInteger(Fluent $column)
/**
* Create the column definition for a float type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeFloat(Fluent $column)
Expand All @@ -646,7 +648,7 @@ protected function typeFloat(Fluent $column)
/**
* Create the column definition for a double type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeDouble(Fluent $column)
Expand All @@ -657,7 +659,7 @@ protected function typeDouble(Fluent $column)
/**
* Create the column definition for a decimal type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeDecimal(Fluent $column)
Expand All @@ -668,7 +670,7 @@ protected function typeDecimal(Fluent $column)
/**
* Create the column definition for a date type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeDate(Fluent $column)
Expand All @@ -679,7 +681,7 @@ protected function typeDate(Fluent $column)
/**
* Create the column definition for a date-time type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeDateTime(Fluent $column)
Expand All @@ -690,7 +692,7 @@ protected function typeDateTime(Fluent $column)
/**
* Create the column definition for a timestamp type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeTimestamp(Fluent $column)
Expand All @@ -705,7 +707,7 @@ protected function typeTimestamp(Fluent $column)
/**
* Create the column definition for an uuid type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeUuid(Fluent $column)
Expand All @@ -717,7 +719,7 @@ protected function typeUuid(Fluent $column)
* Create the column definition for a ARRAY<T> type.
* https://cloud.google.com/spanner/docs/arrays
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeArray(Fluent $column)
Expand All @@ -728,7 +730,7 @@ protected function typeArray(Fluent $column)
/**
* Create the column definition for a boolean type.
*
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function typeBoolean(Fluent $column)
Expand All @@ -738,7 +740,7 @@ protected function typeBoolean(Fluent $column)

/**
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $column
* @param IntColumnDefinition $column
* @return string|null
*/
protected function modifyUseSequence(Blueprint $blueprint, Fluent $column): ?string
Expand All @@ -752,8 +754,8 @@ protected function modifyUseSequence(Blueprint $blueprint, Fluent $column): ?str
/**
* Get the SQL for a nullable column modifier.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $column
* @param Blueprint $blueprint
* @param ColumnDefinition $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
Expand All @@ -765,19 +767,20 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string
*/
protected function getArrayInnerType(Fluent $column): string
{
assert($column->arrayType !== null);
return $this->{'type'.ucfirst($column->arrayType)}($column);
}

/**
* Get the SQL for a default column modifier.
*
* @param Blueprint $blueprint
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @return string|null
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
Expand All @@ -792,7 +795,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column)
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param string $type
* @param mixed $value
* @return int|float|string
Expand All @@ -818,7 +821,7 @@ protected function formatDefaultValue(Fluent $column, string $type, mixed $value
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -833,7 +836,7 @@ protected function formatArrayValue(Fluent $column, mixed $value): string
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -844,7 +847,7 @@ protected function formatBoolValue(Fluent $column, mixed $value): string
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -858,7 +861,7 @@ protected function formatDateValue(Fluent $column, mixed $value): string
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -869,7 +872,7 @@ protected function formatFloatValue(Fluent $column, mixed $value): string
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -880,7 +883,7 @@ protected function formatNumericValue(Fluent $column, mixed $value): string
}

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand Down
Loading

0 comments on commit e2c93f8

Please sign in to comment.