Issue #3346645 by jweowu, catch, smustgrave: Eliminate anti-pattern isset($arr[$key]) || array_key_exists($key, $arr)

merge-requests/3693/head
catch 2023-03-21 19:34:56 +00:00
parent 5a9aa149e3
commit e48191a945
10 changed files with 15 additions and 15 deletions

View File

@ -87,7 +87,7 @@ function form_select_options($element, $choices = NULL) {
// array_key_exists() accommodates the rare event where $element['#value'] is NULL.
// isset() fails in this situation.
$value_valid = isset($element['#value']) || array_key_exists('#value', $element);
$value_valid = \array_key_exists('#value', $element);
$value_is_array = $value_valid && is_array($element['#value']);
// Check if the element is multiple select and no value has been selected.
$empty_value = (empty($element['#value']) && !empty($element['#multiple']));

View File

@ -320,7 +320,7 @@ class Container implements ContainerInterface, ResetInterface {
* {@inheritdoc}
*/
public function getParameter($name): array|bool|string|int|float|NULL {
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
if (!\array_key_exists($name, $this->parameters)) {
if (!$name) {
throw new ParameterNotFoundException('');
}
@ -335,7 +335,7 @@ class Container implements ContainerInterface, ResetInterface {
* {@inheritdoc}
*/
public function hasParameter($name): bool {
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
return \array_key_exists($name, $this->parameters);
}
/**
@ -357,7 +357,7 @@ class Container implements ContainerInterface, ResetInterface {
$id = $this->aliases[$id];
}
return isset($this->services[$id]) || array_key_exists($id, $this->services);
return \array_key_exists($id, $this->services);
}
/**

View File

@ -64,7 +64,7 @@ class ReflectionFactory extends DefaultFactory {
elseif ($param_name == 'configuration') {
$arguments[] = $configuration;
}
elseif (isset($configuration[$param_name]) || array_key_exists($param_name, $configuration)) {
elseif (\array_key_exists($param_name, $configuration)) {
$arguments[] = $configuration[$param_name];
}
elseif ($param->isDefaultValueAvailable()) {

View File

@ -69,7 +69,7 @@ class NestedArray {
public static function &getValue(array &$array, array $parents, &$key_exists = NULL) {
$ref = &$array;
foreach ($parents as $parent) {
if (is_array($ref) && (isset($ref[$parent]) || array_key_exists($parent, $ref))) {
if (is_array($ref) && \array_key_exists($parent, $ref)) {
$ref = &$ref[$parent];
}
else {
@ -219,7 +219,7 @@ class NestedArray {
public static function unsetValue(array &$array, array $parents, &$key_existed = NULL) {
$unset_key = array_pop($parents);
$ref = &self::getValue($array, $parents, $key_existed);
if ($key_existed && is_array($ref) && (isset($ref[$unset_key]) || array_key_exists($unset_key, $ref))) {
if ($key_existed && is_array($ref) && \array_key_exists($unset_key, $ref)) {
$key_existed = TRUE;
unset($ref[$unset_key]);
}

View File

@ -134,7 +134,7 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
public function has($key) {
// Make sure the value is loaded.
$this->get($key);
return isset($this->storage[$key]) || array_key_exists($key, $this->storage);
return \array_key_exists($key, $this->storage);
}
/**
@ -142,7 +142,7 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
*/
public function get($key) {
$this->lazyLoadCache();
if (isset($this->storage[$key]) || array_key_exists($key, $this->storage)) {
if (\array_key_exists($key, $this->storage)) {
return $this->storage[$key];
}
else {

View File

@ -63,7 +63,7 @@ class State implements StateInterface {
foreach ($load as $key) {
// If we find a value, even one that is NULL, add it to the cache and
// return it.
if (isset($loaded_values[$key]) || array_key_exists($key, $loaded_values)) {
if (\array_key_exists($key, $loaded_values)) {
$values[$key] = $loaded_values[$key];
$this->cache[$key] = $loaded_values[$key];
}

View File

@ -190,7 +190,7 @@ class ThemeManager implements ThemeManagerInterface {
$variables = [];
if (isset($info['variables'])) {
foreach (array_keys($info['variables']) as $name) {
if (isset($element["#$name"]) || array_key_exists("#$name", $element)) {
if (\array_key_exists("#$name", $element)) {
$variables[$name] = $element["#$name"];
}
}

View File

@ -98,7 +98,7 @@ class ThemeRegistry extends CacheCollector implements DestructableInterface {
// are not registered, just check the existence of the key in the registry.
// Use array_key_exists() here since a NULL value indicates that the theme
// hook exists but has not yet been requested.
return isset($this->storage[$key]) || array_key_exists($key, $this->storage);
return \array_key_exists($key, $this->storage);
}
/**

View File

@ -287,10 +287,10 @@ function template_preprocess_image_style(&$variables) {
]);
}
if (isset($variables['alt']) || array_key_exists('alt', $variables)) {
if (\array_key_exists('alt', $variables)) {
$variables['image']['#alt'] = $variables['alt'];
}
if (isset($variables['title']) || array_key_exists('title', $variables)) {
if (\array_key_exists('title', $variables)) {
$variables['image']['#title'] = $variables['title'];
}

View File

@ -790,7 +790,7 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
return $this->default_display->getOption($option);
}
if (isset($this->options[$option]) || array_key_exists($option, $this->options)) {
if (\array_key_exists($option, $this->options)) {
return $this->options[$option];
}
}