Skip to content

Commit bddecda

Browse files
committed
Fix deprecated usages of null
1 parent fcd2d80 commit bddecda

File tree

24 files changed

+275
-688
lines changed

24 files changed

+275
-688
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
@@ -399,24 +399,22 @@ protected function processGlobals(?string $uri = null)
399399
return;
400400
}
401401

402-
$uri = strtolower(trim($uri, '/ '));
402+
$uri = strtolower(trim((string) $uri, '/ '));
403403

404404
// Add any global filters, unless they are excluded for this URI
405-
$sets = [
406-
'before',
407-
'after',
408-
];
405+
$sets = ['before', 'after'];
409406

410407
foreach ($sets as $set) {
411408
if (isset($this->config->globals[$set])) {
409+
412410
// look at each alias in the group
413411
foreach ($this->config->globals[$set] as $alias => $rules) {
414412
$keep = true;
413+
415414
if (is_array($rules)) {
416-
// see if it should be excluded
417415
if (isset($rules['except'])) {
418-
// grab the exclusion rules
419416
$check = $rules['except'];
417+
420418
if ($this->pathApplies($uri, $check)) {
421419
$keep = false;
422420
}

system/HTTP/CLIRequest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use RuntimeException;
1616

1717
/**
18-
* Class CLIRequest
19-
*
2018
* Represents a request from the command-line. Provides additional
2119
* tools to interact with that request since CLI requests are not
2220
* static like HTTP requests might be.
@@ -141,11 +139,11 @@ public function getOptionString(bool $useLongOpts = false): string
141139
$out .= "-{$name} ";
142140
}
143141

144-
// If there's a space, we need to group
145-
// so it will pass correctly.
146-
if (mb_strpos($value, ' ') !== false) {
147-
$out .= '"' . $value . '" ';
148-
} elseif ($value !== null) {
142+
if ($value === null) {
143+
$out .= '';
144+
} elseif (mb_strpos($value, ' ') !== false) {
145+
$out .= "\"{$value}\" ";
146+
} else {
149147
$out .= "{$value} ";
150148
}
151149
}
@@ -172,17 +170,17 @@ protected function parseCommand()
172170
if ($optionValue) {
173171
$optionValue = false;
174172
} else {
175-
$this->segments[] = filter_var($arg, FILTER_SANITIZE_STRING);
173+
$this->segments[] = esc(strip_tags($arg));
176174
}
177175

178176
continue;
179177
}
180178

181-
$arg = filter_var(ltrim($arg, '-'), FILTER_SANITIZE_STRING);
179+
$arg = esc(strip_tags(ltrim($arg, '-')));
182180
$value = null;
183181

184182
if (isset($args[$i + 1]) && mb_strpos($args[$i + 1], '-') !== 0) {
185-
$value = filter_var($args[$i + 1], FILTER_SANITIZE_STRING);
183+
$value = esc(strip_tags($args[$i + 1]));
186184
$optionValue = true;
187185
}
188186

0 commit comments

Comments
 (0)