Skip to content

Commit b967d9e

Browse files
authored
Add compatibility for strict types (#4548)
1 parent ddb6d87 commit b967d9e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

system/Debug/Toolbar.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
use CodeIgniter\Format\JSONFormatter;
1919
use CodeIgniter\Format\XMLFormatter;
2020
use CodeIgniter\HTTP\DownloadResponse;
21+
use CodeIgniter\HTTP\IncomingRequest;
2122
use CodeIgniter\HTTP\RequestInterface;
23+
use CodeIgniter\HTTP\Response;
2224
use CodeIgniter\HTTP\ResponseInterface;
2325
use Config\Services;
2426
use Config\Toolbar as ToolbarConfig;
@@ -84,6 +86,11 @@ public function __construct(ToolbarConfig $config)
8486
*/
8587
public function run(float $startTime, float $totalTime, RequestInterface $request, ResponseInterface $response): string
8688
{
89+
/**
90+
* @var IncomingRequest $request
91+
* @var Response $response
92+
*/
93+
8794
// Data items used within the view.
8895
$data['url'] = current_url();
8996
$data['method'] = $request->getMethod(true);
@@ -295,6 +302,11 @@ protected function roundTo(float $number, int $increments = 5): float
295302
*/
296303
public function prepare(RequestInterface $request = null, ResponseInterface $response = null)
297304
{
305+
/**
306+
* @var IncomingRequest $request
307+
* @var Response $response
308+
*/
309+
298310
if (CI_DEBUG && ! is_cli())
299311
{
300312
global $app;
@@ -437,8 +449,8 @@ protected function format(string $data, string $format = 'html'): string
437449
{
438450
$history = new History();
439451
$history->setFiles(
440-
Services::request()->getGet('debugbar_time'),
441-
$this->config->maxHistory
452+
(int) Services::request()->getGet('debugbar_time'),
453+
$this->config->maxHistory
442454
);
443455

444456
$data['collectors'][] = $history->getAsArray();

system/View/Parser.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ protected function replaceSingle($pattern, $content, $template, bool $escape = f
570570
{
571571
// Any dollar signs in the pattern will be misinterpreted, so slash them
572572
$pattern = addcslashes($pattern, '$');
573+
$content = (string) $content;
573574

574575
// Flesh out the main pattern from the delimiters and escape the hash
575576
// See https://regex101.com/r/IKdUlk/1
@@ -579,17 +580,15 @@ protected function replaceSingle($pattern, $content, $template, bool $escape = f
579580
}
580581

581582
// Replace the content in the template
582-
$template = preg_replace_callback($pattern, function ($matches) use ($content, $escape) {
583+
return preg_replace_callback($pattern, function ($matches) use ($content, $escape) {
583584
// Check for {! !} syntax to not escape this one.
584585
if (strpos($matches[0], '{!') === 0 && substr($matches[0], -2) === '!}')
585586
{
586587
$escape = false;
587588
}
588589

589590
return $this->prepareReplacement($matches, $content, $escape);
590-
}, $template);
591-
592-
return $template;
591+
}, (string) $template);
593592
}
594593

595594
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)