Skip to content

Commit 5ff2df0

Browse files
committed
Merge branch 'develop' into 4.7
2 parents 3f2a434 + a19b44c commit 5ff2df0

31 files changed

+378
-818
lines changed

app/Config/Logger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeIgniter\Config\BaseConfig;
66
use CodeIgniter\Log\Handlers\FileHandler;
7+
use CodeIgniter\Log\Handlers\HandlerInterface;
78

89
class Logger extends BaseConfig
910
{
@@ -73,7 +74,7 @@ class Logger extends BaseConfig
7374
* Handlers are executed in the order defined in this array, starting with
7475
* the handler on top and continuing down.
7576
*
76-
* @var array<class-string, array<string, int|list<string>|string>>
77+
* @var array<class-string<HandlerInterface>, array<string, int|list<string>|string>>
7778
*/
7879
public array $handlers = [
7980
/*

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpcov": "^9.0.2 || ^10.0",
2929
"phpunit/phpunit": "^10.5.16 || ^11.2",
3030
"predis/predis": "^3.0",
31-
"rector/rector": "2.0.16",
31+
"rector/rector": "2.0.17",
3232
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3333
},
3434
"replace": {

system/API/ResponseTrait.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@
1313

1414
namespace CodeIgniter\API;
1515

16+
use CodeIgniter\Format\Format;
1617
use CodeIgniter\Format\FormatterInterface;
1718
use CodeIgniter\HTTP\IncomingRequest;
19+
use CodeIgniter\HTTP\RequestInterface;
1820
use CodeIgniter\HTTP\ResponseInterface;
1921

2022
/**
2123
* Provides common, more readable, methods to provide
2224
* consistent HTTP responses under a variety of common
2325
* situations when working as an API.
2426
*
25-
* @property bool $stringAsHtml Whether to treat string data as HTML in JSON response.
26-
* Setting `true` is only for backward compatibility.
27+
* @property RequestInterface $request
28+
* @property ResponseInterface $response
29+
* @property bool $stringAsHtml Whether to treat string data as HTML in JSON response.
30+
* Setting `true` is only for backward compatibility.
2731
*/
2832
trait ResponseTrait
2933
{
@@ -84,7 +88,7 @@ trait ResponseTrait
8488
* Provides a single, simple method to return an API response, formatted
8589
* to match the requested format, with proper content-type and status code.
8690
*
87-
* @param array|string|null $data
91+
* @param array<string, mixed>|string|null $data
8892
*
8993
* @return ResponseInterface
9094
*/
@@ -118,9 +122,9 @@ protected function respond($data = null, ?int $status = null, string $message =
118122
/**
119123
* Used for generic failures that no custom methods exist for.
120124
*
121-
* @param array|string $messages
122-
* @param int $status HTTP status code
123-
* @param string|null $code Custom, API-specific, error code
125+
* @param list<string>|string $messages
126+
* @param int $status HTTP status code
127+
* @param string|null $code Custom, API-specific, error code
124128
*
125129
* @return ResponseInterface
126130
*/
@@ -146,7 +150,7 @@ protected function fail($messages, int $status = 400, ?string $code = null, stri
146150
/**
147151
* Used after successfully creating a new resource.
148152
*
149-
* @param array|string|null $data
153+
* @param array<string, mixed>|string|null $data
150154
*
151155
* @return ResponseInterface
152156
*/
@@ -158,7 +162,7 @@ protected function respondCreated($data = null, string $message = '')
158162
/**
159163
* Used after a resource has been successfully deleted.
160164
*
161-
* @param array|string|null $data
165+
* @param array<string, mixed>|string|null $data
162166
*
163167
* @return ResponseInterface
164168
*/
@@ -170,7 +174,7 @@ protected function respondDeleted($data = null, string $message = '')
170174
/**
171175
* Used after a resource has been successfully updated.
172176
*
173-
* @param array|string|null $data
177+
* @param array<string, mixed>|string|null $data
174178
*
175179
* @return ResponseInterface
176180
*/
@@ -287,15 +291,17 @@ protected function failServerError(string $description = 'Internal Server Error'
287291
* Handles formatting a response. Currently, makes some heavy assumptions
288292
* and needs updating! :)
289293
*
290-
* @param array|string|null $data
294+
* @param array<string, mixed>|string|null $data
291295
*
292296
* @return string|null
293297
*/
294298
protected function format($data = null)
295299
{
300+
/** @var Format $format */
296301
$format = service('format');
297302

298-
$mime = ($this->format === null) ? $format->getConfig()->supportedResponseFormats[0]
303+
$mime = $this->format === null
304+
? $format->getConfig()->supportedResponseFormats[0]
299305
: "application/{$this->format}";
300306

301307
// Determine correct response type through content negotiation if not explicitly declared
@@ -313,14 +319,10 @@ protected function format($data = null)
313319
$this->response->setContentType($mime);
314320

315321
// if we don't have a formatter, make one
316-
if (! isset($this->formatter)) {
317-
// if no formatter, use the default
318-
$this->formatter = $format->getFormatter($mime);
319-
}
322+
$this->formatter ??= $format->getFormatter($mime);
320323

321324
$asHtml = $this->stringAsHtml ?? false;
322325

323-
// Returns as HTML.
324326
if (
325327
($mime === 'application/json' && $asHtml && is_string($data))
326328
|| ($mime !== 'application/json' && is_string($data))
@@ -338,6 +340,7 @@ protected function format($data = null)
338340
if ($mime !== 'application/json') {
339341
// Recursively convert objects into associative arrays
340342
// Conversion not required for JSONFormatter
343+
/** @var array<string, mixed>|string|null $data */
341344
$data = json_decode(json_encode($data), true);
342345
}
343346

@@ -353,7 +356,7 @@ protected function format($data = null)
353356
*/
354357
protected function setResponseFormat(?string $format = null)
355358
{
356-
$this->format = ($format === null) ? null : strtolower($format);
359+
$this->format = $format === null ? null : strtolower($format);
357360

358361
return $this;
359362
}

system/Cache/Handlers/FileHandler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function isSupported(): bool
217217

218218
/**
219219
* Does the heavy lifting of actually retrieving the file and
220-
* verifying it's age.
220+
* verifying its age.
221221
*
222222
* @return array{data: mixed, ttl: int, time: int}|false
223223
*/
@@ -227,7 +227,17 @@ protected function getItem(string $filename)
227227
return false;
228228
}
229229

230-
$data = @unserialize(file_get_contents($this->path . $filename));
230+
$content = @file_get_contents($this->path . $filename);
231+
232+
if ($content === false) {
233+
return false;
234+
}
235+
236+
try {
237+
$data = unserialize($content);
238+
} catch (Throwable) {
239+
return false;
240+
}
231241

232242
if (! is_array($data)) {
233243
return false;

system/Debug/Toolbar/Collectors/Logs.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ class Logs extends BaseCollector
4545
/**
4646
* Our collected data.
4747
*
48-
* @var array
48+
* @var list<array{level: string, msg: string}>
4949
*/
5050
protected $data;
5151

5252
/**
53-
* Returns the data of this collector to be formatted in the toolbar
53+
* Returns the data of this collector to be formatted in the toolbar.
54+
*
55+
* @return array{logs: list<array{level: string, msg: string}>}
5456
*/
5557
public function display(): array
5658
{
@@ -66,7 +68,7 @@ public function isEmpty(): bool
6668
{
6769
$this->collectLogs();
6870

69-
return empty($this->data);
71+
return $this->data !== [];
7072
}
7173

7274
/**
@@ -82,14 +84,18 @@ public function icon(): string
8284
/**
8385
* Ensures the data has been collected.
8486
*
85-
* @return array
87+
* @return list<array{level: string, msg: string}>
8688
*/
8789
protected function collectLogs()
8890
{
89-
if (! empty($this->data)) {
91+
if ($this->data !== []) {
9092
return $this->data;
9193
}
9294

93-
return $this->data = service('logger', true)->logCache ?? [];
95+
$cache = service('logger')->logCache;
96+
97+
$this->data = $cache ?? [];
98+
99+
return $this->data;
94100
}
95101
}

0 commit comments

Comments
 (0)