Skip to content

Commit 92008b3

Browse files
authored
refactor: fix phpstan errors in Debug (#10478)
1 parent d9ee179 commit 92008b3

20 files changed

Lines changed: 151 additions & 278 deletions

system/Debug/BaseExceptionHandler.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ abstract public function handle(
7070

7171
/**
7272
* Gathers the variables that will be made available to the view.
73+
*
74+
* @return array{
75+
* title: string,
76+
* type: string,
77+
* code: int,
78+
* message: string,
79+
* file: string,
80+
* line: int,
81+
* trace: list<array<string, mixed>>,
82+
* }
7383
*/
7484
protected function collectVars(Throwable $exception, int $statusCode): array
7585
{
@@ -99,6 +109,11 @@ protected function collectVars(Throwable $exception, int $statusCode): array
99109

100110
/**
101111
* Mask sensitive data in the trace.
112+
*
113+
* @param list<array<string, mixed>> $trace
114+
* @param list<string> $keysToMask
115+
*
116+
* @return list<array<string, mixed>>
102117
*/
103118
protected function maskSensitiveData(array $trace, array $keysToMask, string $path = ''): array
104119
{
@@ -110,9 +125,10 @@ protected function maskSensitiveData(array $trace, array $keysToMask, string $pa
110125
}
111126

112127
/**
113-
* @param array|object $args
128+
* @param array<array-key, mixed>|object $args
129+
* @param list<string> $keysToMask
114130
*
115-
* @return array|object
131+
* @return array<array-key, mixed>|object
116132
*/
117133
private function maskData($args, array $keysToMask, string $path = '')
118134
{

system/Debug/Exceptions.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ protected function render(Throwable $exception, int $statusCode)
355355
/**
356356
* Gathers the variables that will be made available to the view.
357357
*
358+
* @return array{title: string, type: string, code: int, message: string, file: string, line: int, trace: list<array<string, mixed>>}
359+
*
358360
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
359361
*/
360362
protected function collectVars(Throwable $exception, int $statusCode): array
@@ -386,9 +388,10 @@ protected function collectVars(Throwable $exception, int $statusCode): array
386388
/**
387389
* Mask sensitive data in the trace.
388390
*
389-
* @param array $trace
391+
* @param list<array<string, mixed>> $trace
392+
* @param list<string> $keysToMask
390393
*
391-
* @return array
394+
* @return list<array<string, mixed>>
392395
*
393396
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
394397
*/
@@ -402,9 +405,10 @@ protected function maskSensitiveData($trace, array $keysToMask, string $path = '
402405
}
403406

404407
/**
405-
* @param array|object $args
408+
* @param array<array-key, mixed>|object $args
409+
* @param list<string> $keysToMask
406410
*
407-
* @return array|object
411+
* @return array<array-key, mixed>|object
408412
*
409413
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
410414
*/
@@ -441,6 +445,8 @@ private function maskData($args, array $keysToMask, string $path = '')
441445

442446
/**
443447
* Determines the HTTP status code and the exit status code for this request.
448+
*
449+
* @return array{int, int}
444450
*/
445451
protected function determineCodes(Throwable $exception): array
446452
{

system/Debug/Iterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Iterator
2323
/**
2424
* Stores the tests that we are to run.
2525
*
26-
* @var array
26+
* @var array<string, Closure(): mixed>
2727
*/
2828
protected $tests = [];
2929

3030
/**
3131
* Stores the results of each of the tests.
3232
*
33-
* @var array
33+
* @var array<string, array{time: float, memory: int, n: int}>
3434
*/
3535
protected $results = [];
3636

system/Debug/Timer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Timer
2828
/**
2929
* List of all timers.
3030
*
31-
* @var array
31+
* @var array<string, array{start: float, end: float|null}>
3232
*/
3333
protected $timers = [];
3434

@@ -107,6 +107,8 @@ public function getElapsedTime(string $name, int $decimals = 4)
107107
* Returns the array of timers, with the duration pre-calculated for you.
108108
*
109109
* @param int $decimals Number of decimal places
110+
*
111+
* @return array<string, array{start: float, end: float, duration: float}>
110112
*/
111113
public function getTimers(int $decimals = 4): array
112114
{

system/Debug/Toolbar.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques
190190

191191
/**
192192
* Called within the view to display the timeline itself.
193+
*
194+
* @param list<array{hasTimelineData: bool, timelineData: list<array<string, mixed>>}> $collectors
195+
* @param array<string, string> $styles
193196
*/
194197
protected function renderTimeline(array $collectors, float $startTime, int $segmentCount, int $segmentDuration, array &$styles): string
195198
{
@@ -202,6 +205,9 @@ protected function renderTimeline(array $collectors, float $startTime, int $segm
202205

203206
/**
204207
* Recursively renders timeline elements and their children.
208+
*
209+
* @param list<array<string, mixed>> $rows
210+
* @param array<string, string> $styles
205211
*/
206212
protected function renderTimelineRecursive(array $rows, float $startTime, int $segmentCount, int $segmentDuration, array &$styles, int &$styleCount, int $level = 0, bool $isChild = false): string
207213
{
@@ -268,7 +274,9 @@ protected function renderTimelineRecursive(array $rows, float $startTime, int $s
268274
/**
269275
* Returns a sorted array of timeline data arrays from the collectors.
270276
*
271-
* @param array $collectors
277+
* @param list<array{hasTimelineData: bool, timelineData: list<array<string, mixed>>}> $collectors
278+
*
279+
* @return list<array<string, mixed>>
272280
*/
273281
protected function collectTimelineData($collectors): array
274282
{
@@ -305,6 +313,10 @@ protected function collectTimelineData($collectors): array
305313

306314
/**
307315
* Arranges the already sorted timeline data into a parent => child structure.
316+
*
317+
* @param list<array<string, mixed>> $elements
318+
*
319+
* @return list<array<string, mixed>>
308320
*/
309321
protected function structureTimelineData(array $elements): array
310322
{
@@ -333,6 +345,8 @@ protected function structureTimelineData(array $elements): array
333345
/**
334346
* Returns an array of data from all of the modules
335347
* that should be displayed in the 'Vars' tab.
348+
*
349+
* @return array<string, mixed>
336350
*/
337351
protected function collectVarData(): array
338352
{

system/Debug/Toolbar/Collectors/BaseCollector.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public function hasTimelineData(): bool
105105
/**
106106
* Grabs the data for the timeline, properly formatted,
107107
* or returns an empty array.
108+
*
109+
* @return list<array<string, mixed>>
108110
*/
109111
public function timelineData(): array
110112
{
@@ -140,7 +142,7 @@ public function hasVarData(): bool
140142
* ],
141143
* ];
142144
*
143-
* @return array|null
145+
* @return array<string, mixed>|null
144146
*/
145147
public function getVarData()
146148
{
@@ -159,6 +161,8 @@ public function getVarData()
159161
* 'start' => 10 // milliseconds
160162
* 'duration' => 15 // milliseconds
161163
* ]
164+
*
165+
* @return list<array<string, mixed>>
162166
*/
163167
protected function formatTimelineData(): array
164168
{
@@ -168,7 +172,7 @@ protected function formatTimelineData(): array
168172
/**
169173
* Returns the data of this collector to be formatted in the toolbar
170174
*
171-
* @return array|string
175+
* @return array<string, mixed>|string
172176
*/
173177
public function display()
174178
{
@@ -218,6 +222,20 @@ public function icon(): string
218222

219223
/**
220224
* Return settings as an array.
225+
*
226+
* @return array{
227+
* title: string,
228+
* titleSafe: string,
229+
* titleDetails: string,
230+
* display: array<string, mixed>|string,
231+
* badgeValue: int|null,
232+
* isEmpty: bool,
233+
* hasTabContent: bool,
234+
* hasLabel: bool,
235+
* icon: string,
236+
* hasTimelineData: bool,
237+
* timelineData: list<array<string, mixed>>,
238+
* }
221239
*/
222240
public function getAsArray(): array
223241
{

system/Debug/Toolbar/Collectors/Config.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ class Config
2323
{
2424
/**
2525
* Return toolbar config values as an array.
26+
*
27+
* @return array{
28+
* ciVersion: string,
29+
* phpVersion: string,
30+
* phpSAPI: string,
31+
* environment: string,
32+
* baseURL: string,
33+
* timezone: string,
34+
* locale: string,
35+
* cspEnabled: bool,
36+
* }
2637
*/
2738
public static function display(): array
2839
{

system/Debug/Toolbar/Collectors/Database.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CodeIgniter\Debug\Toolbar\Collectors;
1515

16+
use CodeIgniter\Database\BaseConnection;
1617
use CodeIgniter\Database\Query;
1718
use CodeIgniter\I18n\Time;
1819
use Config\Toolbar;
@@ -55,15 +56,15 @@ class Database extends BaseCollector
5556
/**
5657
* Array of database connections.
5758
*
58-
* @var array
59+
* @var array<string, BaseConnection>
5960
*/
6061
protected $connections;
6162

6263
/**
6364
* The query instances that have been collected
6465
* through the DBQuery Event.
6566
*
66-
* @var array
67+
* @var list<array{query: Query, string: string, duplicate: bool, trace: list<array<string, mixed>>}>
6768
*/
6869
protected static $queries = [];
6970

@@ -113,7 +114,13 @@ public static function collect(Query $query)
113114
/**
114115
* Returns timeline data formatted for the toolbar.
115116
*
116-
* @return array The formatted data or an empty array.
117+
* @return list<array{
118+
* name: string,
119+
* component: string,
120+
* start: float|string|null,
121+
* duration: string,
122+
* query?: string,
123+
* }>
117124
*/
118125
protected function formatTimelineData(): array
119126
{
@@ -144,6 +151,16 @@ protected function formatTimelineData(): array
144151

145152
/**
146153
* Returns the data of this collector to be formatted in the toolbar
154+
*
155+
* @return array{queries: list<array{
156+
* hover: string,
157+
* class: string,
158+
* duration: string,
159+
* sql: string,
160+
* trace: list<array<string, mixed>>,
161+
* trace-file: string,
162+
* qid: string
163+
* }>}
147164
*/
148165
public function display(): array
149166
{

system/Debug/Toolbar/Collectors/Events.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Events extends BaseCollector
5353
/**
5454
* Child classes should implement this to return the timeline data
5555
* formatted for correct usage.
56+
*
57+
* @return list<array{name: string, component: string, start: float, duration: float}>
5658
*/
5759
protected function formatTimelineData(): array
5860
{
@@ -74,6 +76,8 @@ protected function formatTimelineData(): array
7476

7577
/**
7678
* Returns the data of this collector to be formatted in the toolbar
79+
*
80+
* @return array{events: array<string, array{event: string, duration: string, count: int}>}
7781
*/
7882
public function display(): array
7983
{

system/Debug/Toolbar/Collectors/Files.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function getTitleDetails(): string
5252

5353
/**
5454
* Returns the data of this collector to be formatted in the toolbar
55+
*
56+
* @return array{coreFiles: list<array{path: string, name: string}>, userFiles: list<array{path: string, name: string}>}
5557
*/
5658
public function display(): array
5759
{

0 commit comments

Comments
 (0)