Skip to content

Commit 4c50b10

Browse files
committed
Fix deprecated usage of null on string params of internal functions
1 parent 8b01f90 commit 4c50b10

File tree

15 files changed

+78
-143
lines changed

15 files changed

+78
-143
lines changed

app/Config/Mimes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
509509
{
510510
$type = trim(strtolower($type), '. ');
511511

512-
$proposedExtension = trim(strtolower($proposedExtension));
512+
$proposedExtension = trim(strtolower($proposedExtension ?? ''));
513513

514514
if ($proposedExtension !== '') {
515515
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {

system/CLI/CLI.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,12 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f
865865
$out .= "-{$name} ";
866866
}
867867

868-
// If there's a space, we need to group
869-
// so it will pass correctly.
868+
if ($value === null) {
869+
continue;
870+
}
871+
870872
if (mb_strpos($value, ' ') !== false) {
871-
$out .= '"' . $value . '" ';
873+
$out .= "\"{$value}\" ";
872874
} elseif ($value !== null) {
873875
$out .= "{$value} ";
874876
}

system/Database/BaseUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function repairTable(string $tableName)
200200
public function getCSVFromResult(ResultInterface $query, string $delim = ',', string $newline = "\n", string $enclosure = '"')
201201
{
202202
$out = '';
203-
// First generate the headings from the table column names
203+
204204
foreach ($query->getFieldNames() as $name) {
205205
$out .= $enclosure . str_replace($enclosure, $enclosure . $enclosure, $name) . $enclosure . $delim;
206206
}
@@ -212,7 +212,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
212212
$line = [];
213213

214214
foreach ($row as $item) {
215-
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item) . $enclosure;
215+
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
216216
}
217217

218218
$out .= implode($delim, $line) . $newline;

system/Database/Forge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public function dropKey(string $table, string $keyName)
462462
public function dropForeignKey(string $table, string $foreignName)
463463
{
464464
$sql = sprintf(
465-
$this->dropConstraintStr,
465+
(string) $this->dropConstraintStr,
466466
$this->db->escapeIdentifiers($this->db->DBPrefix . $table),
467467
$this->db->escapeIdentifiers($this->db->DBPrefix . $foreignName)
468468
);

system/Database/Postgre/Connection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ protected function buildDSN()
433433
$this->DSN = "host={$this->hostname} ";
434434
}
435435

436-
if (! empty($this->port) && ctype_digit($this->port)) {
437-
$this->DSN .= "port={$this->port} ";
436+
// ctype_digit only accepts strings
437+
$port = (string) $this->port;
438+
439+
if ($port !== '' && ctype_digit($port)) {
440+
$this->DSN .= "port={$port} ";
438441
}
439442

440443
if ($this->username !== '') {

system/Filters/Filters.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,10 @@ protected function processGlobals(?string $uri = null)
397397
return;
398398
}
399399

400-
$uri = strtolower(trim($uri, '/ '));
400+
$uri = strtolower(trim($uri ?? '', '/ '));
401401

402402
// Add any global filters, unless they are excluded for this URI
403-
$sets = [
404-
'before',
405-
'after',
406-
];
403+
$sets = ['before', 'after'];
407404

408405
foreach ($sets as $set) {
409406
if (isset($this->config->globals[$set])) {

system/HTTP/CLIRequest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ public function getOptionString(bool $useLongOpts = false): string
139139
$out .= "-{$name} ";
140140
}
141141

142-
// If there's a space, we need to group
143-
// so it will pass correctly.
142+
if ($value === null) {
143+
continue;
144+
}
145+
144146
if (mb_strpos($value, ' ') !== false) {
145147
$out .= '"' . $value . '" ';
146-
} elseif ($value !== null) {
148+
} else {
147149
$out .= "{$value} ";
148150
}
149151
}

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ protected function applyMethod(string $method, array $curlOptions): array
424424
$this->method = $method;
425425
$curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
426426

427-
$size = strlen($this->body);
427+
$size = strlen($this->body ?? '');
428428

429429
// Have content?
430430
if ($size > 0) {

system/HTTP/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function send()
435435
if ($this->CSPEnabled === true) {
436436
$this->CSP->finalize($this);
437437
} else {
438-
$this->body = str_replace(['{csp-style-nonce}', '{csp-script-nonce}'], '', $this->body);
438+
$this->body = str_replace(['{csp-style-nonce}', '{csp-script-nonce}'], '', $this->body ?? '');
439439
}
440440

441441
$this->sendHeaders();

system/I18n/Time.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,23 @@ class Time extends DateTime
7575
*/
7676
public function __construct(?string $time = null, $timezone = null, ?string $locale = null)
7777
{
78-
// If no locale was provided, grab it from Locale (set by IncomingRequest for web requests)
79-
$this->locale = ! empty($locale) ? $locale : Locale::getDefault();
78+
$this->locale = $locale ?: Locale::getDefault();
8079

81-
// If a test instance has been provided, use it instead.
82-
if ($time === null && static::$testNow instanceof self) {
83-
if (empty($timezone)) {
84-
$timezone = static::$testNow->getTimezone();
85-
}
80+
$time = $time ?? '';
8681

87-
$time = static::$testNow->toDateTimeString();
82+
// If a test instance has been provided, use it instead.
83+
if ($time === '' && static::$testNow instanceof self) {
84+
$timezone = $timezone ?: static::$testNow->getTimezone();
85+
$time = (string) static::$testNow->toDateTimeString();
8886
}
8987

90-
$timezone = ! empty($timezone) ? $timezone : date_default_timezone_get();
88+
$timezone = $timezone ?: date_default_timezone_get();
9189
$this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
9290

9391
// If the time string was a relative string (i.e. 'next Tuesday')
9492
// then we need to adjust the time going in so that we have a current
9593
// timezone to work with.
96-
if (! empty($time) && (is_string($time) && static::hasRelativeKeywords($time))) {
94+
if ($time !== '' && static::hasRelativeKeywords($time)) {
9795
$instance = new DateTime('now', $this->timezone);
9896
$instance->modify($time);
9997
$time = $instance->format('Y-m-d H:i:s');

0 commit comments

Comments
 (0)