From 8e4dad8b1fb6611d2a8145680c2b01acf0f11651 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 14:26:43 +0100 Subject: [PATCH 1/5] doctrine-dbal: support `Result->fetchOne()` type inference --- .phpstan-dba.cache | 262 ------------------ ...ctrineResultDynamicReturnTypeExtension.php | 12 +- tests/data/doctrine-dbal.php | 3 + 3 files changed, 14 insertions(+), 263 deletions(-) diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index 1886c3627..80904ea35 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -3487,92 +3487,6 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( - 5 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'allArrays' => NULL, - 'keyTypes' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 0, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'adaid', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 1, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - ), - 'nextAutoIndex' => 2, - 'optionalKeys' => - array ( - ), - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - '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( - 'value' => 'adaid', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - ), - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - ), - )), - )), 3 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, @@ -4446,98 +4360,6 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( - 3 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'allArrays' => NULL, - 'keyTypes' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'adaid', - 'isClassString' => false, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'gesperrt', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'freigabe1u1', - 'isClassString' => false, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - ), - 'nextAutoIndex' => 0, - 'optionalKeys' => - array ( - ), - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'adaid', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'freigabe1u1', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'gesperrt', - 'isClassString' => false, - )), - ), - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 4294967295, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - ), - )), - )), 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, @@ -4680,90 +4502,6 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L ), )), )), - 4 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'allArrays' => NULL, - 'keyTypes' => - 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\ConstantIntegerType::__set_state(array( - 'value' => 2, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 3, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - ), - 'nextAutoIndex' => 4, - 'optionalKeys' => - array ( - ), - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - '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\ConstantIntegerType::__set_state(array( - 'value' => 2, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 3, - )), - ), - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 4294967295, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - ), - )), - )), ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada ' => diff --git a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php index ac4109109..b3c6d0e97 100644 --- a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php @@ -21,6 +21,16 @@ final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { + public const METHODS = [ + 'fetchone', + 'columncount', + 'fetchfirstcolumn', + 'fetchnumeric', + 'fetchallnumeric', + 'fetchassociative', + 'fetchallassociative', + ]; + public function getClass(): string { return Result::class; @@ -28,7 +38,7 @@ public function getClass(): string public function isMethodSupported(MethodReflection $methodReflection): bool { - return \in_array(strtolower($methodReflection->getName()), ['columncount', 'fetchfirstcolumn', 'fetchnumeric', 'fetchallnumeric', 'fetchassociative', 'fetchallassociative'], true); + return \in_array(strtolower($methodReflection->getName()), self::METHODS, true); } public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type diff --git a/tests/data/doctrine-dbal.php b/tests/data/doctrine-dbal.php index 43a28beee..d08d3848f 100644 --- a/tests/data/doctrine-dbal.php +++ b/tests/data/doctrine-dbal.php @@ -13,6 +13,9 @@ public function foo(Connection $conn) $result = $conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada'); assertType('Doctrine\DBAL\Result, 1: int<0, 4294967295>, gesperrt: int<-128, 127>, 2: int<-128, 127>, freigabe1u1: int<-128, 127>, 3: int<-128, 127>}>', $result); + $fetch = $result->fetchOne(); + assertType('string', $fetch); + $fetch = $result->fetchNumeric(); assertType('array{string, int<0, 4294967295>, int<-128, 127>, int<-128, 127>}|false', $fetch); From 9a306ad86678aa193ab97d3803fc5a2df70666d0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 14:28:31 +0100 Subject: [PATCH 2/5] support `Result->iterateNumeric()` --- .../DoctrineResultDynamicReturnTypeExtension.php | 3 ++- tests/data/doctrine-dbal.php | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php index b3c6d0e97..86f21e212 100644 --- a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php @@ -22,13 +22,14 @@ final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public const METHODS = [ - 'fetchone', 'columncount', + 'fetchone', 'fetchfirstcolumn', 'fetchnumeric', 'fetchallnumeric', 'fetchassociative', 'fetchallassociative', + 'iteratenumeric', ]; public function getClass(): string diff --git a/tests/data/doctrine-dbal.php b/tests/data/doctrine-dbal.php index d08d3848f..0b1e12e1c 100644 --- a/tests/data/doctrine-dbal.php +++ b/tests/data/doctrine-dbal.php @@ -13,6 +13,9 @@ public function foo(Connection $conn) $result = $conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada'); assertType('Doctrine\DBAL\Result, 1: int<0, 4294967295>, gesperrt: int<-128, 127>, 2: int<-128, 127>, freigabe1u1: int<-128, 127>, 3: int<-128, 127>}>', $result); + $columnCount = $result->columnCount(); + assertType('4', $columnCount); + $fetch = $result->fetchOne(); assertType('string', $fetch); @@ -31,8 +34,8 @@ public function foo(Connection $conn) $fetch = $result->fetchAllAssociative(); assertType('array, array{email: string, adaid: int<0, 4294967295>, gesperrt: int<-128, 127>, freigabe1u1: int<-128, 127>}>', $fetch); - $columnCount = $result->columnCount(); - assertType('4', $columnCount); + $fetch = $result->iterateNumeric(); + assertType('Traversable, int<-128, 127>, int<-128, 127>}>', $fetch); } public function executeQuery(Connection $conn, array $types, QueryCacheProfile $qcp) From 923e9b99f667a8ce367bd7d9938304dfc9e9c661 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 14:29:22 +0100 Subject: [PATCH 3/5] support `Result->iterateAssociative()` --- .phpstan-dba.cache | 262 ++++++++++++++++++ ...ctrineResultDynamicReturnTypeExtension.php | 1 + tests/data/doctrine-dbal.php | 3 + 3 files changed, 266 insertions(+) diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index 80904ea35..1886c3627 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -3487,6 +3487,92 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 2, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + '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( + 'value' => 'adaid', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), 3 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, @@ -4360,6 +4446,98 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( + 3 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'nextAutoIndex' => 0, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, @@ -4502,6 +4680,90 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L ), )), )), + 4 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + 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\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'nextAutoIndex' => 4, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + '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\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada ' => diff --git a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php index 86f21e212..11f9baacd 100644 --- a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php @@ -30,6 +30,7 @@ final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodRet 'fetchassociative', 'fetchallassociative', 'iteratenumeric', + 'iterateassociative', ]; public function getClass(): string diff --git a/tests/data/doctrine-dbal.php b/tests/data/doctrine-dbal.php index 0b1e12e1c..92208ba12 100644 --- a/tests/data/doctrine-dbal.php +++ b/tests/data/doctrine-dbal.php @@ -36,6 +36,9 @@ public function foo(Connection $conn) $fetch = $result->iterateNumeric(); assertType('Traversable, int<-128, 127>, int<-128, 127>}>', $fetch); + + $fetch = $result->iterateAssociative(); + assertType('Traversable, gesperrt: int<-128, 127>, freigabe1u1: int<-128, 127>}>', $fetch); } public function executeQuery(Connection $conn, array $types, QueryCacheProfile $qcp) From 2f012bdd566db8fc6481200c6cf8726d8b0824b6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 14:30:41 +0100 Subject: [PATCH 4/5] support `Result->iterateColumn()` --- .phpstan-dba.cache | 176 ------------------ ...ctrineResultDynamicReturnTypeExtension.php | 1 + tests/data/doctrine-dbal.php | 3 + 3 files changed, 4 insertions(+), 176 deletions(-) diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index 1886c3627..82e4a777a 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -4446,98 +4446,6 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( - 3 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'allArrays' => NULL, - 'keyTypes' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'adaid', - 'isClassString' => false, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'gesperrt', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'freigabe1u1', - 'isClassString' => false, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - ), - 'nextAutoIndex' => 0, - 'optionalKeys' => - array ( - ), - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'adaid', - 'isClassString' => false, - )), - 1 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'email', - 'isClassString' => false, - )), - 2 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'freigabe1u1', - 'isClassString' => false, - )), - 3 => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'gesperrt', - 'isClassString' => false, - )), - ), - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 4294967295, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - ), - )), - )), 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, @@ -4680,90 +4588,6 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L ), )), )), - 4 => - PHPStan\Type\Constant\ConstantArrayType::__set_state(array( - 'allArrays' => NULL, - 'keyTypes' => - 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\ConstantIntegerType::__set_state(array( - 'value' => 2, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 3, - )), - ), - 'valueTypes' => - array ( - 0 => - PHPStan\Type\StringType::__set_state(array( - )), - 1 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - 3 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 127, - )), - ), - 'nextAutoIndex' => 4, - 'optionalKeys' => - array ( - ), - 'keyType' => - PHPStan\Type\UnionType::__set_state(array( - '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\ConstantIntegerType::__set_state(array( - 'value' => 2, - )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 3, - )), - ), - )), - 'itemType' => - PHPStan\Type\UnionType::__set_state(array( - 'types' => - array ( - 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -128, - 'max' => 4294967295, - )), - 1 => - PHPStan\Type\StringType::__set_state(array( - )), - ), - )), - )), ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada ' => diff --git a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php index 11f9baacd..5e1ff1fa1 100644 --- a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php @@ -31,6 +31,7 @@ final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodRet 'fetchallassociative', 'iteratenumeric', 'iterateassociative', + 'iteratecolumn', ]; public function getClass(): string diff --git a/tests/data/doctrine-dbal.php b/tests/data/doctrine-dbal.php index 92208ba12..bfaddcf53 100644 --- a/tests/data/doctrine-dbal.php +++ b/tests/data/doctrine-dbal.php @@ -39,6 +39,9 @@ public function foo(Connection $conn) $fetch = $result->iterateAssociative(); assertType('Traversable, gesperrt: int<-128, 127>, freigabe1u1: int<-128, 127>}>', $fetch); + + $fetch = $result->iterateColumn(); + assertType('Traversable', $fetch); } public function executeQuery(Connection $conn, array $types, QueryCacheProfile $qcp) From c3ffedeb4242cf3392e6aa459359af6cd7b12e15 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 14:31:36 +0100 Subject: [PATCH 5/5] fix --- .phpstan-dba.cache | 236 +++++++++++++++--- ...ctrineResultDynamicReturnTypeExtension.php | 2 +- 2 files changed, 207 insertions(+), 31 deletions(-) diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index 82e4a777a..9cba86f9c 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -3487,7 +3487,7 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'error' => NULL, 'result' => array ( - 5 => + 3 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, 'keyTypes' => @@ -3498,18 +3498,10 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'isClassString' => false, )), 1 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 0, - )), - 2 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'value' => 'adaid', 'isClassString' => false, )), - 3 => - PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( - 'value' => 1, - )), ), 'valueTypes' => array ( @@ -3517,20 +3509,12 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L PHPStan\Type\StringType::__set_state(array( )), 1 => - PHPStan\Type\StringType::__set_state(array( - )), - 2 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => 0, - 'max' => 4294967295, - )), - 3 => PHPStan\Type\IntegerRangeType::__set_state(array( 'min' => 0, 'max' => 4294967295, )), ), - 'nextAutoIndex' => 2, + 'nextAutoIndex' => 0, 'optionalKeys' => array ( ), @@ -3539,19 +3523,11 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L '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( 'value' => 'adaid', 'isClassString' => false, )), - 3 => + 1 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'value' => 'email', 'isClassString' => false, @@ -3573,7 +3549,7 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L ), )), )), - 3 => + 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, 'keyTypes' => @@ -3584,10 +3560,18 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L 'isClassString' => false, )), 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 2 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'value' => 'adaid', 'isClassString' => false, )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), ), 'valueTypes' => array ( @@ -3595,12 +3579,20 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L PHPStan\Type\StringType::__set_state(array( )), 1 => + PHPStan\Type\StringType::__set_state(array( + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 3 => PHPStan\Type\IntegerRangeType::__set_state(array( 'min' => 0, 'max' => 4294967295, )), ), - 'nextAutoIndex' => 0, + 'nextAutoIndex' => 2, 'optionalKeys' => array ( ), @@ -3609,11 +3601,19 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L '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( 'value' => 'adaid', 'isClassString' => false, )), - 1 => + 3 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( 'value' => 'email', 'isClassString' => false, @@ -4588,6 +4588,182 @@ Simulated query: SELECT email, adaid FROM ada . WHERE email=\'my_other_table\' L ), )), )), + 3 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'nextAutoIndex' => 0, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), + 4 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + 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\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'nextAutoIndex' => 4, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + '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\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada ' => diff --git a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php index 5e1ff1fa1..09de92c2b 100644 --- a/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineResultDynamicReturnTypeExtension.php @@ -21,7 +21,7 @@ final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { - public const METHODS = [ + private const METHODS = [ 'columncount', 'fetchone', 'fetchfirstcolumn',