Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better phpstan support part2 #237

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.*$#'
- '#^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
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 @@ -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 */
Copy link
Collaborator Author

@taka-oyama taka-oyama Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use assert but that will break compatibility so it will be done in a later version

if ($command->policy === 'olderThan') {
return ', row deletion policy (older_than('.$command->column.', interval '.$command->days.' day))';
}
Expand Down Expand Up @@ -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 '';
Expand Down Expand Up @@ -531,7 +533,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 @@ -542,7 +544,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 @@ -553,7 +555,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 @@ -564,7 +566,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 @@ -575,7 +577,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 @@ -586,7 +588,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 @@ -597,7 +599,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 @@ -608,7 +610,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 @@ -619,7 +621,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 @@ -630,7 +632,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 @@ -641,7 +643,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 @@ -652,7 +654,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 @@ -663,7 +665,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 @@ -674,7 +676,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 @@ -685,7 +687,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 @@ -700,7 +702,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 @@ -712,7 +714,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 @@ -723,7 +725,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 @@ -733,7 +735,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 @@ -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<string, mixed> $column
* @param Blueprint $blueprint
* @param ColumnDefinition $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
Expand All @@ -760,19 +762,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 @@ -787,7 +790,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 @@ -813,7 +816,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 @@ -828,7 +831,7 @@ protected function formatArrayValue(Fluent $column, mixed $value): string
}

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

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

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

/**
* @param Fluent<string, mixed> $column
* @param ColumnDefinition $column
* @param mixed $value
* @return string
*/
Expand All @@ -875,7 +878,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
Loading