From c9296d57b23d6bb1b0dc9f5bb1edd74a00eeaa93 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 18:57:04 +0100 Subject: [PATCH 1/9] More strict static analysis --- .phpstan-dba-mysqli.cache | 223 ++---------------- composer.json | 5 +- phpstan.neon.dist | 5 + src/Analyzer/QueryPlanAnalyzer.php | 3 + src/Error.php | 2 + src/QueryReflection/MysqliQueryReflector.php | 7 +- src/QueryReflection/Parameter.php | 3 + .../PdoMysqlQueryReflector.php | 3 + .../PdoPgSqlQueryReflector.php | 3 + src/QueryReflection/QueryReflection.php | 8 +- src/QueryReflection/QuerySimulation.php | 2 +- src/QueryReflection/ReflectionCache.php | 9 +- src/QueryReflection/RuntimeConfiguration.php | 3 + 13 files changed, 60 insertions(+), 216 deletions(-) diff --git a/.phpstan-dba-mysqli.cache b/.phpstan-dba-mysqli.cache index a889d7168..eb206c981 100644 --- a/.phpstan-dba-mysqli.cache +++ b/.phpstan-dba-mysqli.cache @@ -1,6 +1,6 @@ 'v11-phpstan1_9_3-update', - 'schemaHash' => NULL, + 'schemaHash' => '436d43fc96b9dd0cfad4bbc2837886e4', 'records' => array ( 'SELECT @@ -152,154 +152,6 @@ array ( 'result' => array ( - 5 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, - 'cachedDescriptions' => - array ( - 2 => '0|1|\'dbsignature\'|\'grouper\'', - 1 => 'int|string', - ), - 'types' => - array ( - 0 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 0, - )), - 1 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 1, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'dbsignature', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'grouper', - 'isClassString' => false, - )), - ), - 'normalized' => false, - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, - 'cachedDescriptions' => - array ( - 1 => 'int<-128, 127>|string|null', - ), - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - 2 => - PHPStan\Type\NullType::__set_state(array( - )), - ), - 'normalized' => true, - )), - 'allArrays' => NULL, - 'nextAutoIndexes' => - array ( - 0 => 2, - ), - 'keyTypes' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'dbsignature', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 0, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'grouper', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 1, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, - 'cachedDescriptions' => - array ( - 4 => 'string|null', - 2 => 'string|null', - 3 => 'string|null', - ), - 'types' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\NullType::__set_state(array( - )), - ), - 'normalized' => true, - )), - 1 => - PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, - 'cachedDescriptions' => - array ( - 4 => 'string|null', - 2 => 'string|null', - 3 => 'string|null', - ), - 'types' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\NullType::__set_state(array( - )), - ), - 'normalized' => true, - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - ), - 'optionalKeys' => - array ( - ), - 'isList' => false, - )), 3 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'keyType' => @@ -308,7 +160,6 @@ 'cachedDescriptions' => array ( 2 => '\'dbsignature\'|\'grouper\'', - 1 => 'string', ), 'types' => array ( @@ -331,21 +182,20 @@ )), 'itemType' => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, + 'sortedTypes' => false, 'cachedDescriptions' => array ( - 1 => 'int<-128, 127>|string|null', ), 'types' => array ( 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => PHPStan\Type\IntegerRangeType::__set_state(array( 'min' => -128, 'max' => 127, )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), 2 => PHPStan\Type\NullType::__set_state(array( )), @@ -378,11 +228,9 @@ array ( 0 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, + 'sortedTypes' => false, 'cachedDescriptions' => array ( - 4 => 'string|null', - 3 => 'string|null', ), 'types' => array ( @@ -422,7 +270,6 @@ WHERE table_name = \'1970-01-01\'' => 'cachedDescriptions' => array ( 2 => '0|1|2|\'column_default\'|\'column_name\'|\'is_nullable\'', - 1 => 'int|string', ), 'types' => array ( @@ -441,39 +288,21 @@ WHERE table_name = \'1970-01-01\'' => 3 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'column_default', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'column_default', 'isClassString' => false, )), 4 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'column_name', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'column_name', 'isClassString' => false, )), 5 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'is_nullable', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'is_nullable', 'isClassString' => false, )), @@ -482,10 +311,9 @@ WHERE table_name = \'1970-01-01\'' => )), 'itemType' => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, + 'sortedTypes' => false, 'cachedDescriptions' => array ( - 1 => 'string|null', ), 'types' => array ( @@ -508,13 +336,7 @@ WHERE table_name = \'1970-01-01\'' => 0 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'column_name', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'column_name', 'isClassString' => false, )), @@ -525,13 +347,7 @@ WHERE table_name = \'1970-01-01\'' => 2 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'column_default', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'column_default', 'isClassString' => false, )), @@ -542,13 +358,7 @@ WHERE table_name = \'1970-01-01\'' => 4 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'objectType' => NULL, - 'arrayKeyType' => NULL, - 'value' => 'is_nullable', - 'isClassString' => false, - )), + 'arrayKeyType' => NULL, 'value' => 'is_nullable', 'isClassString' => false, )), @@ -567,11 +377,9 @@ WHERE table_name = \'1970-01-01\'' => )), 2 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, + 'sortedTypes' => false, 'cachedDescriptions' => array ( - 4 => 'string|null', - 3 => 'string|null', ), 'types' => array ( @@ -586,10 +394,9 @@ WHERE table_name = \'1970-01-01\'' => )), 3 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => true, + 'sortedTypes' => false, 'cachedDescriptions' => array ( - 4 => 'string|null', ), 'types' => array ( diff --git a/composer.json b/composer.json index 54cad3822..eeb5c1927 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,12 @@ "doctrine/dbal": "^3.2", "friendsofphp/php-cs-fixer": "3.4.0", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/extension-installer": "^1.2", "phpstan/phpstan-php-parser": "^1.1", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.1", "phpunit/phpunit": "^9", + "tomasvotruba/unused-public": "^0.0.26", "vlucas/phpdotenv": "^5.4" }, "conflicts": { @@ -86,7 +88,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "composer/package-versions-deprecated": true + "composer/package-versions-deprecated": true, + "phpstan/extension-installer": true } }, "extra": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a7972aa2c..677c5612f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,11 @@ parameters: paths: - src/ + unused_public: + methods: true + properties: true + constants: true + bootstrapFiles: - bootstrap.php diff --git a/src/Analyzer/QueryPlanAnalyzer.php b/src/Analyzer/QueryPlanAnalyzer.php index ee57b749e..5b740321b 100644 --- a/src/Analyzer/QueryPlanAnalyzer.php +++ b/src/Analyzer/QueryPlanAnalyzer.php @@ -4,6 +4,9 @@ namespace staabm\PHPStanDba\Analyzer; +/** + * @api + */ final class QueryPlanAnalyzer { /** diff --git a/src/Error.php b/src/Error.php index f966888c0..4e4e8cbf4 100644 --- a/src/Error.php +++ b/src/Error.php @@ -7,6 +7,8 @@ use staabm\PHPStanDba\QueryReflection\QuerySimulation; /** + * @api + * * @phpstan-type ErrorCodes value-of|value-of */ final class Error diff --git a/src/QueryReflection/MysqliQueryReflector.php b/src/QueryReflection/MysqliQueryReflector.php index 1e54d452e..3c931c9d4 100644 --- a/src/QueryReflection/MysqliQueryReflector.php +++ b/src/QueryReflection/MysqliQueryReflector.php @@ -20,10 +20,11 @@ final class MysqliQueryReflector implements QueryReflector, RecordingReflector private const MYSQL_SYNTAX_ERROR_CODE = 1064; private const MYSQL_UNKNOWN_COLUMN_IN_FIELDLIST = 1054; public const MYSQL_UNKNOWN_TABLE = 1146; - public const MYSQL_INCORRECT_TABLE = 1103; - - public const MYSQL_HOST_NOT_FOUND = 2002; + private const MYSQL_INCORRECT_TABLE = 1103; + /** + * @api + */ public const NAME = 'mysqli'; private const MYSQL_ERROR_CODES = [ diff --git a/src/QueryReflection/Parameter.php b/src/QueryReflection/Parameter.php index 965380e43..20817b410 100644 --- a/src/QueryReflection/Parameter.php +++ b/src/QueryReflection/Parameter.php @@ -6,6 +6,9 @@ use PHPStan\Type\Type; +/** + * @api + */ final class Parameter { /** diff --git a/src/QueryReflection/PdoMysqlQueryReflector.php b/src/QueryReflection/PdoMysqlQueryReflector.php index 12547a4f6..ae6127b65 100644 --- a/src/QueryReflection/PdoMysqlQueryReflector.php +++ b/src/QueryReflection/PdoMysqlQueryReflector.php @@ -19,6 +19,9 @@ */ class PdoMysqlQueryReflector extends BasePdoQueryReflector { + /** + * @api + */ public const NAME = 'pdo-mysql'; public function __construct(PDO $pdo) diff --git a/src/QueryReflection/PdoPgSqlQueryReflector.php b/src/QueryReflection/PdoPgSqlQueryReflector.php index 5e00069a5..f513135e2 100644 --- a/src/QueryReflection/PdoPgSqlQueryReflector.php +++ b/src/QueryReflection/PdoPgSqlQueryReflector.php @@ -17,6 +17,9 @@ */ final class PdoPgSqlQueryReflector extends BasePdoQueryReflector { + /** + * @api + */ public const NAME = 'pdo-pgsql'; public function __construct(PDO $pdo) diff --git a/src/QueryReflection/QueryReflection.php b/src/QueryReflection/QueryReflection.php index dbb4a3457..e259d75d0 100644 --- a/src/QueryReflection/QueryReflection.php +++ b/src/QueryReflection/QueryReflection.php @@ -48,6 +48,9 @@ public function __construct(?DbaApi $dbaApi = null) self::reflector()->setupDbaApi($dbaApi); } + /** + * @api + */ public static function setupReflector(QueryReflector $reflector, RuntimeConfiguration $runtimeConfiguration): void { self::$reflector = $reflector; @@ -56,7 +59,7 @@ public static function setupReflector(QueryReflector $reflector, RuntimeConfigur public function validateQueryString(string $queryString): ?Error { - if ('SELECT' !== $this->getQueryType($queryString)) { + if ('SELECT' !== self::getQueryType($queryString)) { return null; } @@ -73,7 +76,7 @@ public function validateQueryString(string $queryString): ?Error */ public function getResultType(string $queryString, int $fetchType): ?Type { - if ('SELECT' !== $this->getQueryType($queryString)) { + if ('SELECT' !== self::getQueryType($queryString)) { return null; } @@ -111,6 +114,7 @@ public function resolvePreparedQueryStrings(Expr $queryExpr, Type $parameterType } /** + * @api * @deprecated use resolvePreparedQueryStrings() instead * * @throws UnresolvableQueryException diff --git a/src/QueryReflection/QuerySimulation.php b/src/QueryReflection/QuerySimulation.php index 52cf2bd49..1a7b55e4b 100644 --- a/src/QueryReflection/QuerySimulation.php +++ b/src/QueryReflection/QuerySimulation.php @@ -27,7 +27,7 @@ */ final class QuerySimulation { - public const DATE_FORMAT = 'Y-m-d'; + private const DATE_FORMAT = 'Y-m-d'; /** * @throws UnresolvableQueryException diff --git a/src/QueryReflection/ReflectionCache.php b/src/QueryReflection/ReflectionCache.php index e7f4e9270..5e29886ac 100644 --- a/src/QueryReflection/ReflectionCache.php +++ b/src/QueryReflection/ReflectionCache.php @@ -13,7 +13,7 @@ final class ReflectionCache { - public const SCHEMA_VERSION = 'v11-phpstan1_9_3-update'; + private const SCHEMA_VERSION = 'v11-phpstan1_9_3-update'; /** * @var string @@ -67,6 +67,12 @@ private function __construct(string $cacheFile) } } + /** + * @api + * + * @param non-empty-string $cacheFile + * @return static + */ public static function create(string $cacheFile): self { return new self($cacheFile); @@ -74,6 +80,7 @@ public static function create(string $cacheFile): self /** * @deprecated use create() instead + * @api */ public static function load(string $cacheFile): self { diff --git a/src/QueryReflection/RuntimeConfiguration.php b/src/QueryReflection/RuntimeConfiguration.php index 0e8d44271..baa93314d 100644 --- a/src/QueryReflection/RuntimeConfiguration.php +++ b/src/QueryReflection/RuntimeConfiguration.php @@ -7,6 +7,9 @@ use PHPStan\Php\PhpVersion; use staabm\PHPStanDba\Analyzer\QueryPlanAnalyzer; +/** + * @api + */ final class RuntimeConfiguration { /** From c6d1afe774363b254a18a9716a1e097fe65641e1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 18:59:13 +0100 Subject: [PATCH 2/9] fix --- src/Analyzer/QueryPlanAnalyzerMysql.php | 3 +++ src/Ast/ExpressionFinder.php | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Analyzer/QueryPlanAnalyzerMysql.php b/src/Analyzer/QueryPlanAnalyzerMysql.php index ac6a02456..7ff840ce5 100644 --- a/src/Analyzer/QueryPlanAnalyzerMysql.php +++ b/src/Analyzer/QueryPlanAnalyzerMysql.php @@ -12,14 +12,17 @@ final class QueryPlanAnalyzerMysql { /** + * @api * @deprecated use QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD instead */ public const DEFAULT_UNINDEXED_READS_THRESHOLD = QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD; /** + * @api * @deprecated use QueryPlanAnalyzer::TABLES_WITHOUT_DATA instead */ public const TABLES_WITHOUT_DATA = QueryPlanAnalyzer::TABLES_WITHOUT_DATA; /** + * @api * @deprecated use QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD instead */ public const DEFAULT_SMALL_TABLE_THRESHOLD = QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD; diff --git a/src/Ast/ExpressionFinder.php b/src/Ast/ExpressionFinder.php index 6c71d7c8e..35d6f2c74 100644 --- a/src/Ast/ExpressionFinder.php +++ b/src/Ast/ExpressionFinder.php @@ -27,6 +27,7 @@ public function __construct() } /** + * @api * @param Variable|MethodCall $expr * * @deprecated use findAssignmentExpression() instead From e8bfb7f7cea782c3e4cb223c674838c4a1c86912 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 19:01:42 +0100 Subject: [PATCH 3/9] Update PreviousConnectingVisitor.php --- src/Ast/PreviousConnectingVisitor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ast/PreviousConnectingVisitor.php b/src/Ast/PreviousConnectingVisitor.php index c3d1df7e6..58a109a6e 100644 --- a/src/Ast/PreviousConnectingVisitor.php +++ b/src/Ast/PreviousConnectingVisitor.php @@ -14,7 +14,7 @@ final class PreviousConnectingVisitor extends NodeVisitorAbstract public const ATTRIBUTE_PREVIOUS = 'dba-previous'; /** - * @var Node[] + * @var list */ private $stack = []; @@ -33,7 +33,7 @@ public function beforeTraverse(array $nodes) public function enterNode(Node $node) { - if (!empty($this->stack)) { + if ($this->stack !== []) { $node->setAttribute(self::ATTRIBUTE_PARENT, $this->stack[\count($this->stack) - 1]); } From da57b790d1632f9f3a751dc7d453dd8e8ccac3bf Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 19:15:31 +0100 Subject: [PATCH 4/9] fix --- src/PdoReflection/PdoStatementReflection.php | 2 +- src/PhpDoc/PhpDocUtil.php | 4 ++-- src/QueryReflection/ChainedReflector.php | 4 ++-- src/QueryReflection/QueryReflection.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PdoReflection/PdoStatementReflection.php b/src/PdoReflection/PdoStatementReflection.php index 152b1c361..7059a52ac 100644 --- a/src/PdoReflection/PdoStatementReflection.php +++ b/src/PdoReflection/PdoStatementReflection.php @@ -87,7 +87,7 @@ public function createGenericStatement(iterable $queryStrings, int $reflectionFe foreach ($queryStrings as $queryString) { $bothType = $queryReflection->getResultType($queryString, QueryReflector::FETCH_TYPE_BOTH); - if ($bothType) { + if ($bothType !== null) { $genericObjects[] = new PdoStatementObjectType($bothType, $reflectionFetchType); } } diff --git a/src/PhpDoc/PhpDocUtil.php b/src/PhpDoc/PhpDocUtil.php index 373ca848a..36c01104c 100644 --- a/src/PhpDoc/PhpDocUtil.php +++ b/src/PhpDoc/PhpDocUtil.php @@ -30,7 +30,7 @@ public static function matchTaintEscape($callLike, Scope $scope): ?string // atm no resolved phpdoc for methods // see https://github.com/phpstan/phpstan/discussions/7657 $phpDocString = $methodReflection->getDocComment(); - if (null !== $phpDocString && preg_match('/@psalm-taint-escape\s+(\S+).*$/m', $phpDocString, $matches)) { + if (null !== $phpDocString && preg_match('/@psalm-taint-escape\s+(\S+).*$/m', $phpDocString, $matches) === 1) { return $matches[1]; } } @@ -91,7 +91,7 @@ private static function matchStringAnnotation(string $annotation, $callLike, Sco // atm no resolved phpdoc for methods // see https://github.com/phpstan/phpstan/discussions/7657 $phpDocString = $methodReflection->getDocComment(); - if (null !== $phpDocString && preg_match('/'.$annotation.'\s+(\S+).*$/m', $phpDocString, $matches)) { + if (null !== $phpDocString && preg_match('/'.$annotation.'\s+(\S+).*$/m', $phpDocString, $matches) === 1) { $placeholder = $matches[1]; if (\in_array($placeholder[0], ['"', "'"], true)) { diff --git a/src/QueryReflection/ChainedReflector.php b/src/QueryReflection/ChainedReflector.php index b61abed3c..8aaec038e 100644 --- a/src/QueryReflection/ChainedReflector.php +++ b/src/QueryReflection/ChainedReflector.php @@ -30,7 +30,7 @@ public function validateQueryString(string $queryString): ?Error $reflectorError = $reflector->validateQueryString($queryString); // on "not found" error, we try the next reflector. - if ($reflectorError) { + if ($reflectorError !== null) { if (!\in_array($reflectorError->getCode(), [MysqliQueryReflector::MYSQL_UNKNOWN_TABLE], true)) { return $reflectorError; } @@ -54,7 +54,7 @@ public function getResultType(string $queryString, int $fetchType): ?Type foreach ($this->reflectors as $reflector) { $reflectorResult = $reflector->getResultType($queryString, $fetchType); - if ($reflectorResult) { + if ($reflectorResult !== null) { return $reflectorResult; } } diff --git a/src/QueryReflection/QueryReflection.php b/src/QueryReflection/QueryReflection.php index e259d75d0..4e7cf6362 100644 --- a/src/QueryReflection/QueryReflection.php +++ b/src/QueryReflection/QueryReflection.php @@ -261,7 +261,7 @@ public static function getQueryType(string $query): ?string { $query = ltrim($query); - if (preg_match('/^\s*\(?\s*(SELECT|SHOW|UPDATE|INSERT|DELETE|REPLACE|CREATE|CALL|OPTIMIZE)/i', $query, $matches)) { + if (preg_match('/^\s*\(?\s*(SELECT|SHOW|UPDATE|INSERT|DELETE|REPLACE|CREATE|CALL|OPTIMIZE)/i', $query, $matches) === 1) { return strtoupper($matches[1]); } From 8b578b95144d499a3ce4238c97a64add882aa31a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 21:56:15 +0100 Subject: [PATCH 5/9] fix --- .phpstan-dba-mysqli.cache | 220 +++++++++++++++++-- .phpstan-dba-pdo-mysql.cache | 1 - composer.json | 2 + phpstan-baseline.neon | 56 +++++ phpstan.neon.dist | 1 + src/Analyzer/QueryPlanAnalyzerMysql.php | 3 + src/Ast/ExpressionFinder.php | 1 + src/Ast/PreviousConnectingVisitor.php | 2 +- src/PdoReflection/PdoStatementReflection.php | 2 +- src/PhpDoc/PhpDocUtil.php | 4 +- src/QueryReflection/ChainedReflector.php | 4 +- src/QueryReflection/QueryReflection.php | 3 +- src/QueryReflection/ReflectionCache.php | 2 + tests/default/QuerySimulationTest.php | 6 +- tests/rules/QueryPlanAnalyzerRuleTest.php | 8 +- 15 files changed, 286 insertions(+), 29 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/.phpstan-dba-mysqli.cache b/.phpstan-dba-mysqli.cache index eb206c981..158295a2d 100644 --- a/.phpstan-dba-mysqli.cache +++ b/.phpstan-dba-mysqli.cache @@ -152,25 +152,34 @@ array ( 'result' => array ( - 3 => + 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'keyType' => PHPStan\Type\UnionType::__set_state(array( 'sortedTypes' => true, 'cachedDescriptions' => array ( - 2 => '\'dbsignature\'|\'grouper\'', + 2 => '0|1|\'dbsignature\'|\'grouper\'', + 1 => 'int|string', ), 'types' => array ( 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 2 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, 'arrayKeyType' => NULL, 'value' => 'dbsignature', 'isClassString' => false, )), - 1 => + 3 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, 'arrayKeyType' => NULL, @@ -182,20 +191,161 @@ )), 'itemType' => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => false, + 'sortedTypes' => true, 'cachedDescriptions' => array ( + 1 => 'int<-128, 127>|string|null', ), 'types' => array ( 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 1 => PHPStan\Type\StringType::__set_state(array( )), + 2 => + PHPStan\Type\NullType::__set_state(array( + )), + ), + 'normalized' => true, + )), + 'allArrays' => NULL, + 'nextAutoIndexes' => + array ( + 0 => 2, + ), + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'dbsignature', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'grouper', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\UnionType::__set_state(array( + 'sortedTypes' => true, + 'cachedDescriptions' => + array ( + 4 => 'string|null', + 2 => 'string|null', + 3 => 'string|null', + ), + 'types' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\NullType::__set_state(array( + )), + ), + 'normalized' => true, + )), + 1 => + PHPStan\Type\UnionType::__set_state(array( + 'sortedTypes' => true, + 'cachedDescriptions' => + array ( + 4 => 'string|null', + 2 => 'string|null', + 3 => 'string|null', + ), + 'types' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\NullType::__set_state(array( + )), + ), + 'normalized' => true, + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'optionalKeys' => + array ( + ), + 'isList' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + 'sortedTypes' => true, + 'cachedDescriptions' => + array ( + 2 => '\'dbsignature\'|\'grouper\'', + 1 => 'string', + ), + 'types' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'dbsignature', + 'isClassString' => false, + )), 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'grouper', + 'isClassString' => false, + )), + ), + 'normalized' => false, + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'sortedTypes' => true, + 'cachedDescriptions' => + array ( + 1 => 'int<-128, 127>|string|null', + ), + 'types' => + array ( + 0 => PHPStan\Type\IntegerRangeType::__set_state(array( 'min' => -128, 'max' => 127, )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), 2 => PHPStan\Type\NullType::__set_state(array( )), @@ -228,9 +378,11 @@ array ( 0 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => false, + 'sortedTypes' => true, 'cachedDescriptions' => array ( + 4 => 'string|null', + 3 => 'string|null', ), 'types' => array ( @@ -270,6 +422,7 @@ WHERE table_name = \'1970-01-01\'' => 'cachedDescriptions' => array ( 2 => '0|1|2|\'column_default\'|\'column_name\'|\'is_nullable\'', + 1 => 'int|string', ), 'types' => array ( @@ -288,21 +441,39 @@ WHERE table_name = \'1970-01-01\'' => 3 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'column_default', + 'isClassString' => false, + )), 'value' => 'column_default', 'isClassString' => false, )), 4 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'column_name', + 'isClassString' => false, + )), 'value' => 'column_name', 'isClassString' => false, )), 5 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'is_nullable', + 'isClassString' => false, + )), 'value' => 'is_nullable', 'isClassString' => false, )), @@ -311,9 +482,10 @@ WHERE table_name = \'1970-01-01\'' => )), 'itemType' => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => false, + 'sortedTypes' => true, 'cachedDescriptions' => array ( + 1 => 'string|null', ), 'types' => array ( @@ -336,7 +508,13 @@ WHERE table_name = \'1970-01-01\'' => 0 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'column_name', + 'isClassString' => false, + )), 'value' => 'column_name', 'isClassString' => false, )), @@ -347,7 +525,13 @@ WHERE table_name = \'1970-01-01\'' => 2 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'column_default', + 'isClassString' => false, + )), 'value' => 'column_default', 'isClassString' => false, )), @@ -358,7 +542,13 @@ WHERE table_name = \'1970-01-01\'' => 4 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'objectType' => NULL, - 'arrayKeyType' => NULL, + 'arrayKeyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'objectType' => NULL, + 'arrayKeyType' => NULL, + 'value' => 'is_nullable', + 'isClassString' => false, + )), 'value' => 'is_nullable', 'isClassString' => false, )), @@ -377,9 +567,10 @@ WHERE table_name = \'1970-01-01\'' => )), 2 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => false, + 'sortedTypes' => true, 'cachedDescriptions' => array ( + 4 => 'string|null', ), 'types' => array ( @@ -394,9 +585,10 @@ WHERE table_name = \'1970-01-01\'' => )), 3 => PHPStan\Type\UnionType::__set_state(array( - 'sortedTypes' => false, + 'sortedTypes' => true, 'cachedDescriptions' => array ( + 4 => 'string|null', ), 'types' => array ( diff --git a/.phpstan-dba-pdo-mysql.cache b/.phpstan-dba-pdo-mysql.cache index a889d7168..07d843bd6 100644 --- a/.phpstan-dba-pdo-mysql.cache +++ b/.phpstan-dba-pdo-mysql.cache @@ -571,7 +571,6 @@ WHERE table_name = \'1970-01-01\'' => 'cachedDescriptions' => array ( 4 => 'string|null', - 3 => 'string|null', ), 'types' => array ( diff --git a/composer.json b/composer.json index eeb5c1927..28d417501 100644 --- a/composer.json +++ b/composer.json @@ -56,6 +56,8 @@ "@csfix" ], "record": [ + "phpstan analyse -c phpstan.neon.dist --generate-baseline", + "phpstan clear-result-cache", "@putenv DBA_MODE=recording", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..a73f71e5e --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,56 @@ +parameters: + ignoreErrors: + - + message: "#^Instanceof between mysqli_result\\\\|string\\|null\\>\\> and mysqli_result will always evaluate to true\\.$#" + count: 1 + path: src/DbSchema/SchemaHasherMysql.php + + - + message: "#^Strict comparison using \\!\\=\\= between null and PHPStan\\\\Type\\\\Type will always evaluate to true\\.$#" + count: 1 + path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.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\\\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should be covariant with return type \\(array\\, 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\\(\\)$#" + count: 1 + path: src/QueryReflection/PdoPgSqlQueryReflector.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\\.$#" + count: 1 + path: src/QueryReflection/QueryReflection.php + + - + message: "#^Strict comparison using \\=\\=\\= between null and null will always evaluate to true\\.$#" + count: 1 + path: src/QueryReflection/QueryReflection.php + + - + message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#" + count: 2 + path: src/TypeMapping/MysqliTypeMapper.php + + - + message: "#^Only booleans are allowed in an elseif condition, int\\|false given\\.$#" + count: 1 + path: src/TypeMapping/MysqliTypeMapper.php + + - + message: "#^Only booleans are allowed in an if condition, int given\\.$#" + count: 1 + path: src/TypeMapping/MysqliTypeMapper.php + + - + message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" + count: 1 + path: src/TypeMapping/MysqliTypeMapper.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 677c5612f..d44cf1904 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,7 @@ includes: - config/stubFiles.neon - config/extensions.neon + - phpstan-baseline.neon parameters: level: max diff --git a/src/Analyzer/QueryPlanAnalyzerMysql.php b/src/Analyzer/QueryPlanAnalyzerMysql.php index 7ff840ce5..8b313a3ff 100644 --- a/src/Analyzer/QueryPlanAnalyzerMysql.php +++ b/src/Analyzer/QueryPlanAnalyzerMysql.php @@ -13,16 +13,19 @@ final class QueryPlanAnalyzerMysql { /** * @api + * * @deprecated use QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD instead */ public const DEFAULT_UNINDEXED_READS_THRESHOLD = QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD; /** * @api + * * @deprecated use QueryPlanAnalyzer::TABLES_WITHOUT_DATA instead */ public const TABLES_WITHOUT_DATA = QueryPlanAnalyzer::TABLES_WITHOUT_DATA; /** * @api + * * @deprecated use QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD instead */ public const DEFAULT_SMALL_TABLE_THRESHOLD = QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD; diff --git a/src/Ast/ExpressionFinder.php b/src/Ast/ExpressionFinder.php index 35d6f2c74..f6930e84a 100644 --- a/src/Ast/ExpressionFinder.php +++ b/src/Ast/ExpressionFinder.php @@ -28,6 +28,7 @@ public function __construct() /** * @api + * * @param Variable|MethodCall $expr * * @deprecated use findAssignmentExpression() instead diff --git a/src/Ast/PreviousConnectingVisitor.php b/src/Ast/PreviousConnectingVisitor.php index 58a109a6e..93fe934cf 100644 --- a/src/Ast/PreviousConnectingVisitor.php +++ b/src/Ast/PreviousConnectingVisitor.php @@ -33,7 +33,7 @@ public function beforeTraverse(array $nodes) public function enterNode(Node $node) { - if ($this->stack !== []) { + if ([] !== $this->stack) { $node->setAttribute(self::ATTRIBUTE_PARENT, $this->stack[\count($this->stack) - 1]); } diff --git a/src/PdoReflection/PdoStatementReflection.php b/src/PdoReflection/PdoStatementReflection.php index 7059a52ac..cb815bd30 100644 --- a/src/PdoReflection/PdoStatementReflection.php +++ b/src/PdoReflection/PdoStatementReflection.php @@ -87,7 +87,7 @@ public function createGenericStatement(iterable $queryStrings, int $reflectionFe foreach ($queryStrings as $queryString) { $bothType = $queryReflection->getResultType($queryString, QueryReflector::FETCH_TYPE_BOTH); - if ($bothType !== null) { + if (null !== $bothType) { $genericObjects[] = new PdoStatementObjectType($bothType, $reflectionFetchType); } } diff --git a/src/PhpDoc/PhpDocUtil.php b/src/PhpDoc/PhpDocUtil.php index 36c01104c..07809f0f3 100644 --- a/src/PhpDoc/PhpDocUtil.php +++ b/src/PhpDoc/PhpDocUtil.php @@ -30,7 +30,7 @@ public static function matchTaintEscape($callLike, Scope $scope): ?string // atm no resolved phpdoc for methods // see https://github.com/phpstan/phpstan/discussions/7657 $phpDocString = $methodReflection->getDocComment(); - if (null !== $phpDocString && preg_match('/@psalm-taint-escape\s+(\S+).*$/m', $phpDocString, $matches) === 1) { + if (null !== $phpDocString && 1 === preg_match('/@psalm-taint-escape\s+(\S+).*$/m', $phpDocString, $matches)) { return $matches[1]; } } @@ -91,7 +91,7 @@ private static function matchStringAnnotation(string $annotation, $callLike, Sco // atm no resolved phpdoc for methods // see https://github.com/phpstan/phpstan/discussions/7657 $phpDocString = $methodReflection->getDocComment(); - if (null !== $phpDocString && preg_match('/'.$annotation.'\s+(\S+).*$/m', $phpDocString, $matches) === 1) { + if (null !== $phpDocString && 1 === preg_match('/'.$annotation.'\s+(\S+).*$/m', $phpDocString, $matches)) { $placeholder = $matches[1]; if (\in_array($placeholder[0], ['"', "'"], true)) { diff --git a/src/QueryReflection/ChainedReflector.php b/src/QueryReflection/ChainedReflector.php index 8aaec038e..9a660f000 100644 --- a/src/QueryReflection/ChainedReflector.php +++ b/src/QueryReflection/ChainedReflector.php @@ -30,7 +30,7 @@ public function validateQueryString(string $queryString): ?Error $reflectorError = $reflector->validateQueryString($queryString); // on "not found" error, we try the next reflector. - if ($reflectorError !== null) { + if (null !== $reflectorError) { if (!\in_array($reflectorError->getCode(), [MysqliQueryReflector::MYSQL_UNKNOWN_TABLE], true)) { return $reflectorError; } @@ -54,7 +54,7 @@ public function getResultType(string $queryString, int $fetchType): ?Type foreach ($this->reflectors as $reflector) { $reflectorResult = $reflector->getResultType($queryString, $fetchType); - if ($reflectorResult !== null) { + if (null !== $reflectorResult) { return $reflectorResult; } } diff --git a/src/QueryReflection/QueryReflection.php b/src/QueryReflection/QueryReflection.php index 4e7cf6362..74daab7c3 100644 --- a/src/QueryReflection/QueryReflection.php +++ b/src/QueryReflection/QueryReflection.php @@ -115,6 +115,7 @@ public function resolvePreparedQueryStrings(Expr $queryExpr, Type $parameterType /** * @api + * * @deprecated use resolvePreparedQueryStrings() instead * * @throws UnresolvableQueryException @@ -261,7 +262,7 @@ public static function getQueryType(string $query): ?string { $query = ltrim($query); - if (preg_match('/^\s*\(?\s*(SELECT|SHOW|UPDATE|INSERT|DELETE|REPLACE|CREATE|CALL|OPTIMIZE)/i', $query, $matches) === 1) { + if (1 === preg_match('/^\s*\(?\s*(SELECT|SHOW|UPDATE|INSERT|DELETE|REPLACE|CREATE|CALL|OPTIMIZE)/i', $query, $matches)) { return strtoupper($matches[1]); } diff --git a/src/QueryReflection/ReflectionCache.php b/src/QueryReflection/ReflectionCache.php index 5e29886ac..d78262ab6 100644 --- a/src/QueryReflection/ReflectionCache.php +++ b/src/QueryReflection/ReflectionCache.php @@ -71,6 +71,7 @@ private function __construct(string $cacheFile) * @api * * @param non-empty-string $cacheFile + * * @return static */ public static function create(string $cacheFile): self @@ -80,6 +81,7 @@ public static function create(string $cacheFile): self /** * @deprecated use create() instead + * * @api */ public static function load(string $cacheFile): self diff --git a/tests/default/QuerySimulationTest.php b/tests/default/QuerySimulationTest.php index b38d1c570..f0cfa52b0 100644 --- a/tests/default/QuerySimulationTest.php +++ b/tests/default/QuerySimulationTest.php @@ -18,7 +18,7 @@ public function testIntersectionTypeInt() $builder->setOffsetValueType(new IntegerType(), new IntegerType()); $simulatedValue = QuerySimulation::simulateParamValueType($builder->getArray(), false); - $this->assertNotNull($simulatedValue); + self::assertNotNull($simulatedValue); } public function testIntersectionTypeString() @@ -28,7 +28,7 @@ public function testIntersectionTypeString() $builder->setOffsetValueType(new StringType(), new IntegerType()); $simulatedValue = QuerySimulation::simulateParamValueType($builder->getArray(), false); - $this->assertNotNull($simulatedValue); + self::assertNotNull($simulatedValue); } public function testIntersectionTypeMix() @@ -39,7 +39,7 @@ public function testIntersectionTypeMix() $builder->setOffsetValueType(new IntegerType(), new FloatType()); $simulatedValue = QuerySimulation::simulateParamValueType($builder->getArray(), false); - $this->assertNotNull($simulatedValue); + self::assertNotNull($simulatedValue); } /** diff --git a/tests/rules/QueryPlanAnalyzerRuleTest.php b/tests/rules/QueryPlanAnalyzerRuleTest.php index 435778955..597b086a0 100644 --- a/tests/rules/QueryPlanAnalyzerRuleTest.php +++ b/tests/rules/QueryPlanAnalyzerRuleTest.php @@ -49,11 +49,11 @@ public static function getAdditionalConfigFiles(): array public function testNotUsingIndex(): void { if ('pdo-pgsql' === getenv('DBA_REFLECTOR')) { - $this->markTestSkipped('query plan analyzer is not yet implemented for pgsql'); + self::markTestSkipped('query plan analyzer is not yet implemented for pgsql'); } if ('recording' !== getenv('DBA_MODE')) { - $this->markTestSkipped('query plan analyzer requires a active database connection'); + self::markTestSkipped('query plan analyzer requires a active database connection'); } $this->numberOfAllowedUnindexedReads = true; @@ -94,11 +94,11 @@ public function testNotUsingIndex(): void public function testNotUsingIndexInDebugMode(): void { if ('pdo-pgsql' === getenv('DBA_REFLECTOR')) { - $this->markTestSkipped('query plan analyzer is not yet implemented for pgsql'); + self::markTestSkipped('query plan analyzer is not yet implemented for pgsql'); } if ('recording' !== getenv('DBA_MODE')) { - $this->markTestSkipped('query plan analyzer requires a active database connection'); + self::markTestSkipped('query plan analyzer requires a active database connection'); } $this->debugMode = true; From 17e122b6f7600deb37888a0ff647222c3b3d4be0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 22:00:58 +0100 Subject: [PATCH 6/9] Update phpstan-baseline.neon --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a73f71e5e..fa08e37f6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: '#^Instanceof between mysqli_result\\> and mysqli_result will always evaluate to true\.$#' + count: 1 + path: src/DbSchema/SchemaHasherMysql.php + - message: "#^Instanceof between mysqli_result\\\\|string\\|null\\>\\> and mysqli_result will always evaluate to true\\.$#" count: 1 From dc6fbf47e98e2e7ae5204dfb93592c267a9fc6d9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 22:03:27 +0100 Subject: [PATCH 7/9] Update composer.json --- composer.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/composer.json b/composer.json index 28d417501..eeb5c1927 100644 --- a/composer.json +++ b/composer.json @@ -56,8 +56,6 @@ "@csfix" ], "record": [ - "phpstan analyse -c phpstan.neon.dist --generate-baseline", - "phpstan clear-result-cache", "@putenv DBA_MODE=recording", From 9a912f5623a549e4050fb8065873e61f8a961867 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 22:05:12 +0100 Subject: [PATCH 8/9] fix --- phpstan-baseline.neon | 10 ---------- src/TypeMapping/MysqliTypeMapper.php | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fa08e37f6..56d8883f1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -45,17 +45,7 @@ parameters: count: 2 path: src/TypeMapping/MysqliTypeMapper.php - - - message: "#^Only booleans are allowed in an elseif condition, int\\|false given\\.$#" - count: 1 - path: src/TypeMapping/MysqliTypeMapper.php - - message: "#^Only booleans are allowed in an if condition, int given\\.$#" count: 1 path: src/TypeMapping/MysqliTypeMapper.php - - - - message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" - count: 1 - path: src/TypeMapping/MysqliTypeMapper.php diff --git a/src/TypeMapping/MysqliTypeMapper.php b/src/TypeMapping/MysqliTypeMapper.php index 61078fc53..72ed0e40b 100644 --- a/src/TypeMapping/MysqliTypeMapper.php +++ b/src/TypeMapping/MysqliTypeMapper.php @@ -29,12 +29,12 @@ public function __construct(?DbaApi $dbaApi) // skip bool constants like MYSQLI_IS_MARIADB continue; } - if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) { + if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m) === 1) { if (!\is_string($m[1])) { throw new ShouldNotHappenException(); } $this->nativeTypes[$n] = $m[1]; - } elseif (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m)) { + } elseif (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m) === 1) { if (!\is_string($m[1])) { throw new ShouldNotHappenException(); } From 92adc5ee6414cb4f6a15a5af44c5d4b69ce21dc5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Dec 2022 23:26:58 +0100 Subject: [PATCH 9/9] cs --- src/TypeMapping/MysqliTypeMapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TypeMapping/MysqliTypeMapper.php b/src/TypeMapping/MysqliTypeMapper.php index 72ed0e40b..575823b6e 100644 --- a/src/TypeMapping/MysqliTypeMapper.php +++ b/src/TypeMapping/MysqliTypeMapper.php @@ -29,12 +29,12 @@ public function __construct(?DbaApi $dbaApi) // skip bool constants like MYSQLI_IS_MARIADB continue; } - if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m) === 1) { + if (1 === preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) { if (!\is_string($m[1])) { throw new ShouldNotHappenException(); } $this->nativeTypes[$n] = $m[1]; - } elseif (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m) === 1) { + } elseif (1 === preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m)) { if (!\is_string($m[1])) { throw new ShouldNotHappenException(); }