Skip to content

Commit f729426

Browse files
committed
Fix deprecated usages of null
1 parent 04f77b2 commit f729426

File tree

22 files changed

+210
-541
lines changed

22 files changed

+210
-541
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101

102102
- name: Install latest ImageMagick
103103
run: |
104+
sudo apt-get update
104105
sudo apt-get install --reinstall libgs9-common fonts-noto-mono libgs9:amd64 libijs-0.35:amd64 fonts-urw-base35 ghostscript poppler-data libjbig2dec0:amd64 gsfonts libopenjp2-7:amd64 fonts-droid-fallback ttf-dejavu-core
105106
sudo apt-get install -y imagemagick
106107
sudo apt-get install --fix-broken

app/Config/Mimes.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Config;
44

55
/**
6-
* Mimes
7-
*
86
* This file contains an array of mime types. It is used by the
97
* Upload class to help identify allowed file types.
108
*
@@ -509,15 +507,13 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
509507
{
510508
$type = trim(strtolower($type), '. ');
511509

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

514512
if ($proposedExtension !== '') {
515513
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {
516-
// The detected mime type matches with the proposed extension.
517514
return $proposedExtension;
518515
}
519516

520-
// An extension was proposed, but the media type does not match the mime type list.
521517
return null;
522518
}
523519

system/CLI/CLI.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,11 @@ 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.
870-
if (mb_strpos($value, ' ') !== false) {
871-
$out .= '"' . $value . '" ';
872-
} elseif ($value !== null) {
868+
if ($value === null) {
869+
$out .= '';
870+
} elseif (mb_strpos($value, ' ') !== false) {
871+
$out .= "\"{$value}\" ";
872+
} else {
873873
$out .= "{$value} ";
874874
}
875875
}

system/Database/BaseUtils.php

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313

1414
use CodeIgniter\Database\Exceptions\DatabaseException;
1515

16-
/**
17-
* Class BaseUtils
18-
*/
1916
abstract class BaseUtils
2017
{
2118
/**
22-
* Database object
23-
*
2419
* @var object
2520
*/
2621
protected $db;
@@ -46,24 +41,18 @@ abstract class BaseUtils
4641
*/
4742
protected $repairTable = false;
4843

49-
/**
50-
* Class constructor
51-
*/
5244
public function __construct(ConnectionInterface &$db)
5345
{
5446
$this->db = &$db;
5547
}
5648

5749
/**
58-
* List databases
59-
*
6050
* @throws DatabaseException
6151
*
6252
* @return array|bool
6353
*/
6454
public function listDatabases()
6555
{
66-
// Is there a cached result?
6756
if (isset($this->db->dataCache['db_names'])) {
6857
return $this->db->dataCache['db_names'];
6958
}
@@ -79,6 +68,7 @@ public function listDatabases()
7968
$this->db->dataCache['db_names'] = [];
8069

8170
$query = $this->db->query($this->listDatabases);
71+
8272
if ($query === false) {
8373
return $this->db->dataCache['db_names'];
8474
}
@@ -90,17 +80,12 @@ public function listDatabases()
9080
return $this->db->dataCache['db_names'];
9181
}
9282

93-
/**
94-
* Determine if a particular database exists
95-
*/
9683
public function databaseExists(string $databaseName): bool
9784
{
9885
return in_array($databaseName, $this->listDatabases(), true);
9986
}
10087

10188
/**
102-
* Optimize Table
103-
*
10489
* @throws DatabaseException
10590
*
10691
* @return bool
@@ -121,8 +106,6 @@ public function optimizeTable(string $tableName)
121106
}
122107

123108
/**
124-
* Optimize Database
125-
*
126109
* @throws DatabaseException
127110
*
128111
* @return mixed
@@ -145,17 +128,16 @@ public function optimizeDatabase()
145128
return $res;
146129
}
147130

148-
// Build the result array...
149-
150131
$res = $res->getResultArray();
151132

152-
// Postgre & SQLite3 returns empty array
153133
if (empty($res)) {
134+
// Postgre & SQLite3 returns empty array
154135
$key = $tableName;
155136
} else {
156137
$res = current($res);
157138
$key = str_replace($this->db->database . '.', '', current($res));
158139
$keys = array_keys($res);
140+
159141
unset($res[$keys[0]]);
160142
}
161143

@@ -166,8 +148,6 @@ public function optimizeDatabase()
166148
}
167149

168150
/**
169-
* Repair Table
170-
*
171151
* @throws DatabaseException
172152
*
173153
* @return mixed
@@ -183,6 +163,7 @@ public function repairTable(string $tableName)
183163
}
184164

185165
$query = $this->db->query(sprintf($this->repairTable, $this->db->escapeIdentifiers($tableName)));
166+
186167
if (is_bool($query)) {
187168
return $query;
188169
}
@@ -193,26 +174,23 @@ public function repairTable(string $tableName)
193174
}
194175

195176
/**
196-
* Generate CSV from a query result object
197-
*
198177
* @return string
199178
*/
200179
public function getCSVFromResult(ResultInterface $query, string $delim = ',', string $newline = "\n", string $enclosure = '"')
201180
{
202181
$out = '';
203-
// First generate the headings from the table column names
182+
204183
foreach ($query->getFieldNames() as $name) {
205184
$out .= $enclosure . str_replace($enclosure, $enclosure . $enclosure, $name) . $enclosure . $delim;
206185
}
207186

208187
$out = substr($out, 0, -strlen($delim)) . $newline;
209188

210-
// Next blast through the result array and build out the rows
211189
while ($row = $query->getUnbufferedRow('array')) {
212190
$line = [];
213191

214192
foreach ($row as $item) {
215-
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item) . $enclosure;
193+
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
216194
}
217195

218196
$out .= implode($delim, $line) . $newline;
@@ -221,9 +199,6 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
221199
return $out;
222200
}
223201

224-
/**
225-
* Generate XML data from a query result object
226-
*/
227202
public function getXMLFromResult(ResultInterface $query, array $params = []): string
228203
{
229204
foreach (['root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t"] as $key => $val) {
@@ -256,8 +231,6 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
256231
}
257232

258233
/**
259-
* Database Backup
260-
*
261234
* @param array|string $params
262235
*
263236
* @throws DatabaseException
@@ -274,7 +247,7 @@ public function backup($params = [])
274247
'tables' => [],
275248
'ignore' => [],
276249
'filename' => '',
277-
'format' => 'gzip', // gzip, txt
250+
'format' => 'gzip',
278251
'add_drop' => true,
279252
'add_insert' => true,
280253
'newline' => "\n",

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 (! empty($port) && ctype_digit($port)) {
440+
$this->DSN .= "port={$port} ";
438441
}
439442

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

system/Filters/Filters.php

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

400-
$uri = strtolower(trim($uri, '/ '));
400+
$uri = strtolower(trim((string) $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])) {
407+
410408
// look at each alias in the group
411409
foreach ($this->config->globals[$set] as $alias => $rules) {
412410
$keep = true;
411+
413412
if (is_array($rules)) {
414-
// see if it should be excluded
415413
if (isset($rules['except'])) {
416-
// grab the exclusion rules
417414
$check = $rules['except'];
415+
418416
if ($this->pathApplies($uri, $check)) {
419417
$keep = false;
420418
}

system/HTTP/CLIRequest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ 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.
144-
if (mb_strpos($value, ' ') !== false) {
145-
$out .= '"' . $value . '" ';
146-
} elseif ($value !== null) {
142+
if ($value === null) {
143+
$out .= '';
144+
} elseif (mb_strpos($value, ' ') !== false) {
145+
$out .= "\"{$value}\" ";
146+
} else {
147147
$out .= "{$value} ";
148148
}
149149
}

system/HTTP/CURLRequest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ public function put(string $url, array $options = []): ResponseInterface
227227
*/
228228
public function setAuth(string $username, string $password, string $type = 'basic')
229229
{
230-
$this->config['auth'] = [
231-
$username,
232-
$password,
233-
$type,
234-
];
230+
$this->config['auth'] = [$username, $password, $type];
235231

236232
return $this;
237233
}
@@ -305,14 +301,12 @@ protected function parseOptions(array $options)
305301
*/
306302
protected function prepareURL(string $url): string
307303
{
308-
// If it's a full URI, then we have nothing to do here...
309304
if (strpos($url, '://') !== false) {
310305
return $url;
311306
}
312307

313308
$uri = $this->baseURI->resolveRelativeURI($url);
314309

315-
// Create the string instead of casting to prevent baseURL muddling
316310
return URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery(), $uri->getFragment());
317311
}
318312

@@ -324,7 +318,7 @@ protected function prepareURL(string $url): string
324318
*/
325319
public function getMethod(bool $upper = false): string
326320
{
327-
return ($upper) ? strtoupper($this->method) : strtolower($this->method);
321+
return $upper ? strtoupper($this->method) : strtolower($this->method);
328322
}
329323

330324
/**
@@ -421,12 +415,10 @@ protected function applyMethod(string $method, array $curlOptions): array
421415
{
422416
$method = strtoupper($method);
423417

424-
$this->method = $method;
425-
$curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
418+
$this->method = $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
426419

427-
$size = strlen($this->body);
420+
$size = strlen((string) $this->body);
428421

429-
// Have content?
430422
if ($size > 0) {
431423
return $this->applyBody($curlOptions);
432424
}

system/HTTP/ResponseTrait.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use InvalidArgumentException;
2323

2424
/**
25-
* Request Trait
26-
*
2725
* Additional methods to make a PSR-7 Response class
2826
* compliant with the framework's own ResponseInterface.
2927
*
@@ -435,7 +433,7 @@ public function send()
435433
if ($this->CSPEnabled === true) {
436434
$this->CSP->finalize($this);
437435
} else {
438-
$this->body = str_replace(['{csp-style-nonce}', '{csp-script-nonce}'], '', $this->body);
436+
$this->body = str_replace(['{csp-style-nonce}', '{csp-script-nonce}'], '', (string) $this->body);
439437
}
440438

441439
$this->sendHeaders();

system/Helpers/number_helper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,20 @@
1717
/**
1818
* Formats a numbers as bytes, based on size, and adds the appropriate suffix
1919
*
20-
* @param mixed $num Will be cast as int
21-
* @param string $locale
20+
* @param mixed $num
2221
*
2322
* @return bool|string
2423
*/
2524
function number_to_size($num, int $precision = 1, ?string $locale = null)
2625
{
27-
// Strip any formatting & ensure numeric input
2826
try {
2927
$num = 0 + str_replace(',', '', $num);
3028
} catch (ErrorException $ee) {
3129
return false;
3230
}
3331

34-
// ignore sub part
3532
$generalLocale = $locale;
33+
3634
if (! empty($locale) && ($underscorePos = strpos($locale, '_'))) {
3735
$generalLocale = substr($locale, 0, $underscorePos);
3836
}

0 commit comments

Comments
 (0)