Skip to content

Commit

Permalink
update phpstan version
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrnik committed Feb 12, 2023
1 parent aa9ba11 commit cac2c63
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 141 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"require-dev": {
"tracy/tracy": "^2",
"phpunit/phpunit": "^9",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.3.4",
"nette/neon": "^3",
"brick/date-time": "^0.3",
"zrnik/phpunit-exceptions": "^0.0.5"
Expand Down
47 changes: 22 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/Accounts/Updater/AccountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ public function getAccountById(int $id): ?Account
{
$statement = $this->pdo->prepare('SELECT * FROM account WHERE id = :id');
$statement->execute(['id' => $id]);

$result = $statement->fetch(PDO::FETCH_ASSOC);

if ($result === false) {
return null;
}

return Account::fromArray(iterator_to_array($result));
}

Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ parameters:
# checkExplicitmixed: true
paths:
- src
- tests
- examples

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
Expand Down
20 changes: 10 additions & 10 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ public function getNotNull(): bool

//region Default Value
/**
* @var mixed|null
* @var float|bool|int|string|null
*/
private mixed $default = null;
private float|bool|int|string|null $default = null;

/**
* Allowed types of default values.
Expand All @@ -180,11 +180,11 @@ public function getNotNull(): bool

/**
* Set or unset (with null) default value of column.
* @param mixed|null $defaultValue
* @param float|bool|int|string|null $defaultValue
* @return $this
* @throws InvalidArgumentException
*/
public function setDefault(mixed $defaultValue = null): Column
public function setDefault(float|bool|int|string $defaultValue = null): Column
{
$type = gettype($defaultValue);

Expand All @@ -209,25 +209,25 @@ public function setDefault(mixed $defaultValue = null): Column
/**
* Gets a default value.
*
* @return mixed
* @return scalar|null
*/
public function getDefault(): mixed
public function getDefault(): float|bool|int|string|null
{
return $this->default ?? null;
}
//endregion

//region Column Comment
/**
* @var string|null
* @var float|bool|int|string|null
*/
private ?string $comment = null;
private float|bool|int|string|null $comment = null;

/**
* Returns string that was set as a comment.
* @return string|null
* @return float|bool|int|string|null
*/
public function getComment(): ?string
public function getComment(): float|bool|int|string|null
{
return $this->comment;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Queries/Makers/IQueryMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@ public static function removeForeignKey(Table $table, Column $column, string $Fo
public static function compareType(string $type1, string $type2): bool;

/**
* @param string|null $comment1
* @param string|null $comment2
* @param float|bool|int|string|null $comment1
* @param float|bool|int|string|null $comment2
* @return bool
*/
public static function compareComment(?string $comment1, ?string $comment2): bool;
public static function compareComment(
float|bool|int|string|null $comment1,
float|bool|int|string|null $comment2
): bool;

//endregion
}
52 changes: 32 additions & 20 deletions src/Queries/Makers/QueryMakerMySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static function describeTable(PDO $pdo, Table $table): ?TableDescription
$QueryInfo->isExecuted = true;
$Statement->execute();

/**
* @var string $result
* @phpstan-ignore-next-line => there is 'Create Table', trust me :)
*/
$result = $Statement->fetch(PDO::FETCH_ASSOC)['Create Table'];
$QueryInfo->isSuccess = true;

Expand Down Expand Up @@ -325,22 +329,24 @@ public static function createUniqueIndexQuery(Table $table, Column $column, ?Tab
* @param string $uniqueIndex
* @param TableDescription|null $oldTableDescription
* @param ColumnDescription|null $columnDescription
* @return array<mixed>|null
* @return array<Query>|null
* @throws InvalidArgumentException
*/
public static function removeUniqueIndexQuery(Table $table, Column $column, string $uniqueIndex, ?TableDescription $oldTableDescription, ?ColumnDescription $columnDescription): ?array
{
//Remove Foreign Keys and then add them back after the index was removed!
$Queries = [];

foreach ($columnDescription?->foreignKeys as $foreignKeyName) {
$DropQueries = static::removeForeignKey($table, $column, $foreignKeyName, $oldTableDescription, $columnDescription);
foreach ($DropQueries as $DropQuery) {
$DropQuery->setReason("Invoked by 'removeUniqueIndexQuery[" . $uniqueIndex . "]'" . PHP_EOL . $DropQuery->getReason());
}
if($columnDescription !== null) {
foreach ($columnDescription->foreignKeys as $foreignKeyName) {
$DropQueries = static::removeForeignKey($table, $column, $foreignKeyName, $oldTableDescription, $columnDescription);
foreach ($DropQueries as $DropQuery) {
$DropQuery->setReason("Invoked by 'removeUniqueIndexQuery[" . $uniqueIndex . "]'" . PHP_EOL . $DropQuery->getReason());
}

foreach ($DropQueries as $dropQuery) {
$Queries[] = $dropQuery;
foreach ($DropQueries as $dropQuery) {
$Queries[] = $dropQuery;
}
}
}

Expand All @@ -349,17 +355,19 @@ public static function removeUniqueIndexQuery(Table $table, Column $column, stri
->setReason("There is unexpected unique index '" . $uniqueIndex . "' on '"
. $table->getName() . '.' . $column->getName() . "'.");

foreach ($columnDescription?->foreignKeys as $foreignKeyTarget => $foreignKeyName) {
$CreateQueries = static::createForeignKey($table, $column, $foreignKeyTarget, $oldTableDescription, $columnDescription);
if($columnDescription !== null) {
foreach ($columnDescription->foreignKeys as $foreignKeyTarget => $foreignKeyName) {
$CreateQueries = static::createForeignKey($table, $column, $foreignKeyTarget, $oldTableDescription, $columnDescription);

foreach ($CreateQueries as $CreateQuery) {
$CreateQuery->setReason("Invoked by 'removeUniqueIndexQuery[" . $uniqueIndex . "]'" . PHP_EOL . $CreateQuery->getReason());
}
foreach ($CreateQueries as $CreateQuery) {
$CreateQuery->setReason("Invoked by 'removeUniqueIndexQuery[" . $uniqueIndex . "]'" . PHP_EOL . $CreateQuery->getReason());
}

foreach ($CreateQueries as $query) {
$Queries[] = $query;
}
foreach ($CreateQueries as $query) {
$Queries[] = $query;
}

}
}

return $Queries;
Expand Down Expand Up @@ -435,12 +443,16 @@ public static function compareType(string $type1, string $type2): bool
}

/**
* @param string|null $comment1
* @param string|null $comment2
* @param float|bool|int|string|null $comment1
* @param float|bool|int|string|null $comment2
* @return bool
*/
public static function compareComment(?string $comment1, ?string $comment2): bool
public static function compareComment(
float|bool|int|string|null $comment1,
float|bool|int|string|null $comment2
): bool
{
return $comment1 === $comment2;
// '==' intended
return $comment1 == $comment2;
}
}
24 changes: 15 additions & 9 deletions src/Queries/Makers/QueryMakerSQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static function describeTable(PDO $pdo, Table $table): ?TableDescription
$QueryInfo->isExecuted = true;
$Statement->execute();

/** @var array<array<bool|float|int|string|null>>|false $SQLiteTableData */
$SQLiteTableData = $Statement->fetchAll(PDO::FETCH_ASSOC);
$QueryInfo->isSuccess = true;

Expand Down Expand Up @@ -94,7 +95,7 @@ public static function describeTable(PDO $pdo, Table $table): ?TableDescription
$sql = str_replace(
["\r", "\n", 'CREATE TABLE "' . $table->getName() . '"'],
[' ', ' ', 'CREATE TABLE ' . $table->getName()],
$PartRow['sql']
(string)$PartRow['sql']
);

while (Strings::contains($sql, ' ')) {
Expand Down Expand Up @@ -321,10 +322,12 @@ public static function alterTableColumnQuery(

$keyInBothArrays = [$table->getPrimaryKeyName()];
foreach ($MoveColumns as $columnName) {
foreach ($oldTableDescription?->columns as $subColumnDescription) {
if ($subColumnDescription->column->getName() === $columnName) {
$keyInBothArrays[] = $columnName;
break;
if($oldTableDescription !== null) {
foreach ($oldTableDescription->columns as $subColumnDescription) {
if ($subColumnDescription->column->getName() === $columnName) {
$keyInBothArrays[] = $columnName;
break;
}
}
}
}
Expand Down Expand Up @@ -581,13 +584,16 @@ public static function compareType(string $type1, string $type2): bool
}

/**
* @param string|null $comment1
* @param string|null $comment2
* @param float|bool|int|string|null $comment1
* @param float|bool|int|string|null $comment2
* @return bool
*/
public static function compareComment(?string $comment1, ?string $comment2): bool
public static function compareComment(
float|bool|int|string|null $comment1,
float|bool|int|string|null $comment2,
): bool
{
//Comments not supported by SQLite, just report that its correct anyhow
//Comments not supported by SQLite, just report that its correct
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Queries/Tables/ColumnDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ColumnDescription
public bool $notNull = false;

/**
* @var string|null
* @var float|bool|int|string|null
*/
public ?string $comment = null;
public float|bool|int|string|null $comment = null;

/**
* @var string|null
Expand Down
Loading

0 comments on commit cac2c63

Please sign in to comment.