From faef7cf0cc79155b5073c7d7e780b3f0e5537e62 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 24 Jan 2024 21:56:55 +0100 Subject: [PATCH 1/2] Connection: Add var type hint to help pghpstan --- src/Connection.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index de84c72..c26fbf1 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -72,14 +72,19 @@ public function __call($name, array $arguments) { $this->connect(); - if (! method_exists($this->pdo, $name)) { + /** @var PDO $pdo */ + $pdo = $this->pdo; + if (! method_exists($pdo, $name)) { $class = get_class($this); $message = "Call to undefined method $class::$name"; throw new BadMethodCallException($message); } - return call_user_func_array([$this->pdo, $name], $arguments); + /** @var callable $callback */ + $callback = [$this->pdo, $name]; + + return call_user_func_array($callback, $arguments); } /** @@ -211,7 +216,7 @@ public function ping($reconnect = true) * @param Select|string $stmt The SQL statement to prepare and execute. * @param array $values Values to bind to the statement * - * @return array + * @return array|false */ public function fetchAll($stmt, array $values = null) { @@ -225,7 +230,7 @@ public function fetchAll($stmt, array $values = null) * @param Select|string $stmt The SQL statement to prepare and execute. * @param array $values Values to bind to the statement * - * @return array + * @return array|false */ public function fetchCol($stmt, array $values = null) { @@ -264,7 +269,7 @@ public function fetchRow($stmt, array $values = null) * @param Select|string $stmt The SQL statement to prepare and execute. * @param array $values Values to bind to the statement * - * @return array + * @return array|false */ public function fetchPairs($stmt, array $values = null) { From c5c36105c996ad0fee1200b6398e1dd53b5939a9 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 24 Jan 2024 21:57:15 +0100 Subject: [PATCH 2/2] Update phpstan baseline --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5107fd0..21778f7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -240,11 +240,6 @@ parameters: count: 1 path: src/Connection.php - - - message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{PDO\\|null, string\\} given\\.$#" - count: 1 - path: src/Connection.php - - message: "#^Parameter \\#1 \\$condition of method ipl\\\\Sql\\\\Delete\\:\\:where\\(\\) expects array\\|ipl\\\\Sql\\\\ExpressionInterface\\|ipl\\\\Sql\\\\Select\\|string, mixed given\\.$#" count: 1 @@ -260,11 +255,6 @@ parameters: count: 1 path: src/Connection.php - - - message: "#^Parameter \\#1 \\$object_or_class of function method_exists expects object\\|string, PDO\\|null given\\.$#" - count: 1 - path: src/Connection.php - - message: "#^Parameter \\#2 \\$className of method PDOStatement\\:\\:setFetchMode\\(\\) expects int\\|object\\|string, mixed given\\.$#" count: 1