Skip to content

apply strict in_array with pass true to 3rd parameter #3565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 30, 2020
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
2 changes: 1 addition & 1 deletion system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ protected function format($data = null)
$format = "application/$this->format";

// Determine correct response type through content negotiation if not explicitly declared
if (empty($this->format) || ! in_array($this->format, ['json', 'xml']))
if (empty($this->format) || ! in_array($this->format, ['json', 'xml'], true))
{
$format = $this->request->negotiate('media', $config->supportedResponseFormats, false);
}
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/MigrateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function run(array $params)
// Loop for all $namespaces
foreach ($namespaces as $namespace => $path)
{
if (in_array($namespace, $this->ignoredNamespaces))
if (in_array($namespace, $this->ignoredNamespaces, true))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function esc($data, string $context = 'html', string $encoding = null)
return $data;
}

if (! in_array($context, ['html', 'js', 'css', 'url', 'attr']))
if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true))
{
throw new InvalidArgumentException('Invalid escape context provided.');
}
Expand Down
2 changes: 1 addition & 1 deletion system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ protected static function discoverServices(string $name, array $arguments)
{
$classname = $locator->getClassname($file);

if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
if (! in_array($classname, ['CodeIgniter\\Config\\Services'], true))
{
static::$services[] = new $classname();
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ protected function maxMinAvgSum(string $select = '', string $alias = '', string

$type = strtoupper($type);

if (! in_array($type, ['MAX', 'MIN', 'AVG', 'SUM', 'COUNT']))
if (! in_array($type, ['MAX', 'MIN', 'AVG', 'SUM', 'COUNT'], true))
{
throw new DatabaseException('Invalid function type: ' . $type);
}
Expand Down
14 changes: 7 additions & 7 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function setAliasedTables(array $aliases)
*/
public function addTableAlias(string $table)
{
if (! in_array($table, $this->aliasedTables))
if (! in_array($table, $this->aliasedTables, true))
{
$this->aliasedTables[] = $table;
}
Expand Down Expand Up @@ -1171,13 +1171,13 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
//
// NOTE: The ! empty() condition prevents this method
// from breaking when QB isn't enabled.
if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables))
if (! empty($this->aliasedTables) && in_array($parts[0], $this->aliasedTables, true))
{
if ($protectIdentifiers === true)
{
foreach ($parts as $key => $val)
{
if (! in_array($val, $this->reservedIdentifiers))
if (! in_array($val, $this->reservedIdentifiers, true))
{
$parts[$key] = $this->escapeIdentifiers($val);
}
Expand Down Expand Up @@ -1262,7 +1262,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
}
}

if ($protectIdentifiers === true && ! in_array($item, $this->reservedIdentifiers))
if ($protectIdentifiers === true && ! in_array($item, $this->reservedIdentifiers, true))
{
$item = $this->escapeIdentifiers($item);
}
Expand All @@ -1283,7 +1283,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, bool $prot
*/
public function escapeIdentifiers($item)
{
if ($this->escapeChar === '' || empty($item) || in_array($item, $this->reservedIdentifiers))
if ($this->escapeChar === '' || empty($item) || in_array($item, $this->reservedIdentifiers, true))
{
return $item;
}
Expand Down Expand Up @@ -1587,7 +1587,7 @@ public function listTables(bool $constrainByPrefix = false)
*/
public function tableExists(string $tableName): bool
{
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables());
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -1662,7 +1662,7 @@ public function getFieldNames(string $table)
*/
public function fieldExists(string $fieldName, string $tableName): bool
{
return in_array($fieldName, $this->getFieldNames($tableName));
return in_array($fieldName, $this->getFieldNames($tableName), true);
}

//--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function listDatabases()
*/
public function databaseExists(string $database_name): bool
{
return in_array($database_name, $this->listDatabases());
return in_array($database_name, $this->listDatabases(), true);
}

//--------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ protected function _processIndexes(string $table)
continue;
}

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

if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions))
if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true))
{
$sql .= ' ON DELETE ' . $fkey['onDelete'];
}

if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions))
if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true))
{
$sql .= ' ON UPDATE ' . $fkey['onUpdate'];
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function regress(int $targetBatch = 0, string $group = null)
}

// Make sure $targetBatch is found
if ($targetBatch !== 0 && ! in_array($targetBatch, $batches))
if ($targetBatch !== 0 && ! in_array($targetBatch, $batches, true))
{
$message = lang('Migrations.batchNotFound') . $targetBatch;

Expand Down
4 changes: 2 additions & 2 deletions system/Database/MySQLi/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function _createTableAttributes(array $attributes): string
{
$sql .= ' ' . strtoupper($key) . ' = ';

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

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

$sql .= ",\n\t{$unique}KEY " . $this->db->escapeIdentifiers(implode('_', $this->keys[$i]))
. ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i])) . ')';
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLite3/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function _processIndexes(string $table): array
continue;
}

if (in_array($i, $this->uniqueKeys))
if (in_array($i, $this->uniqueKeys, true))
{
$sqls[] = 'CREATE UNIQUE INDEX ' . $this->db->escapeIdentifiers($table . '_' . implode('_', $this->keys[$i]))
. ' ON ' . $this->db->escapeIdentifiers($table)
Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function exceptionHandler(Throwable $exception)
] = $this->determineCodes($exception);

// Log it
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes))
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true))
{
log_message('critical', $exception->getMessage() . "\n{trace}", [
'trace' => $exception->getTraceAsString(),
Expand Down Expand Up @@ -219,7 +219,7 @@ public function shutdownHandler()
if (! is_null($error))
{
// Fatal Error?
if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]))
if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE], true))
{
$this->exceptionHandler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
}
Expand Down
4 changes: 2 additions & 2 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public function setPriority($n = 3)
*/
public function setNewline($newline = "\n")
{
$this->newline = in_array($newline, ["\n", "\r\n", "\r"]) ? $newline : "\n";
$this->newline = in_array($newline, ["\n", "\r\n", "\r"], true) ? $newline : "\n";
return $this;
}
//--------------------------------------------------------------------
Expand Down Expand Up @@ -860,7 +860,7 @@ protected function getProtocol()
*/
protected function getEncoding()
{
in_array($this->encoding, $this->bitDepths) || $this->encoding = '8bit'; // @phpstan-ignore-line
in_array($this->encoding, $this->bitDepths, true) || $this->encoding = '8bit'; // @phpstan-ignore-line
foreach ($this->baseCharsets as $charset)
{
if (strpos($this->charset, $charset) === 0)
Expand Down
2 changes: 1 addition & 1 deletion system/Encryption/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function initialize(EncryptionConfig $config = null)
}

// Check for an unknown driver
if (! in_array($this->driver, $this->drivers))
if (! in_array($this->driver, $this->drivers, true))
{
throw EncryptionException::forUnKnownHandler($this->driver);
}
Expand Down
6 changes: 3 additions & 3 deletions system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function __get(string $key)
}

// Do we need to mutate this into a date?
if (in_array($key, $this->dates))
if (in_array($key, $this->dates, true))
{
$result = $this->mutateDate($result);
}
Expand Down Expand Up @@ -366,7 +366,7 @@ public function __set(string $key, $value = null)
$key = $this->mapProperty($key);

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

Expand Down
2 changes: 1 addition & 1 deletion system/Format/JSONFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function format($data)

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

if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION]))
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true))
{
throw FormatException::forInvalidJSON(json_last_error_msg());
}
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ protected function addToHeader(string $name, $values = null)

if ($reportOnly === true)
{
$reportSources[] = in_array($value, $this->validSources) ? "'{$value}'" : $value;
$reportSources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
}
else
{
Expand All @@ -829,7 +829,7 @@ protected function addToHeader(string $name, $values = null)
}
else
{
$sources[] = in_array($value, $this->validSources) ? "'{$value}'" : $value;
$sources[] = in_array($value, $this->validSources, true) ? "'{$value}'" : $value;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function setLocale(string $locale)
{
// If it's not a valid locale, set it
// to the default locale for the site.
if (! in_array($locale, $this->validLocales))
if (! in_array($locale, $this->validLocales, true))
{
$locale = $this->defaultLocale;
}
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Message
protected $validProtocolVersions = [
'1.0',
'1.1',
'2',
'2.0',
];

/**
Expand Down Expand Up @@ -379,7 +379,7 @@ public function setProtocolVersion(string $version)
$version = substr($version, strpos($version, '/') + 1);
}

if (! in_array($version, $this->validProtocolVersions))
if (! in_array($version, $this->validProtocolVersions, true))
{
throw HTTPException::forInvalidHTTPProtocol(implode(', ', $this->validProtocolVersions));
}
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ public function stripQuery(...$params)
* Filters the query variables so that only the keys passed in
* are kept. The rest are removed from the object.
*
* @param array ...$params
* @param string ...$params
*
* @return $this
*/
Expand All @@ -906,7 +906,7 @@ public function keepQuery(...$params)

foreach ($this->query as $key => $value)
{
if (! in_array($key, $params))
if (! in_array($key, $params, true))
{
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
$before = Services::filters()
->getFilters()['before'];

if ((in_array('csrf', $before) || array_key_exists('csrf', $before)) && strpos($action, base_url()) !== false && ! stripos($form, 'method="get"'))
if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && strpos($action, base_url()) !== false && ! stripos($form, 'method="get"'))
{
$form .= csrf_field($csrfId ?? null);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
$form .= '<optgroup label="' . $key . "\">\n";
foreach ($val as $optgroup_key => $optgroup_val)
{
$sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
$sel = in_array($optgroup_key, $selected, true) ? ' selected="selected"' : '';
$form .= '<option value="' . htmlspecialchars($optgroup_key) . '"' . $sel . '>'
. $optgroup_val . "</option>\n";
}
Expand All @@ -432,7 +432,7 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
else
{
$form .= '<option value="' . htmlspecialchars($key) . '"'
. (in_array($key, $selected) ? ' selected="selected"' : '') . '>'
. (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>'
. $val . "</option>\n";
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/c

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

if (! in_array($rel, ['alternate', 'canonical']))
if (! in_array($rel, ['alternate', 'canonical'], true))
{
$link .= 'type="' . $type . '" ';
}
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/inflector_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ function is_pluralizable(string $word): bool
'weather',
'wisdom',
'work',
]);
], true);

return ! $uncountables;
}
Expand Down
8 changes: 4 additions & 4 deletions system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ public function rotate(float $angle)
{
// Allowed rotation values
$degs = [
90,
180,
270,
90.0,
180.0,
270.0,
];

if (! in_array($angle, $degs))
if (! in_array($angle, $degs, true))
{
throw ImageException::forMissingAngle();
}
Expand Down
2 changes: 1 addition & 1 deletion system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ protected function supportedFormatCheck()
switch ($this->image()->imageType)
{
case IMAGETYPE_WEBP:
if (! in_array('WEBP', \Imagick::queryFormats()))
if (! in_array('WEBP', \Imagick::queryFormats(), true))
{
throw ImageException::forInvalidImageCreate(lang('images.webpNotSupported'));
}
Expand Down
2 changes: 1 addition & 1 deletion system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected function load(string $file, string $locale, bool $return = false)
$this->loadedFiles[$locale] = [];
}

if (in_array($file, $this->loadedFiles[$locale]))
if (in_array($file, $this->loadedFiles[$locale], true))
{
// Don't load it more than once.
return [];
Expand Down
Loading