Skip to content
Snippets Groups Projects
Unverified Commit 115a3388 authored by Alex Pott's avatar Alex Pott
Browse files

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 cb14f8ba
No related branches found
No related tags found
9 merge requests!1445Issue #2920039: Views' User Name exposed group filter validation,!1298Issue #3240993: Let layout builder render inline block translations,!774Issue #3174569: Example node template file name is incorrect,!497Issue #2463967: Use .user.ini file for PHP settings,!433Resolve #3163663 "Too many open files",!233Resolve #2693787 "Taxonomy term name",!133Resolve #2666286 "Clean up menuui",!112Resolve #3187004 "Drupaldatetime serialization issue",!53Resolve #3181870: Correct typo "the the" in "core/classList" deprecation message.
Showing
with 108 additions and 1 deletion
......@@ -303,6 +303,7 @@ function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
$state = 'candidate_left';
}
break;
case 'candidate_left':
if ($value == '[') {
$state = 'array_index';
......@@ -311,6 +312,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, '\'"');
......@@ -321,6 +323,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])) {
......@@ -339,6 +342,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);
......@@ -351,11 +355,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 = '';
......@@ -754,31 +760,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;
......@@ -816,9 +828,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;
......@@ -877,26 +891,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;
}
......
......@@ -619,6 +619,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);
......
......@@ -396,6 +396,7 @@ protected function processField($field) {
case 'smallint':
$field['pgsql_type'] = $map['int:medium'];
break;
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);
......
......@@ -242,9 +242,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;
......@@ -270,17 +272,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.
......@@ -299,11 +305,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;
......
......@@ -110,6 +110,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 <>.
......@@ -118,6 +119,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;
}
......
......@@ -38,6 +38,7 @@ protected function setUpAuthorization($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access news feeds']);
break;
case 'POST':
case 'PATCH':
case 'DELETE':
......@@ -180,10 +181,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);
break;
case 3:
case 'online':
$settings['user']['block_seconds_online'] = $this->variableGet('user_block_seconds_online', 900);
......
......@@ -31,9 +31,11 @@ protected function setUpAuthorization($method) {
case 'GET':
$this->entity->setVisibilityConfig('user_role', [])->save();
break;
case 'POST':
$this->grantPermissionsToTestedRole(['administer blocks']);
break;
case 'PATCH':
$this->grantPermissionsToTestedRole(['administer blocks']);
break;
......@@ -137,6 +139,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The block visibility condition 'user_role' denied access.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
......
......@@ -56,9 +56,11 @@ protected function setUpAuthorization($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access comments', 'view test entity']);
break;
case 'POST':
$this->grantPermissionsToTestedRole(['post comments']);
break;
case 'PATCH':
// Anonymous users are not ever allowed to edit their own comments. To
// be able to test PATCHing comments as the anonymous user, the more
......@@ -71,6 +73,7 @@ protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer comments']);
}
break;
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer comments']);
break;
......@@ -315,10 +318,13 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET';
return "The 'access comments' permission is required and the comment must be published.";
case 'POST';
return "The 'post comments' permission is required.";
case 'PATCH';
return "The 'edit own comments' permission is required, the user must be the comment author, and the comment must be published.";
case 'DELETE':
// \Drupal\comment\CommentAccessControlHandler::checkAccess() does not
// specify a reason for not allowing a comment to be deleted.
......
......@@ -81,6 +81,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The 'view config_test' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment