Skip to content

Commit af181f0

Browse files
authored
[12.x] Add types to the \Illuminate\Database\Connection class (laravel#56459)
* Type $handler callable in Connection::whenQueryingForLongerThan() * Properly type $queryDurationHandlers as list of a associative arrays * Type rest of the Connection class
1 parent 3da6005 commit af181f0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class Connection implements ConnectionInterface
3838
/**
3939
* The active PDO connection.
4040
*
41-
* @var \PDO|\Closure
41+
* @var \PDO|(\Closure(): \PDO)
4242
*/
4343
protected $pdo;
4444

4545
/**
4646
* The active PDO connection used for reads.
4747
*
48-
* @var \PDO|\Closure
48+
* @var \PDO|(\Closure(): \PDO)
4949
*/
5050
protected $readPdo;
5151

@@ -80,7 +80,7 @@ class Connection implements ConnectionInterface
8080
/**
8181
* The reconnector instance for the connection.
8282
*
83-
* @var callable
83+
* @var (callable(\Illuminate\Database\Connection): mixed)
8484
*/
8585
protected $reconnector;
8686

@@ -150,7 +150,7 @@ class Connection implements ConnectionInterface
150150
/**
151151
* All of the queries run against the connection.
152152
*
153-
* @var array
153+
* @var array{query: string, bindings: array, time: float|null}[]
154154
*/
155155
protected $queryLog = [];
156156

@@ -171,7 +171,7 @@ class Connection implements ConnectionInterface
171171
/**
172172
* All of the registered query duration handlers.
173173
*
174-
* @var array
174+
* @var array{has_run: bool, handler: (callable(\Illuminate\Database\Connection, class-string<\Illuminate\Database\Events\QueryExecuted>): mixed)}[]
175175
*/
176176
protected $queryDurationHandlers = [];
177177

@@ -192,7 +192,7 @@ class Connection implements ConnectionInterface
192192
/**
193193
* All of the callbacks that should be invoked before a query is executed.
194194
*
195-
* @var \Closure[]
195+
* @var (\Closure(string, array, \Illuminate\Database\Connection): mixed)[]
196196
*/
197197
protected $beforeExecutingCallbacks = [];
198198

@@ -206,7 +206,7 @@ class Connection implements ConnectionInterface
206206
/**
207207
* Create a new database connection instance.
208208
*
209-
* @param \PDO|\Closure $pdo
209+
* @param \PDO|(\Closure(): \PDO) $pdo
210210
* @param string $database
211211
* @param string $tablePrefix
212212
* @param array $config
@@ -638,8 +638,8 @@ public function threadCount()
638638
/**
639639
* Execute the given callback in "dry run" mode.
640640
*
641-
* @param \Closure $callback
642-
* @return array
641+
* @param (\Closure(\Illuminate\Database\Connection): mixed) $callback
642+
* @return array{query: string, bindings: array, time: float|null}[]
643643
*/
644644
public function pretend(Closure $callback)
645645
{
@@ -681,8 +681,8 @@ public function withoutPretending(Closure $callback)
681681
/**
682682
* Execute the given callback in "dry run" mode.
683683
*
684-
* @param \Closure $callback
685-
* @return array
684+
* @param (\Closure(): array{query: string, bindings: array, time: float|null}[]) $callback
685+
* @return array{query: string, bindings: array, time: float|null}[]
686686
*/
687687
protected function withFreshQueryLog($callback)
688688
{
@@ -876,7 +876,7 @@ protected function getElapsedTime($start)
876876
* Register a callback to be invoked when the connection queries for longer than a given amount of time.
877877
*
878878
* @param \DateTimeInterface|\Carbon\CarbonInterval|float|int $threshold
879-
* @param callable $handler
879+
* @param (callable(\Illuminate\Database\Connection, class-string<\Illuminate\Database\Events\QueryExecuted>): mixed) $handler
880880
* @return void
881881
*/
882882
public function whenQueryingForLongerThan($threshold, $handler)
@@ -1307,7 +1307,7 @@ public function setReadPdo($pdo)
13071307
/**
13081308
* Set the reconnect instance on the connection.
13091309
*
1310-
* @param callable $reconnector
1310+
* @param (callable(\Illuminate\Database\Connection): mixed) $reconnector
13111311
* @return $this
13121312
*/
13131313
public function setReconnector(callable $reconnector)
@@ -1506,7 +1506,7 @@ public function pretending()
15061506
/**
15071507
* Get the connection query log.
15081508
*
1509-
* @return array
1509+
* @return array{query: string, bindings: array, time: float|null}[]
15101510
*/
15111511
public function getQueryLog()
15121512
{

0 commit comments

Comments
 (0)