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

enable phpstan/phpstan-deprecation-rules #544

Merged
merged 3 commits into from
Feb 26, 2023
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dibi/dibi": "^4.2",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
Expand Down
196 changes: 193 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,155 @@ parameters:
count: 1
path: src/DbSchema/SchemaHasherMysql.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/DoctrineReflection/DoctrineReflection.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/DoctrineReflection/DoctrineReflection.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Result not found\\.$#"
count: 1
path: src/DoctrineReflection/DoctrineResultObjectType.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Statement not found\\.$#"
count: 1
path: src/DoctrineReflection/DoctrineStatementObjectType.php

-
message: """
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
use resolveQueryStrings\\(\\) instead$#
"""
count: 1
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 2
path: src/Extensions/DibiConnectionFetchDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
count: 1
path: src/Extensions/DoctrineConnectionExecuteQueryDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
count: 1
path: src/Extensions/DoctrineConnectionFetchDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
count: 1
path: src/Extensions/DoctrineConnectionPrepareDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
count: 1
path: src/Extensions/DoctrineConnectionQueryDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Result not found\\.$#"
count: 1
path: src/Extensions/DoctrineResultDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/Extensions/DoctrineResultDynamicReturnTypeExtension.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Statement not found\\.$#"
count: 1
path: src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/Extensions/PdoStatementColumnCountDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php

-
message: "#^Strict comparison using \\!\\=\\= between null and PHPStan\\\\Type\\\\Type will always evaluate to true\\.$#"
count: 1
path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/Extensions/PdoStatementFetchObjectDynamicReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/PdoReflection/PdoStatementObjectType.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/PdoReflection/PdoStatementObjectType.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/PdoReflection/PdoStatementReflection.php

-
message: "#^Strict comparison using \\=\\=\\= between 'dibi' and 'dibi' will always evaluate to true\\.$#"
count: 1
path: src/QueryReflection/DbaApi.php

-
message: "#^Return type \\(array\\<int, array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should be covariant with return type \\(array\\<int, array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: 0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\|2147483648\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\BasePdoQueryReflector\\:\\:simulateQuery\\(\\)$#"
message: """
#^Call to deprecated method getConstantArrays\\(\\) of class PHPStan\\\\Type\\\\TypeUtils\\:
Use PHPStan\\\\Type\\\\Type\\:\\:getConstantArrays\\(\\) instead and handle optional keys if necessary\\.$#
"""
count: 1
path: src/QueryReflection/QueryReflection.php

-
message: """
#^Call to deprecated method getConstantStrings\\(\\) of class PHPStan\\\\Type\\\\TypeUtils\\:
Use PHPStan\\\\Type\\\\Type\\:\\:getConstantStrings\\(\\) instead$#
"""
count: 1
path: src/QueryReflection/PdoPgSqlQueryReflector.php
path: src/QueryReflection/QueryReflection.php

-
message: """
#^Call to deprecated method resolvePreparedQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
use resolvePreparedQueryStrings\\(\\) instead$#
"""
count: 1
path: src/QueryReflection/QueryReflection.php

-
message: "#^Casting to \\*NEVER\\* something that's already \\*NEVER\\*\\.$#"
count: 1
path: src/QueryReflection/QueryReflection.php

-
message: "#^Instanceof between PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType and PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType will always evaluate to true\\.$#"
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 3
path: src/QueryReflection/QueryReflection.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/QueryReflection/QueryReflection.php

Expand All @@ -45,6 +172,69 @@ parameters:
count: 1
path: src/QueryReflection/QueryReflection.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Accessory\\\\AccessoryType is error\\-prone and deprecated\\. Use methods on PHPStan\\\\Type\\\\Type instead\\.$#"
count: 1
path: src/QueryReflection/QuerySimulation.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ArrayType is error\\-prone and deprecated\\. Use Type\\:\\:isArray\\(\\) or Type\\:\\:getArrays\\(\\) instead\\.$#"
count: 1
path: src/QueryReflection/QuerySimulation.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
count: 1
path: src/QueryReflection/QuerySimulation.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
count: 2
path: src/QueryReflection/QuerySimulation.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
count: 2
path: src/QueryReflection/QuerySimulation.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/Rules/DoctrineKeyValueStyleRule.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 2
path: src/Rules/DoctrineKeyValueStyleRule.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
path: src/Rules/PdoStatementExecuteMethodRule.php

-
message: """
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
use resolveQueryStrings\\(\\) instead$#
"""
count: 1
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 2
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\StringType is error\\-prone and deprecated\\. Use Type\\:\\:isString\\(\\) instead\\.$#"
count: 1
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
count: 1
path: src/SchemaReflection/SchemaReflection.php

-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
count: 2
Expand Down
8 changes: 2 additions & 6 deletions src/SchemaReflection/SchemaReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace staabm\PHPStanDba\SchemaReflection;

use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantStringType;

final class SchemaReflection
{
Expand Down Expand Up @@ -43,11 +41,9 @@ public function getTable(string $tableName): ?Table
$valueTypes = $resultType->getValueTypes();
$columns = [];
foreach ($keyTypes as $i => $keyType) {
if (! $keyType instanceof ConstantStringType) {
throw new ShouldNotHappenException();
foreach ($keyType->getConstantStrings() as $constantString) {
$columns[] = new Column($constantString->getValue(), $valueTypes[$i]);
}

$columns[] = new Column($keyType->getValue(), $valueTypes[$i]);
}

return $this->tables[$tableName] = new Table($tableName, $columns);
Expand Down
14 changes: 11 additions & 3 deletions src/SqlAst/StrCaseReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ public function getReturnType(FunctionCall $expression, QueryScope $scope): ?Typ
return new NullType();
}

if ($argType instanceof ConstantStringType) {
$results = [];
$constantStrings = $argType->getConstantStrings();
foreach ($constantStrings as $constantString) {
if (\in_array($expression->getFunction()->getName(), [BuiltInFunction::LOWER, BuiltInFunction::LCASE], true)) {
return new ConstantStringType(strtolower($argType->getValue()));
$results[] = new ConstantStringType(strtolower($constantString->getValue()));

continue;
}

return new ConstantStringType(strtoupper($argType->getValue()));
$results[] = new ConstantStringType(strtoupper($constantString->getValue()));
}

if (count($results) > 0) {
return TypeCombinator::union(...$results);
}

if (TypeCombinator::containsNull($argType)) {
Expand Down