2525 * @method string quote(mixed $string, int $parameterType = PDO::PARAM_STR)
2626 * @method mixed setAttribute(int $attribute, mixed $value)
2727 *
28- * @phpstan-type dsnArgs array{
29- * dsn: string,
30- * username?: string,
31- * password?: string,
32- * options?: array<int, mixed>
33- * }
34- *
35- * @phpstan-type logEntryType array{
36- * start: float,
37- * finish: ?float,
38- * duration: ?float,
39- * performed: ?bool,
40- * statement: ?string,
41- * values: array<array-key, mixed>,
42- * trace: ?string,
43- * connection?: string
44- * }
28+ * @phpstan-import-type dsn_args_array from PdoCustomTypes
29+ * @phpstan-import-type log_entry_array from PdoCustomTypes
30+ * @phpstan-import-type fetch_assoc_array from PdoCustomTypes
31+ * @phpstan-import-type fetch_string_mixed_array from PdoCustomTypes
4532 */
4633class Connection
4734{
@@ -51,7 +38,7 @@ static public function new(mixed ...$args) : Connection
5138 return new static ($ args [0 ]);
5239 }
5340
54- /** @var dsnArgs $args */
41+ /** @var dsn_args_array $args */
5542 return new static (new PDO (...$ args ));
5643 }
5744
@@ -75,7 +62,7 @@ static public function factory(mixed ...$args) : callable
7562
7663 public function __construct (protected PDO $ pdo )
7764 {
78- $ this ->persistent = (bool )$ this ->pdo ->getAttribute (PDO ::ATTR_PERSISTENT );
65+ $ this ->persistent = (bool ) $ this ->pdo ->getAttribute (PDO ::ATTR_PERSISTENT );
7966 }
8067
8168 public function __call (
@@ -153,7 +140,7 @@ public function prepare(
153140 $ sth = PersistentLoggedStatement::new (
154141 $ sth ,
155142 function (array $ entry ) : void {
156- /** @var logEntryType $entry */
143+ /** @var log_entry_array $entry */
157144 $ this ->addLogEntry ($ entry );
158145 },
159146 $ this ->newLogEntry ()
@@ -178,6 +165,13 @@ public function perform(
178165 return $ sth ;
179166 }
180167
168+ /**
169+ * @param PDOStatement $sth
170+ * @param int|string $name
171+ * @param mixed $args
172+ *
173+ * @return void
174+ */
181175 protected function performBind (
182176 PDOStatement $ sth ,
183177 mixed $ name ,
@@ -190,7 +184,6 @@ protected function performBind(
190184 }
191185
192186 if (! is_array ($ args )) {
193- /** @var int|string $name */
194187 $ sth ->bindValue ($ name , $ args );
195188 return ;
196189 }
@@ -201,7 +194,6 @@ protected function performBind(
201194 $ args [0 ] = $ args [0 ] ? '1 ' : '0 ' ;
202195 }
203196
204- /** @var int|string $name */
205197 $ sth ->bindValue ($ name , ...$ args );
206198 }
207199
@@ -286,10 +278,10 @@ public function fetchObject(
286278 /**
287279 * @template T of object
288280 * *
289- * @param string $statement
290- * @param array $values
291- * @param class-string<T> $class
292- * @param array<mixed> ...$args
281+ * @param string $statement
282+ * @param array $values
283+ * @param class-string<T> $class
284+ * @param callable|int|string ...$args
293285 *
294286 * @return array|false
295287 */
@@ -301,17 +293,22 @@ public function fetchObjects(
301293 ) : array |false
302294 {
303295 $ sth = $ this ->perform ($ statement , $ values );
304- /** @var array<array-key, callable|int|string> $args */
305296 return $ sth ->fetchAll (PDO ::FETCH_CLASS , $ class , ...$ args );
306297 }
307298
299+ /**
300+ * @param string $statement
301+ * @param array $values
302+ *
303+ * @return fetch_assoc_array|false
304+ */
308305 public function fetchOne (
309306 string $ statement ,
310307 array $ values = []
311308 ) : array |false
312309 {
313310 $ sth = $ this ->perform ($ statement , $ values );
314- /** @var array<array-key, mixed> $result */
311+ /** @var fetch_assoc_array $result */
315312 $ result = $ sth ->fetch (PDO ::FETCH_ASSOC );
316313
317314 return $ result ;
@@ -358,7 +355,7 @@ public function yieldUnique(
358355 $ sth = $ this ->perform ($ statement , $ values );
359356
360357 while ($ row = $ sth ->fetch (PDO ::FETCH_UNIQUE )) {
361- /** @var array<string, mixed> $row */
358+ /** @var fetch_string_mixed_array $row */
362359 $ key = array_shift ($ row );
363360 yield $ key => $ row ;
364361 }
@@ -437,7 +434,7 @@ public function logQueries(bool $logQueries = true) : void
437434 LoggedStatement::CLASS ,
438435 [
439436 function (array $ entry ) : void {
440- /** @var logEntryType $entry */
437+ /** @var log_entry_array $entry */
441438 $ this ->addLogEntry ($ entry );
442439 },
443440 $ this ->newLogEntry ()
@@ -458,7 +455,7 @@ public function setQueryLogger(callable $queryLogger) : void
458455 /**
459456 * @param string|null $statement
460457 *
461- * @return logEntryType
458+ * @return log_entry_array
462459 */
463460 protected function newLogEntry (?string $ statement = null ) : array
464461 {
@@ -474,7 +471,7 @@ protected function newLogEntry(?string $statement = null) : array
474471 }
475472
476473 /**
477- * @param logEntryType $entry
474+ * @param log_entry_array $entry
478475 *
479476 * @return void
480477 */
0 commit comments