diff --git a/src/Extensions/PdoQuoteDynamicReturnTypeExtension.php b/src/Extensions/PdoQuoteDynamicReturnTypeExtension.php index 0e0f75db..32348391 100644 --- a/src/Extensions/PdoQuoteDynamicReturnTypeExtension.php +++ b/src/Extensions/PdoQuoteDynamicReturnTypeExtension.php @@ -24,6 +24,13 @@ final class PdoQuoteDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { + // Values of PDO::PARAM_* constants, independent of the loaded extensions. + private const PARAM_INT = 1; + + private const PARAM_STR = 2; + + private const PARAM_BOOL = 5; + private PhpVersion $phpVersion; public function __construct(PhpVersion $phpVersion) @@ -77,7 +84,7 @@ private function inferType(MethodCall $methodCall, Scope $scope): ?Type $args = $methodCall->getArgs(); if (1 === \count($args)) { - $type = PDO::PARAM_STR; + $type = self::PARAM_STR; } else { $typeType = $scope->getType($args[1]->value); if (! $typeType instanceof ConstantIntegerType) { @@ -90,7 +97,7 @@ private function inferType(MethodCall $methodCall, Scope $scope): ?Type $stringType = $this->inferStringType($argType); // check for types which are supported by all drivers, therefore cannot return false. - if (PDO::PARAM_STR === $type || PDO::PARAM_INT === $type || PDO::PARAM_BOOL === $type) { + if (self::PARAM_STR === $type || self::PARAM_INT === $type || self::PARAM_BOOL === $type) { return $stringType; } diff --git a/src/PdoReflection/PdoStatementReflection.php b/src/PdoReflection/PdoStatementReflection.php index 53e84723..2f28c00d 100644 --- a/src/PdoReflection/PdoStatementReflection.php +++ b/src/PdoReflection/PdoStatementReflection.php @@ -4,7 +4,6 @@ namespace staabm\PHPStanDba\PdoReflection; -use PDO; use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; use PHPStan\Type\Constant\ConstantIntegerType; @@ -19,6 +18,21 @@ // XXX move into a "Reflection" package on next major version final class PdoStatementReflection { + // Values of PDO::FETCH_* constants, independent of the loaded extensions. + private const FETCH_ASSOC = 2; + + private const FETCH_NUM = 3; + + private const FETCH_BOTH = 4; + + private const FETCH_OBJ = 5; + + private const FETCH_COLUMN = 7; + + private const FETCH_CLASS = 8; + + private const FETCH_KEY_PAIR = 12; + // XXX move into separate class on next major version public function findPrepareQueryStringExpression(MethodCall $methodCall): ?Expr { @@ -57,17 +71,17 @@ public function getFetchType(Type $fetchModeType): ?int return null; } - if (PDO::FETCH_CLASS === $fetchModeType->getValue() || PDO::FETCH_OBJ === $fetchModeType->getValue()) { + if (self::FETCH_CLASS === $fetchModeType->getValue() || self::FETCH_OBJ === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_CLASS; - } elseif (PDO::FETCH_KEY_PAIR === $fetchModeType->getValue()) { + } elseif (self::FETCH_KEY_PAIR === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_KEY_VALUE; - } elseif (PDO::FETCH_ASSOC === $fetchModeType->getValue()) { + } elseif (self::FETCH_ASSOC === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_ASSOC; - } elseif (PDO::FETCH_NUM === $fetchModeType->getValue()) { + } elseif (self::FETCH_NUM === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_NUMERIC; - } elseif (PDO::FETCH_BOTH === $fetchModeType->getValue()) { + } elseif (self::FETCH_BOTH === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_BOTH; - } elseif (PDO::FETCH_COLUMN === $fetchModeType->getValue()) { + } elseif (self::FETCH_COLUMN === $fetchModeType->getValue()) { return QueryReflector::FETCH_TYPE_COLUMN; }