Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); refactor: fix types by kenjis · Pull Request #8091 · codeigniter4/CodeIgniter4 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/CLI/CLI.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1066,7 +1066,7 @@ public static function table(array $tbody, array $thead = [])

foreach ($tableRows[$row] as $col) {
// Sets the size of this column in the current row
$allColsLengths[$row][$column] = static::strlen($col);
$allColsLengths[$row][$column] = static::strlen((string) $col);

// If the current column does not have a value among the larger ones
// or the value of this is greater than the existing one
Expand All@@ -1086,7 +1086,7 @@ public static function table(array $tbody, array $thead = [])
$column = 0;

foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);
$diff = $maxColsLengths[$column] - static::strlen((string) $col);

if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
Expand All@@ -1106,7 +1106,7 @@ public static function table(array $tbody, array $thead = [])
$cols = '+';

foreach ($tableRows[$row] as $col) {
$cols .= str_repeat('-', static::strlen($col) + 2) . '+';
$cols .= str_repeat('-', static::strlen((string) $col) + 2) . '+';
}
$table .= $cols . PHP_EOL;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -744,7 +744,7 @@ protected function generateCacheName(Cache $config): string
? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
: '';

return md5($uri->setFragment('')->setQuery($query));
return md5((string) $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,7 +175,7 @@ public function execute(...$data)
// Let others do something with this query
Events::trigger('DBQuery', $query);

if ($this->db->isWriteType($query)) {
if ($this->db->isWriteType((string) $query)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -357,7 +357,7 @@ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, i
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}

$sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
$sql = substr_replace($sql, (string) $escapedValue, $matches[0][$c][1], $ml);
} while ($c !== 0);

return $sql;
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -898,7 +898,7 @@ protected function setDate()
{
$timezone = date('Z');
$operator = ($timezone[0] === '-') ? '-' : '+';
$timezone = abs($timezone);
$timezone = abs((int) $timezone);
$timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60;

return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp($value);
return Time::createFromTimestamp((int) $value);
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/Format/XMLFormatter.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,8 @@ protected function normalizeXMLTag($key)
'\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}';
$validName = $startChar . '\\.\\d\\x{B7}\\x{300}-\\x{36F}\\x{203F}-\\x{2040}';

$key = (string) $key;

$key = trim($key);
$key = preg_replace("/[^{$validName}-]+/u", '', $key);
$key = preg_replace("/^[^{$startChar}]+/u", 'item$0', $key);
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/Files/FileCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -185,7 +185,7 @@ protected function createFileObject(array $array)
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
($array['size'] ?? null) === null ? null : (int) $array['size'],
$array['error'] ?? null,
$array['full_path'] ?? null
);
Expand Down
18 changes: 9 additions & 9 deletions system/HTTP/ResponseInterface.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -320,15 +320,15 @@ public function sendBody();
* Accepts an arbitrary number of binds (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param array|string $name Cookie name or array containing binds
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
* @param array|Cookie|string $name Cookie name / array containing binds / Cookie object
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,7 +179,7 @@ function doctype(string $type = 'html5'): string
$config = new DocTypes();
$doctypes = $config->list;

return $doctypes[$type] ?? false;
return $doctypes[$type] ?? '';
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/number_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
// Strip any formatting & ensure numeric input
try {
// @phpstan-ignore-next-line
$num = 0 + str_replace(',', '', $num);
$num = 0 + str_replace(',', '', (string) $num);
} catch (ErrorException $ee) {
// Catch "Warning: A non-numeric value encountered"
return false;
Expand DownExpand Up@@ -142,7 +142,7 @@ function format_number(float $num, int $precision = 1, ?string $locale = null, a

// Try to format it per the locale
if ($type === NumberFormatter::CURRENCY) {
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $options['fraction']);
$formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, (float) $options['fraction']);
$output = $formatter->formatCurrency($num, $options['currency']);
} else {
// In order to specify a precision, we'll have to modify
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$digits = (int) $matches[1][$i];
$out = '';
if ($digits < 128) {
$out .= chr($digits);
Expand Down
16 changes: 8 additions & 8 deletions system/I18n/TimeTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -543,7 +543,7 @@ public function setYear($value)
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
throw I18nException::forInvalidMonth((string) $value);
}

if (is_string($value) && ! is_numeric($value)) {
Expand All@@ -565,13 +565,13 @@ public function setMonth($value)
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
throw I18nException::forInvalidDay((string) $value);
}

$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
throw I18nException::forInvalidOverDay($lastDay, (string) $value);
}

return $this->setValue('day', $value);
Expand All@@ -589,7 +589,7 @@ public function setDay($value)
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
throw I18nException::forInvalidHour((string) $value);
}

return $this->setValue('hour', $value);
Expand All@@ -607,7 +607,7 @@ public function setHour($value)
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
throw I18nException::forInvalidMinutes((string) $value);
}

return $this->setValue('minute', $value);
Expand All@@ -625,7 +625,7 @@ public function setMinute($value)
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
throw I18nException::forInvalidSeconds((string) $value);
}

return $this->setValue('second', $value);
Expand DownExpand Up@@ -1008,7 +1008,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTime());
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand DownExpand Up@@ -1109,7 +1109,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this);
return IntlCalendar::fromDateTime($this->toDateTime());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Images/Handlers/BaseHandler.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,12 +559,12 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);

if ($height === null) {
$height = ceil(($width / $cropWidth) * $cropHeight);
$height = (int) ceil(($width / $cropWidth) * $cropHeight);
}

[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);

return $this->crop($cropWidth, $cropHeight, $x, $y)->resize($width, $height);
return $this->crop($cropWidth, $cropHeight, (int) $x, (int) $y)->resize($width, $height);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1367,14 +1367,14 @@ protected function buildReverseRoute(string $from, array $params): string
// or maybe $placeholder is not a placeholder, but a regex.
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;

if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
if (! preg_match('#^' . $pattern . '$#u', (string) $params[$index])) {
throw RouterException::forInvalidParameterType();
}

// Ensure that the param we're inserting matches
// the expected param type.
$pos = strpos($from, $placeholder);
$from = substr_replace($from, $params[$index], $pos, strlen($placeholder));
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
}

$from = $this->replaceLocale($from, $locale);
Expand Down
4 changes: 3 additions & 1 deletion system/Router/Router.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -382,7 +382,9 @@ protected function checkRoutes(string $uri): bool
foreach ($routes as $routeKey => $handler) {
$routeKey = $routeKey === '/'
? $routeKey
: ltrim($routeKey, '/ ');
// $routeKey may be int, because it is an array key,
// and the URI `/1` is valid. The leading `/` is removed.
: ltrim((string) $routeKey, '/ ');

$matchedKey = $routeKey;

Expand Down
2 changes: 1 addition & 1 deletion system/View/Cell.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -209,7 +209,7 @@ final protected function renderCell(BaseCell $instance, string $method, array $p
$publicParams = array_intersect_key($params, $publicProperties);

foreach ($params as $key => $value) {
$getter = 'get' . ucfirst($key) . 'Property';
$getter = 'get' . ucfirst((string) $key) . 'Property';
if (in_array($key, $privateProperties, true) && method_exists($instance, $getter)) {
$publicParams[$key] = $value;
}
Expand Down
8 changes: 6 additions & 2 deletions system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,10 @@ public static function date($value, string $format): string
$value = strtotime($value);
}

if ($value !== null) {
$value = (int) $value;
}

return date($format, $value);
}

Expand DownExpand Up@@ -158,7 +162,7 @@ public static function local_number($value, string $type = 'decimal', int $preci
'duration' => NumberFormatter::DURATION,
];

return format_number($value, $precision, $locale, ['type' => $types[$type]]);
return format_number((float) $value, $precision, $locale, ['type' => $types[$type]]);
}

/**
Expand All@@ -179,7 +183,7 @@ public static function local_currency($value, string $currency, ?string $locale
'fraction' => $fraction,
];

return format_number($value, 2, $locale, $options);
return format_number((float) $value, 2, $locale, $options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/View/Parser.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,7 +619,7 @@ protected function applyFilters(string $replace, array $filters): string
$replace = $this->config->filters[$filter]($replace, ...$param);
}

return $replace;
return (string) $replace;
}

// Plugins
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/ClearDebugbarTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ protected function createDummyDebugbarJson(): void

// create 10 dummy debugbar json files
for ($i = 0; $i < 10; $i++) {
$path = str_replace($time, $time - $i, $path);
$path = str_replace((string) $time, (string) ($time - $i), $path);
file_put_contents($path, "{}\n");

$time -= $i;
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public function testRedirectResponseCookiesSent(): void

$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CommonFunctionsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -576,7 +576,7 @@ public function testRedirectResponseCookies1(): void

$answer1 = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'onething'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Debug/Toolbar/Collectors/HistoryTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ private function createDummyDebugbarJson(): void

// create 20 dummy debugbar json files
for ($i = 0; $i < 20; $i++) {
$path = str_replace($time, sprintf('%.6f', $time - self::STEP), $path);
$path = str_replace((string) $time, sprintf('%.6f', $time - self::STEP), $path);
file_put_contents($path, json_encode($dummyData));
$time = sprintf('%.6f', $time - self::STEP);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/system/HTTP/ResponseSendTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,9 +127,11 @@ public function testRedirectResponseCookies(): void

$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo', 'bar'));
$this->assertTrue($answer1->hasCookie('login_time'));

$response->setBody('Hello');

// send it
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,7 +551,7 @@ public function testRedirectResponseCookies(): void
$response = new Response(new App());
$answer1 = $response->redirect('/login')
->setCookie('foo', 'bar', YEAR)
->setCookie('login_time', $loginTime, YEAR);
->setCookie('login_time', (string) $loginTime, YEAR);

$this->assertTrue($answer1->hasCookie('foo'));
$this->assertTrue($answer1->hasCookie('login_time'));
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,10 +250,12 @@ public function testSameSiteParamArray(): void

public function testSameSiteParam(): void
{
set_cookie($this->name, $this->value, $this->expire, '', '', '', '', '', 'Strict');
set_cookie($this->name, $this->value, $this->expire, '', '', '', null, null, 'Strict');

$this->assertTrue($this->response->hasCookie($this->name));

$theCookie = $this->response->getCookie($this->name);

$this->assertSame('Strict', $theCookie->getSameSite());

delete_cookie($this->name);
Expand Down
Loading