Unverified Commit 9d1faa52 authored by alexpott's avatar alexpott

Issue #2824935 by idebr, mfernea, Deepak Goyal, pfrenssen, longwave,...

Issue #2824935 by idebr, mfernea, Deepak Goyal, pfrenssen, longwave, hgunicamp, jofitz, andypost, daffie: Fix Squiz.ControlStructures.SwitchDeclaration coding standard
parent b086cafd
......@@ -301,6 +301,7 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
$state = 'candidate_left';
}
break;
case 'candidate_left':
if ($value == '[') {
$state = 'array_index';
......@@ -309,6 +310,7 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
$state = 'candidate_right';
}
break;
case 'array_index':
if (_drupal_rewrite_settings_is_array_index($type, $value)) {
$index = trim($value, '\'"');
......@@ -319,6 +321,7 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
throw new Exception('invalid array index');
}
break;
case 'right_bracket':
if ($value == ']') {
if (isset($current[$index])) {
......@@ -337,6 +340,7 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
throw new Exception('] expected');
}
break;
case 'candidate_right':
if (_drupal_rewrite_settings_is_simple($type, $value)) {
$value = _drupal_rewrite_settings_dump_one($current);
......@@ -349,11 +353,13 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
$state = 'wait_for_semicolon';
}
break;
case 'wait_for_semicolon':
if ($value == ';') {
$state = 'default';
}
break;
case 'semicolon_skip':
if ($value == ';') {
$value = '';
......@@ -672,31 +678,37 @@ function drupal_verify_install_file($file, $mask = NULL, $type = 'file', $autofi
}
}
break;
case FILE_READABLE:
if (!is_readable($file)) {
$return = FALSE;
}
break;
case FILE_WRITABLE:
if (!is_writable($file)) {
$return = FALSE;
}
break;
case FILE_EXECUTABLE:
if (!is_executable($file)) {
$return = FALSE;
}
break;
case FILE_NOT_READABLE:
if (is_readable($file)) {
$return = FALSE;
}
break;
case FILE_NOT_WRITABLE:
if (is_writable($file)) {
$return = FALSE;
}
break;
case FILE_NOT_EXECUTABLE:
if (is_executable($file)) {
$return = FALSE;
......@@ -734,9 +746,11 @@ function drupal_install_mkdir($file, $mask, $message = TRUE) {
case FILE_READABLE:
$mod |= 0444;
break;
case FILE_WRITABLE:
$mod |= 0222;
break;
case FILE_EXECUTABLE:
$mod |= 0111;
break;
......@@ -795,26 +809,31 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) {
$mod |= 0444;
}
break;
case FILE_WRITABLE:
if (!is_writable($file)) {
$mod |= 0222;
}
break;
case FILE_EXECUTABLE:
if (!is_executable($file)) {
$mod |= 0111;
}
break;
case FILE_NOT_READABLE:
if (is_readable($file)) {
$mod &= ~0444;
}
break;
case FILE_NOT_WRITABLE:
if (is_writable($file)) {
$mod &= ~0222;
}
break;
case FILE_NOT_EXECUTABLE:
if (is_executable($file)) {
$mod &= ~0111;
......
......@@ -641,6 +641,7 @@ public static function checkArray($array) {
$valid_time = FALSE;
}
break;
case 'minute':
case 'second':
default:
......
......@@ -400,6 +400,7 @@ private function tokenizeFormula($formula) {
$tokens[] = $formula[$i];
}
break;
case 5:
if ($next == '&') {
$tokens[] = '&&';
......@@ -409,6 +410,7 @@ private function tokenizeFormula($formula) {
$tokens[] = $formula[$i];
}
break;
case 6:
if ($next == '|') {
$tokens[] = '||';
......@@ -502,42 +504,55 @@ protected function evaluatePlural($element_stack, $n) {
case '==':
$f = $element_stack[$i - 2] == $element_stack[$i - 1];
break;
case '!=':
$f = $element_stack[$i - 2] != $element_stack[$i - 1];
break;
case '<=':
$f = $element_stack[$i - 2] <= $element_stack[$i - 1];
break;
case '>=':
$f = $element_stack[$i - 2] >= $element_stack[$i - 1];
break;
case '<':
$f = $element_stack[$i - 2] < $element_stack[$i - 1];
break;
case '>':
$f = $element_stack[$i - 2] > $element_stack[$i - 1];
break;
case '+':
$f = $element_stack[$i - 2] + $element_stack[$i - 1];
break;
case '-':
$f = $element_stack[$i - 2] - $element_stack[$i - 1];
break;
case '*':
$f = $element_stack[$i - 2] * $element_stack[$i - 1];
break;
case '/':
$f = $element_stack[$i - 2] / $element_stack[$i - 1];
break;
case '%':
$f = $element_stack[$i - 2] % $element_stack[$i - 1];
break;
case '&&':
$f = $element_stack[$i - 2] && $element_stack[$i - 1];
break;
case '||':
$f = $element_stack[$i - 2] || $element_stack[$i - 1];
break;
case ':':
$f = $element_stack[$i - 3] ? $element_stack[$i - 2] : $element_stack[$i - 1];
// This operator has 3 preceding elements, instead of the default 2.
......
......@@ -103,6 +103,7 @@ public static function getStatus() {
switch (static::check()) {
case 'mb_strlen':
return Unicode::STATUS_SINGLEBYTE;
case '':
return Unicode::STATUS_MULTIBYTE;
}
......
......@@ -621,6 +621,7 @@ protected function getMissingDependencies($config_name, array $data, array $enab
case 'theme':
$list_to_check = $enabled_extensions;
break;
case 'config':
$list_to_check = $all_config;
break;
......
......@@ -169,26 +169,37 @@ protected function match(array $condition, $value) {
switch ($condition['operator']) {
case '=':
return $value == $condition['value'];
case '>':
return $value > $condition['value'];
case '<':
return $value < $condition['value'];
case '>=':
return $value >= $condition['value'];
case '<=':
return $value <= $condition['value'];
case '<>':
return $value != $condition['value'];
case 'IN':
return array_search($value, $condition['value']) !== FALSE;
case 'NOT IN':
return array_search($value, $condition['value']) === FALSE;
case 'STARTS_WITH':
return strpos($value, $condition['value']) === 0;
case 'CONTAINS':
return strpos($value, $condition['value']) !== FALSE;
case 'ENDS_WITH':
return substr($value, -strlen($condition['value'])) === (string) $condition['value'];
default:
throw new QueryException('Invalid condition operator.');
}
......
......@@ -183,18 +183,21 @@ protected function loadRecords() {
return $id !== $value;
};
break;
case 'STARTS_WITH':
$filter = function ($name) use ($value, $prefix_length) {
$id = substr($name, $prefix_length);
return strpos($id, $value) === 0;
};
break;
case 'CONTAINS':
$filter = function ($name) use ($value, $prefix_length) {
$id = substr($name, $prefix_length);
return strpos($id, $value) !== FALSE;
};
break;
case 'ENDS_WITH':
$filter = function ($name) use ($value, $prefix_length) {
$id = substr($name, $prefix_length);
......
......@@ -744,14 +744,18 @@ public function query($query, array $args = [], $options = []) {
switch ($options['return']) {
case Database::RETURN_STATEMENT:
return $stmt;
case Database::RETURN_AFFECTED:
$stmt->allowRowCount = TRUE;
return $stmt->rowCount();
case Database::RETURN_INSERT_ID:
$sequence_name = isset($options['sequence_name']) ? $options['sequence_name'] : NULL;
return $this->connection->lastInsertId($sequence_name);
case Database::RETURN_NULL:
return NULL;
default:
throw new \PDOException('Invalid return directive: ' . $options['return']);
}
......@@ -891,33 +895,43 @@ public function getDriverClass($class) {
case 'Condition':
$this->driverClasses[$class] = Condition::class;
break;
case 'Delete':
$this->driverClasses[$class] = Delete::class;
break;
case 'Insert':
$this->driverClasses[$class] = Insert::class;
break;
case 'Merge':
$this->driverClasses[$class] = Merge::class;
break;
case 'Schema':
$this->driverClasses[$class] = Schema::class;
break;
case 'Select':
$this->driverClasses[$class] = Select::class;
break;
case 'Transaction':
$this->driverClasses[$class] = Transaction::class;
break;
case 'Truncate':
$this->driverClasses[$class] = Truncate::class;
break;
case 'Update':
$this->driverClasses[$class] = Update::class;
break;
case 'Upsert':
$this->driverClasses[$class] = Upsert::class;
break;
default:
$this->driverClasses[$class] = $class;
}
......
......@@ -395,7 +395,8 @@ protected function processField($field) {
case 'smallint':
$field['pgsql_type'] = $map['int:medium'];
break;
case 'int' :
case 'int':
$field['pgsql_type'] = $map['int:big'];
break;
}
......
......@@ -153,8 +153,10 @@ public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
switch (func_num_args()) {
case 1:
return parent::setFetchMode($mode);
case 2:
return parent::setFetchMode($mode, $a1);
case 3:
default:
return parent::setFetchMode($mode, $a1, $a2);
......@@ -171,10 +173,13 @@ public function fetchAll($mode = NULL, $column_index = NULL, $constructor_argume
switch (func_num_args()) {
case 0:
return parent::fetchAll();
case 1:
return parent::fetchAll($mode);
case 2:
return parent::fetchAll($mode, $column_index);
case 3:
default:
return parent::fetchAll($mode, $column_index, $constructor_arguments);
......
......@@ -243,9 +243,11 @@ public function setFetchMode($mode, $a1 = NULL, $a2 = []) {
$this->defaultFetchOptions['constructor_args'] = $a2;
}
break;
case \PDO::FETCH_COLUMN:
$this->defaultFetchOptions['column'] = $a1;
break;
case \PDO::FETCH_INTO:
$this->defaultFetchOptions['object'] = $a1;
break;
......@@ -271,17 +273,21 @@ public function current() {
switch ($this->fetchStyle) {
case \PDO::FETCH_ASSOC:
return $this->currentRow;
case \PDO::FETCH_BOTH:
// \PDO::FETCH_BOTH returns an array indexed by both the column name
// and the column number.
return $this->currentRow + array_values($this->currentRow);
case \PDO::FETCH_NUM:
return array_values($this->currentRow);
case \PDO::FETCH_LAZY:
// We do not do lazy as everything is fetched already. Fallback to
// \PDO::FETCH_OBJ.
case \PDO::FETCH_OBJ:
return (object) $this->currentRow;
case \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE:
$class_name = array_shift($this->currentRow);
// Deliberate no break.
......@@ -300,11 +306,13 @@ public function current() {
$result->$k = $v;
}
return $result;
case \PDO::FETCH_INTO:
foreach ($this->currentRow as $k => $v) {
$this->fetchOptions['object']->$k = $v;
}
return $this->fetchOptions['object'];
case \PDO::FETCH_COLUMN:
if (isset($this->columnNames[$this->fetchOptions['column']])) {
return $this->currentRow[$this->columnNames[$this->fetchOptions['column']]];
......
......@@ -93,30 +93,43 @@ protected function matchLabel($match, $match_operator, $label) {
switch ($match_operator) {
case '=':
return $label == $match;
case '>':
return $label > $match;
case '<':
return $label < $match;
case '>=':
return $label >= $match;
case '<=':
return $label <= $match;
case '<>':
return $label != $match;
case 'IN':
return array_search($label, $match) !== FALSE;
case 'NOT IN':
return array_search($label, $match) === FALSE;
case 'STARTS_WITH':
return strpos($label, $match) === 0;
case 'CONTAINS':
return strpos($label, $match) !== FALSE;
case 'ENDS_WITH':
return mb_substr($label, -mb_strlen($match)) === (string) $match;
case 'IS NOT NULL':
return TRUE;
case 'IS NULL':
return FALSE;
default:
// Invalid match operator.
return FALSE;
......
......@@ -120,6 +120,7 @@ public static function translateCondition(&$condition, SelectInterface $sql_quer
$condition['operator'] = 'LIKE';
}
break;
case '<>':
// If a field explicitly requests that queries should not be case
// sensitive, use the NOT LIKE operator, otherwise keep <>.
......@@ -128,6 +129,7 @@ public static function translateCondition(&$condition, SelectInterface $sql_quer
$condition['operator'] = 'NOT LIKE';
}
break;
case 'STARTS_WITH':
if ($case_sensitive) {
$condition['operator'] = 'LIKE BINARY';
......
......@@ -276,6 +276,7 @@ protected function validateDependencies(ConfigImporter $config_importer) {
['%name' => $name, '%module' => implode(', ', $this->getNames($diffs, $module_data))]
);
break;
case 'theme':
$message = $this->formatPlural(
count($diffs),
......@@ -284,6 +285,7 @@ protected function validateDependencies(ConfigImporter $config_importer) {
['%name' => $name, '%theme' => implode(', ', $this->getNames($diffs, $theme_data))]
);
break;
case 'config':
$message = $this->formatPlural(
count($diffs),
......
......@@ -237,6 +237,7 @@ public function check($password, $hash) {
// A normal Drupal 7 password using sha512.
$computed_hash = $this->crypt('sha512', $password, $stored_hash);
break;
case '$H$':
// phpBB3 uses "$H$" for the same thing as "$P$".
case '$P$':
......@@ -244,6 +245,7 @@ public function check($password, $hash) {
// imported password or from an earlier Drupal version.
$computed_hash = $this->crypt('md5', $password, $stored_hash);
break;
default:
return FALSE;
}
......
......@@ -35,6 +35,7 @@ protected function setUpAuthorization($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access news feeds']);
break;
case 'POST':
case 'PATCH':
case 'DELETE':
......@@ -182,10 +183,12 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The 'access news feeds' permission is required.";
case 'POST':
case 'PATCH':
case 'DELETE':
return "The 'administer news feeds' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
......
......@@ -35,21 +35,26 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$settings['block_count'] = $old_settings['aggregator']['item_count'];
$settings['feed'] = $id;
break;
case 'book_navigation':
$settings['block_mode'] = $old_settings['book']['block_mode'];
break;
case 'forum_active_block':
case 'forum_new_block':
$settings['block_count'] = $old_settings['forum']['block_num'];
break;
case 'statistics_popular_block':
$settings['top_day_num'] = $old_settings['statistics']['statistics_block_top_day_num'];
$settings['top_all_num'] = $old_settings['statistics']['statistics_block_top_all_num'];
$settings['top_last_num'] = $old_settings['statistics']['statistics_block_top_last_num'];
break;
case 'views_block:who_s_new-block_1':
$settings['items_per_page'] = $old_settings['user']['block_whois_new_count'];
break;
case 'views_block:who_s_online-who_s_online_block':
$settings['items_per_page'] = $old_settings['user']['max_list_count'];
break;
......
......@@ -145,23 +145,28 @@ public function prepareRow(Row $row) {
}
$settings['aggregator']['item_count'] = $item_count;
break;
case 'book':
$settings['book']['block_mode'] = $this->variableGet('book_block_mode', 'all pages');
break;
case 'forum':
$settings['forum']['block_num'] = $this->variableGet('forum_block_num_' . $delta, 5);
break;
case 'statistics':
foreach (['statistics_block_top_day_num', 'statistics_block_top_all_num', 'statistics_block_top_last_num'] as $name) {
$settings['statistics'][$name] = $this->variableGet($name, 0);
}
break;
case 'user':
switch ($delta) {
case 2:
case 'new':
$settings['user']['block_whois_new_count'] = $this->variableGet('user_block_whois_new_count', 5);