[Rector] Apply Rector: UnusedForeachValueToArrayKeysRector

This commit is contained in:
Abdul Malik Ikhsan 2021-03-13 01:17:32 +07:00
parent c9a68047c8
commit cdd078c5e5
No known key found for this signature in database
GPG Key ID: 80035E72114C7548
18 changed files with 27 additions and 23 deletions

View File

@ -2,6 +2,7 @@
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\For_\ForToForeachRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
@ -70,4 +71,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ShortenElseIfRector::class);
$services->set(RemoveUnusedForeachKeyRector::class);
$services->set(SimplifyIfElseToTernaryRector::class);
$services->set(UnusedForeachValueToArrayKeysRector::class);
};

View File

@ -299,7 +299,9 @@ abstract class BaseModel
$this->tempUseSoftDeletes = $this->useSoftDeletes;
$this->tempAllowCallbacks = $this->allowCallbacks;
/** @var Validation $validation */
/**
* @var Validation $validation
*/
$validation = $validation ?? Services::validation(null, false);
$this->validation = $validation;
@ -1177,7 +1179,7 @@ abstract class BaseModel
throw DataException::forInvalidAllowedFields(get_class($this));
}
foreach ($data as $key => $val)
foreach (array_keys($data) as $key)
{
if (! in_array($key, $this->allowedFields, true))
{
@ -1447,7 +1449,7 @@ abstract class BaseModel
return [];
}
foreach ($rules as $field => $rule)
foreach (array_keys($rules) as $field)
{
if (! array_key_exists($field, $data))
{

View File

@ -226,7 +226,7 @@ abstract class BaseCommand
public function getPad(array $array, int $pad): int
{
$max = 0;
foreach ($array as $key => $value)
foreach (array_keys($array) as $key)
{
$max = max($max, strlen($key));
}

View File

@ -200,7 +200,7 @@ class Commands
{
$alternatives = [];
foreach ($collection as $commandName => $attributes)
foreach (array_keys($collection) as $commandName)
{
$lev = levenshtein($name, $commandName);

View File

@ -669,7 +669,7 @@ class CodeIgniter
$output = $cachedResponse['output'];
// Clear all default headers
foreach ($this->response->headers() as $key => $val)
foreach (array_keys($this->response->headers()) as $key)
{
$this->response->removeHeader($key);
}

View File

@ -90,7 +90,7 @@ class MigrateStatus extends BaseCommand
// Collection of migration status
$status = [];
foreach ($namespaces as $namespace => $path)
foreach (array_keys($namespaces) as $namespace)
{
if (ENVIRONMENT !== 'testing')
{

View File

@ -138,7 +138,7 @@ class ListCommands extends BaseCommand
*/
protected function listSimple(array $commands)
{
foreach ($commands as $title => $command)
foreach (array_keys($commands) as $title)
{
CLI::write($title);
}

View File

@ -102,7 +102,7 @@ class BaseConfig
{
if (is_array($property))
{
foreach ($property as $key => $val)
foreach (array_keys($property) as $key)
{
$this->initEnvValue($property[$key], "{$name}.{$key}", $prefix, $shortPrefix);
}

View File

@ -339,7 +339,7 @@ abstract class BaseUtils
// Did the user submit any preferences? If so set them....
if (! empty($params))
{
foreach ($prefs as $key => $val)
foreach (array_keys($prefs) as $key)
{
if (isset($params[$key]))
{

View File

@ -410,7 +410,7 @@ class Email
$config = get_object_vars($config);
}
foreach (get_class_vars(get_class($this)) as $key => $value)
foreach (array_keys(get_class_vars(get_class($this))) as $key)
{
if (property_exists($this, $key) && isset($config[$key]))
{

View File

@ -482,7 +482,7 @@ class CURLRequest extends Request
$set = [];
foreach ($headers as $name => $value)
foreach (array_keys($headers) as $name)
{
$set[] = $name . ': ' . $this->getHeaderLine($name);
}

View File

@ -175,7 +175,7 @@ class CookieStore implements Countable, IteratorAggregate
$store = clone $this;
foreach ($store->cookies as $index => $cookie)
foreach (array_keys($store->cookies) as $index)
{
if ($index === $id)
{

View File

@ -86,7 +86,7 @@ trait MessageTrait
}
unset($contentType);
foreach ($_SERVER as $key => $val)
foreach (array_keys($_SERVER) as $key)
{
if (sscanf($key, 'HTTP_%s', $header) === 1)
{

View File

@ -494,7 +494,7 @@ trait ResponseTrait
header(sprintf('HTTP/%s %s %s', $this->getProtocolVersion(), $this->getStatusCode(), $this->getReason()), true, $this->getStatusCode());
// Send all of our headers
foreach ($this->getHeaders() as $name => $values)
foreach (array_keys($this->getHeaders()) as $name)
{
header($name . ': ' . $this->getHeaderLine($name), false, $this->getStatusCode());
}

View File

@ -313,10 +313,10 @@ if (! function_exists('form_multiselect'))
/**
* Multi-select menu
*
* @param mixed $name
* @param array $options
* @param array $selected
* @param mixed $extra
* @param mixed $name
* @param array $options
* @param array $selected
* @param mixed $extra
*
* @return string
*/
@ -932,7 +932,7 @@ if (! function_exists('parse_form_attributes'))
{
if (is_array($attributes))
{
foreach ($default as $key => $val)
foreach (array_keys($default) as $key)
{
if (isset($attributes[$key]))
{

View File

@ -610,7 +610,7 @@ class Model extends BaseModel
{
$data = is_array($key) ? $key : [$key => $value];
foreach ($data as $k => $v)
foreach (array_keys($data) as $k)
{
$this->tempData['escape'][$k] = $escape;
}

View File

@ -141,7 +141,7 @@ class Cell
}
}
foreach ($paramArray as $key => $val)
foreach (array_keys($paramArray) as $key)
{
if (! isset($methodParams[$key]))
{

View File

@ -268,7 +268,7 @@ class RedirectResponseTest extends CIUnitTestCase
$_SESSION = [];
$baseResponse = service('response');
foreach ($baseResponse->headers() as $key => $val)
foreach (array_keys($baseResponse->headers()) as $key)
{
$baseResponse->removeHeader($key);
}