Skip to content
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
11 changes: 9 additions & 2 deletions src/Extensions/PdoQuoteDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
28 changes: 21 additions & 7 deletions src/PdoReflection/PdoStatementReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace staabm\PHPStanDba\PdoReflection;

use PDO;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Type\Constant\ConstantIntegerType;
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down
Loading