From 9cf0e3c5283ed3adb074953b904a095ac975349c Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Wed, 6 Nov 2024 19:42:34 +0900 Subject: [PATCH] feat: better phpstan support part2 (#237) --- phpstan.neon | 2 - src/Schema/ColumnDefinition.php | 41 ++++++++++++ src/Schema/Grammar.php | 75 +++++++++++----------- src/Schema/RowDeletionPolicyDefinition.php | 33 ++++++++++ 4 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 src/Schema/ColumnDefinition.php create mode 100644 src/Schema/RowDeletionPolicyDefinition.php diff --git a/phpstan.neon b/phpstan.neon index f8cd2e9..822d7bd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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.*$#' - '#^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/ColumnDefinition.php b/src/Schema/ColumnDefinition.php new file mode 100644 index 0000000..94b1fc6 --- /dev/null +++ b/src/Schema/ColumnDefinition.php @@ -0,0 +1,41 @@ + $command + * @param Fluent&object{ column: ColumnDefinition } $command * @return list|string */ public function compileAdd(Blueprint $blueprint, Fluent $command) @@ -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 $command + * @param Fluent&object{ column: ColumnDefinition } $command * @param Connection $connection * @return list|string */ @@ -155,7 +155,7 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection * Compile a drop column command. * * @param Blueprint $blueprint - * @param Fluent $command + * @param Fluent&object{ columns: list } $command * @return string[] */ public function compileDropColumn(Blueprint $blueprint, Fluent $command) @@ -168,7 +168,7 @@ public function compileDropColumn(Blueprint $blueprint, Fluent $command) /** * @param Blueprint $blueprint - * @param Fluent $command + * @param RowDeletionPolicyDefinition $command * @return string */ public function compileAddRowDeletionPolicy(Blueprint $blueprint, Fluent $command) @@ -183,7 +183,7 @@ public function compileAddRowDeletionPolicy(Blueprint $blueprint, Fluent $comman /** * @param Blueprint $blueprint - * @param Fluent $command + * @param RowDeletionPolicyDefinition $command * @return string */ public function compileReplaceRowDeletionPolicy(Blueprint $blueprint, Fluent $command) @@ -198,7 +198,7 @@ public function compileReplaceRowDeletionPolicy(Blueprint $blueprint, Fluent $co /** * @param Blueprint $blueprint - * @param Fluent $command + * @param RowDeletionPolicyDefinition $command * @return string */ public function compileDropRowDeletionPolicy(Blueprint $blueprint, Fluent $command) @@ -372,6 +372,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))'; } @@ -497,6 +498,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 ''; @@ -531,7 +533,7 @@ public function compileDropIfExists(Blueprint $blueprint, Fluent $command) /** * Create the column definition for a string type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeString(Fluent $column) @@ -542,7 +544,7 @@ protected function typeString(Fluent $column) /** * Create the column definition for a char type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeChar(Fluent $column) @@ -553,7 +555,7 @@ protected function typeChar(Fluent $column) /** * Create the column definition for a text type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeText(Fluent $column) @@ -564,7 +566,7 @@ protected function typeText(Fluent $column) /** * Create the column definition for a medium text type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeMediumText(Fluent $column) @@ -575,7 +577,7 @@ protected function typeMediumText(Fluent $column) /** * Create the column definition for a long text type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeLongText(Fluent $column) @@ -586,7 +588,7 @@ protected function typeLongText(Fluent $column) /** * Create the column definition for a json type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeJson(Fluent $column) @@ -597,7 +599,7 @@ protected function typeJson(Fluent $column) /** * Create the column definition for a binary type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeBinary(Fluent $column) @@ -608,7 +610,7 @@ protected function typeBinary(Fluent $column) /** * Create the column definition for a big integer type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeBigInteger(Fluent $column) @@ -619,7 +621,7 @@ protected function typeBigInteger(Fluent $column) /** * Create the column definition for an integer type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeInteger(Fluent $column) @@ -630,7 +632,7 @@ protected function typeInteger(Fluent $column) /** * Create the column definition for a float type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeFloat(Fluent $column) @@ -641,7 +643,7 @@ protected function typeFloat(Fluent $column) /** * Create the column definition for a double type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeDouble(Fluent $column) @@ -652,7 +654,7 @@ protected function typeDouble(Fluent $column) /** * Create the column definition for a decimal type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeDecimal(Fluent $column) @@ -663,7 +665,7 @@ protected function typeDecimal(Fluent $column) /** * Create the column definition for a date type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeDate(Fluent $column) @@ -674,7 +676,7 @@ protected function typeDate(Fluent $column) /** * Create the column definition for a date-time type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeDateTime(Fluent $column) @@ -685,7 +687,7 @@ protected function typeDateTime(Fluent $column) /** * Create the column definition for a timestamp type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeTimestamp(Fluent $column) @@ -700,7 +702,7 @@ protected function typeTimestamp(Fluent $column) /** * Create the column definition for an uuid type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeUuid(Fluent $column) @@ -712,7 +714,7 @@ protected function typeUuid(Fluent $column) * Create the column definition for a ARRAY type. * https://cloud.google.com/spanner/docs/arrays * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeArray(Fluent $column) @@ -723,7 +725,7 @@ protected function typeArray(Fluent $column) /** * Create the column definition for a boolean type. * - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function typeBoolean(Fluent $column) @@ -733,7 +735,7 @@ protected function typeBoolean(Fluent $column) /** * @param Blueprint $blueprint - * @param Fluent $column + * @param IntColumnDefinition $column * @return string|null */ protected function modifyUseSequence(Blueprint $blueprint, Fluent $column): ?string @@ -747,8 +749,8 @@ protected function modifyUseSequence(Blueprint $blueprint, Fluent $column): ?str /** * Get the SQL for a nullable column modifier. * - * @param Blueprint $blueprint - * @param Fluent $column + * @param Blueprint $blueprint + * @param ColumnDefinition $column * @return string|null */ protected function modifyNullable(Blueprint $blueprint, Fluent $column) @@ -760,11 +762,12 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column) } /** - * @param Fluent $column + * @param ColumnDefinition $column * @return string */ protected function getArrayInnerType(Fluent $column): string { + assert($column->arrayType !== null); return $this->{'type'.ucfirst($column->arrayType)}($column); } @@ -772,7 +775,7 @@ protected function getArrayInnerType(Fluent $column): string * Get the SQL for a default column modifier. * * @param Blueprint $blueprint - * @param Fluent $column + * @param ColumnDefinition $column * @return string|null */ protected function modifyDefault(Blueprint $blueprint, Fluent $column) @@ -787,7 +790,7 @@ protected function modifyDefault(Blueprint $blueprint, Fluent $column) } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param string $type * @param mixed $value * @return int|float|string @@ -813,7 +816,7 @@ protected function formatDefaultValue(Fluent $column, string $type, mixed $value } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ @@ -828,7 +831,7 @@ protected function formatArrayValue(Fluent $column, mixed $value): string } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ @@ -839,7 +842,7 @@ protected function formatBoolValue(Fluent $column, mixed $value): string } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ @@ -853,7 +856,7 @@ protected function formatDateValue(Fluent $column, mixed $value): string } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ @@ -864,7 +867,7 @@ protected function formatFloatValue(Fluent $column, mixed $value): string } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ @@ -875,7 +878,7 @@ protected function formatNumericValue(Fluent $column, mixed $value): string } /** - * @param Fluent $column + * @param ColumnDefinition $column * @param mixed $value * @return string */ diff --git a/src/Schema/RowDeletionPolicyDefinition.php b/src/Schema/RowDeletionPolicyDefinition.php new file mode 100644 index 0000000..1363d45 --- /dev/null +++ b/src/Schema/RowDeletionPolicyDefinition.php @@ -0,0 +1,33 @@ + + */ +class RowDeletionPolicyDefinition extends Fluent +{ +}