Skip to content

Commit

Permalink
Fixed PDO::query() parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 8, 2017
1 parent 098221f commit 06fc09d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
Expand Down Expand Up @@ -123,6 +124,33 @@ public function getParameters(): array
true
);
}

if (
$this->declaringClass->getName() === 'PDO'
&& $this->reflection->getName() === 'query'
&& count($this->parameters) < 4
) {
$this->parameters[] = new DummyParameter(
'statement',
new StringType(false),
false
);
$this->parameters[] = new DummyParameter(
'fetchColumn',
new IntegerType(false),
true
);
$this->parameters[] = new DummyParameter(
'colno',
new MixedType(),
true
);
$this->parameters[] = new DummyParameter(
'constructorArgs',
new ArrayType(new MixedType(), false),
true
);
}
}

return $this->parameters;
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function testCallMethods()
'Call to an undefined method ArrayObject::doFoo().',
104,
],
[
'Method PDO::query() invoked with 0 parameters, 1-4 required.',
109,
],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Methods/data/call-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ private function returnsVoid()
$arrayOfStdClass = new \ArrayObject([new \stdClass()]);
$arrayOfStdClass->doFoo();
};

$g = function () {
$pdo = new \PDO('dsn', 'username', 'password');
$pdo->query();
$pdo->query('statement');
};

0 comments on commit 06fc09d

Please sign in to comment.