merge IF statement with enclosing one (sonarqube static analysis)

This commit is contained in:
joebordes 2021-05-12 21:21:46 +02:00
parent 81515dcc95
commit 6b3c5ae608

View File

@ -172,9 +172,7 @@ class Validator
return $find[1]; return $find[1];
} }
if (is_null($value)) { if (is_null($value) || (is_string($value) && trim($value) === '')) {
return false;
} elseif (is_string($value) && trim($value) === '') {
return false; return false;
} }
@ -890,13 +888,11 @@ class Validator
} elseif (isset($cards)) { } elseif (isset($cards)) {
// if we have cards, check our users card against only the ones we have // if we have cards, check our users card against only the ones we have
foreach ($cards as $card) { foreach ($cards as $card) {
if (in_array($card, array_keys($cardRegex))) { if (in_array($card, array_keys($cardRegex)) && preg_match($cardRegex[$card], $value) === 1) {
// if the card is valid, we want to stop looping // if the card is valid, we want to stop looping
if (preg_match($cardRegex[$card], $value) === 1) {
return true; return true;
} }
} }
}
} else { } else {
// loop through every card // loop through every card
foreach ($cardRegex as $regex) { foreach ($cardRegex as $regex) {
@ -1102,11 +1098,9 @@ class Validator
} }
} }
// Use custom label instead of field name if set // Use custom label instead of field name if set
if (is_string($params[0])) { if (is_string($params[0]) && isset($this->_labels[$param])) {
if (isset($this->_labels[$param])) {
$param = $this->_labels[$param]; $param = $this->_labels[$param];
} }
}
$values[] = $param; $values[] = $param;
} }
@ -1291,12 +1285,10 @@ class Validator
protected function hasRule($name, $field) protected function hasRule($name, $field)
{ {
foreach ($this->_validations as $validation) { foreach ($this->_validations as $validation) {
if ($validation['rule'] == $name) { if ($validation['rule'] == $name && in_array($field, $validation['fields'])) {
if (in_array($field, $validation['fields'])) {
return true; return true;
} }
} }
}
return false; return false;
} }