Skip to content

Commit cc8154f

Browse files
authored
Merge pull request #3565 from samsonasik/in_array_strict
apply strict in_array with pass true to 3rd parameter
2 parents 04ed220 + d2aecef commit cc8154f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+88
-88
lines changed

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ protected function format($data = null)
390390
$format = "application/$this->format";
391391

392392
// Determine correct response type through content negotiation if not explicitly declared
393-
if (empty($this->format) || ! in_array($this->format, ['json', 'xml']))
393+
if (empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
394394
{
395395
$format = $this->request->negotiate('media', $config->supportedResponseFormats, false);
396396
}

system/Commands/Database/MigrateStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function run(array $params)
136136
// Loop for all $namespaces
137137
foreach ($namespaces as $namespace => $path)
138138
{
139-
if (in_array($namespace, $this->ignoredNamespaces))
139+
if (in_array($namespace, $this->ignoredNamespaces, true))
140140
{
141141
continue;
142142
}

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ function esc($data, string $context = 'html', string $encoding = null)
467467
return $data;
468468
}
469469

470-
if (! in_array($context, ['html', 'js', 'css', 'url', 'attr']))
470+
if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true))
471471
{
472472
throw new InvalidArgumentException('Invalid escape context provided.');
473473
}

system/Config/BaseService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected static function discoverServices(string $name, array $arguments)
267267
{
268268
$classname = $locator->getClassname($file);
269269

270-
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
270+
if (! in_array($classname, ['CodeIgniter\\Config\\Services'], true))
271271
{
272272
static::$services[] = new $classname();
273273
}

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ protected function maxMinAvgSum(string $select = '', string $alias = '', string
513513

514514
$type = strtoupper($type);
515515

516-
if (! in_array($type, ['MAX', 'MIN', 'AVG', 'SUM', 'COUNT']))
516+
if (! in_array($type, ['MAX', 'MIN', 'AVG', 'SUM', 'COUNT'], true))
517517
{
518518
throw new DatabaseException('Invalid function type: ' . $type);
519519
}

system/Database/BaseConnection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public function setAliasedTables(array $aliases)
602602
*/
603603
public function addTableAlias(string $table)
604604
{
605-
if (! in_array($table, $this->aliasedTables))
605+
if (! in_array($table, $this->aliasedTables, true))
606606
{
607607
$this->aliasedTables[] = $table;
608608
}
@@ -1171,13 +1171,13 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
11711171
//
11721172
// NOTE: The ! empty() condition prevents this method
11731173
// from breaking when QB isn't enabled.
1174-
if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables))
1174+
if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables, true))
11751175
{
11761176
if ($protectIdentifiers === true)
11771177
{
11781178
foreach ($parts as $key => $val)
11791179
{
1180-
if (! in_array($val, $this->reservedIdentifiers))
1180+
if (! in_array($val, $this->reservedIdentifiers, true))
11811181
{
11821182
$parts[$key] = $this->escapeIdentifiers($val);
11831183
}
@@ -1262,7 +1262,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
12621262
}
12631263
}
12641264

1265-
if ($protectIdentifiers === true && ! in_array($item, $this->reservedIdentifiers))
1265+
if ($protectIdentifiers === true && ! in_array($item, $this->reservedIdentifiers, true))
12661266
{
12671267
$item = $this->escapeIdentifiers($item);
12681268
}
@@ -1283,7 +1283,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
12831283
*/
12841284
public function escapeIdentifiers($item)
12851285
{
1286-
if ($this->escapeChar === '' || empty($item) || in_array($item, $this->reservedIdentifiers))
1286+
if ($this->escapeChar === '' || empty($item) || in_array($item, $this->reservedIdentifiers, true))
12871287
{
12881288
return $item;
12891289
}
@@ -1587,7 +1587,7 @@ public function listTables(bool $constrainByPrefix = false)
15871587
*/
15881588
public function tableExists(string $tableName): bool
15891589
{
1590-
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables());
1590+
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true);
15911591
}
15921592

15931593
//--------------------------------------------------------------------
@@ -1662,7 +1662,7 @@ public function getFieldNames(string $table)
16621662
*/
16631663
public function fieldExists(string $fieldName, string $tableName): bool
16641664
{
1665-
return in_array($fieldName, $this->getFieldNames($tableName));
1665+
return in_array($fieldName, $this->getFieldNames($tableName), true);
16661666
}
16671667

16681668
//--------------------------------------------------------------------

system/Database/BaseUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function listDatabases()
139139
*/
140140
public function databaseExists(string $database_name): bool
141141
{
142-
return in_array($database_name, $this->listDatabases());
142+
return in_array($database_name, $this->listDatabases(), true);
143143
}
144144

145145
//--------------------------------------------------------------------

system/Database/Forge.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ protected function _processIndexes(string $table)
12561256
continue;
12571257
}
12581258

1259-
if (in_array($i, $this->uniqueKeys))
1259+
if (in_array($i, $this->uniqueKeys, true))
12601260
{
12611261
$sqls[] = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table)
12621262
. ' ADD CONSTRAINT ' . $this->db->escapeIdentifiers($table . '_' . implode('_', $this->keys[$i]))
@@ -1302,12 +1302,12 @@ protected function _processForeignKeys(string $table): string
13021302
$sql .= ",\n\tCONSTRAINT " . $this->db->escapeIdentifiers($name_index)
13031303
. ' FOREIGN KEY(' . $this->db->escapeIdentifiers($field) . ') REFERENCES ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')';
13041304

1305-
if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions))
1305+
if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true))
13061306
{
13071307
$sql .= ' ON DELETE ' . $fkey['onDelete'];
13081308
}
13091309

1310-
if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions))
1310+
if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true))
13111311
{
13121312
$sql .= ' ON UPDATE ' . $fkey['onUpdate'];
13131313
}

system/Database/MigrationRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function regress(int $targetBatch = 0, string $group = null)
293293
}
294294

295295
// Make sure $targetBatch is found
296-
if ($targetBatch !== 0 && ! in_array($targetBatch, $batches))
296+
if ($targetBatch !== 0 && ! in_array($targetBatch, $batches, true))
297297
{
298298
$message = lang('Migrations.batchNotFound') . $targetBatch;
299299

system/Database/MySQLi/Forge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function _createTableAttributes(array $attributes): string
136136
{
137137
$sql .= ' ' . strtoupper($key) . ' = ';
138138

139-
if (in_array(strtoupper($key), $this->_quoted_table_options))
139+
if (in_array(strtoupper($key), $this->_quoted_table_options, true))
140140
{
141141
$sql .= $this->db->escape($attributes[$key]);
142142
}
@@ -265,7 +265,7 @@ protected function _processIndexes(string $table): string
265265
// @phpstan-ignore-next-line
266266
is_array($this->keys[$i]) || $this->keys[$i] = [$this->keys[$i]];
267267

268-
$unique = in_array($i, $this->uniqueKeys) ? 'UNIQUE ' : '';
268+
$unique = in_array($i, $this->uniqueKeys, true) ? 'UNIQUE ' : '';
269269

270270
$sql .= ",\n\t{$unique}KEY " . $this->db->escapeIdentifiers(implode('_', $this->keys[$i]))
271271
. ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i])) . ')';

system/Database/SQLite3/Forge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected function _processIndexes(string $table): array
234234
continue;
235235
}
236236

237-
if (in_array($i, $this->uniqueKeys))
237+
if (in_array($i, $this->uniqueKeys, true))
238238
{
239239
$sqls[] = 'CREATE UNIQUE INDEX ' . $this->db->escapeIdentifiers($table . '_' . implode('_', $this->keys[$i]))
240240
. ' ON ' . $this->db->escapeIdentifiers($table)

system/Debug/Exceptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function exceptionHandler(Throwable $exception)
150150
] = $this->determineCodes($exception);
151151

152152
// Log it
153-
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes))
153+
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true))
154154
{
155155
log_message('critical', $exception->getMessage() . "\n{trace}", [
156156
'trace' => $exception->getTraceAsString(),
@@ -219,7 +219,7 @@ public function shutdownHandler()
219219
if (! is_null($error))
220220
{
221221
// Fatal Error?
222-
if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]))
222+
if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE], true))
223223
{
224224
$this->exceptionHandler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
225225
}

system/Email/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ public function setPriority($n = 3)
813813
*/
814814
public function setNewline($newline = "\n")
815815
{
816-
$this->newline = in_array($newline, ["\n", "\r\n", "\r"]) ? $newline : "\n";
816+
$this->newline = in_array($newline, ["\n", "\r\n", "\r"], true) ? $newline : "\n";
817817
return $this;
818818
}
819819
//--------------------------------------------------------------------
@@ -860,7 +860,7 @@ protected function getProtocol()
860860
*/
861861
protected function getEncoding()
862862
{
863-
in_array($this->encoding, $this->bitDepths) || $this->encoding = '8bit'; // @phpstan-ignore-line
863+
in_array($this->encoding, $this->bitDepths, true) || $this->encoding = '8bit'; // @phpstan-ignore-line
864864
foreach ($this->baseCharsets as $charset)
865865
{
866866
if (strpos($this->charset, $charset) === 0)

system/Encryption/Encryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function initialize(EncryptionConfig $config = null)
140140
}
141141

142142
// Check for an unknown driver
143-
if (! in_array($this->driver, $this->drivers))
143+
if (! in_array($this->driver, $this->drivers, true))
144144
{
145145
throw EncryptionException::forUnKnownHandler($this->driver);
146146
}

system/Entity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function __get(string $key)
331331
}
332332

333333
// Do we need to mutate this into a date?
334-
if (in_array($key, $this->dates))
334+
if (in_array($key, $this->dates, true))
335335
{
336336
$result = $this->mutateDate($result);
337337
}
@@ -366,7 +366,7 @@ public function __set(string $key, $value = null)
366366
$key = $this->mapProperty($key);
367367

368368
// Check if the field should be mutated into a date
369-
if (in_array($key, $this->dates))
369+
if (in_array($key, $this->dates, true))
370370
{
371371
$value = $this->mutateDate($value);
372372
}
@@ -623,7 +623,7 @@ private function castAsJson($value, bool $asArray = false)
623623
$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
624624
if (function_exists('json_decode'))
625625
{
626-
if ((is_string($value) && strlen($value) > 1 && in_array($value[0], ['[', '{', '"'])) || is_numeric($value))
626+
if ((is_string($value) && strlen($value) > 1 && in_array($value[0], ['[', '{', '"'], true)) || is_numeric($value))
627627
{
628628
$tmp = json_decode($value, $asArray);
629629

system/Format/JSONFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function format($data)
6666

6767
$result = json_encode($data, $options, 512);
6868

69-
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION]))
69+
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true))
7070
{
7171
throw FormatException::forInvalidJSON(json_last_error_msg());
7272
}

system/HTTP/ContentSecurityPolicy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ protected function addToHeader(string $name, $values = null)
819819

820820
if ($reportOnly === true)
821821
{
822-
$reportSources[] = in_array($value, $this->validSources) ? "'{$value}'" : $value;
822+
$reportSources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
823823
}
824824
else
825825
{
@@ -829,7 +829,7 @@ protected function addToHeader(string $name, $values = null)
829829
}
830830
else
831831
{
832-
$sources[] = in_array($value, $this->validSources) ? "'{$value}'" : $value;
832+
$sources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
833833
}
834834
}
835835
}

system/HTTP/IncomingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function setLocale(string $locale)
246246
{
247247
// If it's not a valid locale, set it
248248
// to the default locale for the site.
249-
if (! in_array($locale, $this->validLocales))
249+
if (! in_array($locale, $this->validLocales, true))
250250
{
251251
$locale = $this->defaultLocale;
252252
}

system/HTTP/Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Message
7878
protected $validProtocolVersions = [
7979
'1.0',
8080
'1.1',
81-
'2',
81+
'2.0',
8282
];
8383

8484
/**
@@ -379,7 +379,7 @@ public function setProtocolVersion(string $version)
379379
$version = substr($version, strpos($version, '/') + 1);
380380
}
381381

382-
if (! in_array($version, $this->validProtocolVersions))
382+
if (! in_array($version, $this->validProtocolVersions, true))
383383
{
384384
throw HTTPException::forInvalidHTTPProtocol(implode(', ', $this->validProtocolVersions));
385385
}

system/HTTP/URI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ public function stripQuery(...$params)
896896
* Filters the query variables so that only the keys passed in
897897
* are kept. The rest are removed from the object.
898898
*
899-
* @param array ...$params
899+
* @param string ...$params
900900
*
901901
* @return $this
902902
*/
@@ -906,7 +906,7 @@ public function keepQuery(...$params)
906906

907907
foreach ($this->query as $key => $value)
908908
{
909-
if (! in_array($key, $params))
909+
if (! in_array($key, $params, true))
910910
{
911911
continue;
912912
}

system/Helpers/form_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
102102
$before = Services::filters()
103103
->getFilters()['before'];
104104

105-
if ((in_array('csrf', $before) || array_key_exists('csrf', $before)) && strpos($action, base_url()) !== false && ! stripos($form, 'method="get"'))
105+
if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && strpos($action, base_url()) !== false && ! stripos($form, 'method="get"'))
106106
{
107107
$form .= csrf_field($csrfId ?? null);
108108
}
@@ -423,7 +423,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
423423
$form .= '<optgroup label="' . $key . "\">\n";
424424
foreach ($val as $optgroup_key => $optgroup_val)
425425
{
426-
$sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
426+
$sel = in_array($optgroup_key, $selected, true) ? ' selected="selected"' : '';
427427
$form .= '<option value="' . htmlspecialchars($optgroup_key) . '"' . $sel . '>'
428428
. $optgroup_val . "</option>\n";
429429
}
@@ -432,7 +432,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
432432
else
433433
{
434434
$form .= '<option value="' . htmlspecialchars($key) . '"'
435-
. (in_array($key, $selected) ? ' selected="selected"' : '') . '>'
435+
. (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
436436
. $val . "</option>\n";
437437
}
438438
}

system/Helpers/html_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/c
323323

324324
$link .= 'rel="' . $rel . '" ';
325325

326-
if (! in_array($rel, ['alternate', 'canonical']))
326+
if (! in_array($rel, ['alternate', 'canonical'], true))
327327
{
328328
$link .= 'type="' . $type . '" ';
329329
}

system/Helpers/inflector_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function is_pluralizable(string $word): bool
339339
'weather',
340340
'wisdom',
341341
'work',
342-
]);
342+
], true);
343343

344344
return ! $uncountables;
345345
}

system/Images/Handlers/BaseHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ public function rotate(float $angle)
361361
{
362362
// Allowed rotation values
363363
$degs = [
364-
90,
365-
180,
366-
270,
364+
90.0,
365+
180.0,
366+
270.0,
367367
];
368368

369-
if (! in_array($angle, $degs))
369+
if (! in_array($angle, $degs, true))
370370
{
371371
throw ImageException::forMissingAngle();
372372
}

system/Images/Handlers/ImageMagickHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ protected function supportedFormatCheck()
388388
switch ($this->image()->imageType)
389389
{
390390
case IMAGETYPE_WEBP:
391-
if (! in_array('WEBP', \Imagick::queryFormats()))
391+
if (! in_array('WEBP', \Imagick::queryFormats(), true))
392392
{
393393
throw ImageException::forInvalidImageCreate(lang('images.webpNotSupported'));
394394
}

system/Language/Language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected function load(string $file, string $locale, bool $return = false)
295295
$this->loadedFiles[$locale] = [];
296296
}
297297

298-
if (in_array($file, $this->loadedFiles[$locale]))
298+
if (in_array($file, $this->loadedFiles[$locale], true))
299299
{
300300
// Don't load it more than once.
301301
return [];

0 commit comments

Comments
 (0)