Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm - why is this case statement unreachable?

Tags:

phpstorm

PhpStorm inspection is claiming that everything after the break in the second case is unreachable. I don't see why. What am I missing?

function mymodule_admin_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'taxonomy_overview_terms':
      // We need to add a submit handler to this form so we can save the weight
      // in Mongo.
      $form['#submit'][] = 'mymodule_admin_taxonomy_overview_submit_mongo';
      break;

      // Unwraps the mymodule News node form
    case 'mymodule_news_node_form':
      $form['#nowrap'] = true;

      $form['field_news_image']['#prefix'] = '<div class="row"><div class="large-5 columns">';
      $form['field_news_image']['#suffix'] = '</div></div>';

      $form['actions']['#prefix'] = '<div class="row"><div class="large-3 columns actions">';
      $form['actions']['#suffix'] = '</div></div>';

      break; // PhpStorm claims everything after this is unreachable ******

      // Unwraps the page forms
    case 'basic_page_with_multiple_images_node_form':
      $form['#nowrap'] = true;

      $form['field_bottom_image']['#prefix'] = '<div class="row"><div class="large-5 columns">';
      $form['field_bottom_image']['#suffix'] = '</div></div>';

      $form['actions']['#prefix'] = '<div class="row"><div class="large-3 columns actions">';
      $form['actions']['#suffix'] = '</div></div>';

      break;

    case 'page_node_form':
      $form['#nowrap'] = true;

      $form['field_bottom_image']['#prefix'] = '<div class="row"><div class="large-5 columns">';
      $form['field_bottom_image']['#suffix'] = '</div></div>';

      $form['actions']['#prefix'] = '<div class="row"><div class="large-3 columns actions">';
      $form['actions']['#suffix'] = '</div></div>';

      break;

    case 'basic_page_with_top_image':
      $form['#nowrap'] = true;

      $form['field_top_image']['#prefix'] = '<div class="row"><div class="large-5 columns">';
      $form['field_top_image']['#suffix'] = '</div></div>';

      $form['actions']['#prefix'] = '<div class="row"><div class="large-3 columns actions">';
      $form['actions']['#suffix'] = '</div></div>';

      break;

    case 'basic_page_with_inline_images_node_form':
      $form['#nowrap'] = true;

      $form['actions']['#prefix'] = '<div class="row"><div class="large-3 columns actions">';
      $form['actions']['#suffix'] = '</div></div>';

      break;
  }
}

I hadn't included the rest of the code because stackoverflow was telling me I had too much code for my question.

As you can see there are more conditions after the case in question. If the first two conditions are not met, the rest should be evaluated, therefor the rest of the code is reachable. Is this not correct?

like image 740
joekrukosky Avatar asked Mar 20 '26 02:03

joekrukosky


1 Answers

Your code is looking fine here in PhpStorm v7 -- no such error messages at all. And overall code looks fine.

Looks like IDE is out-of-sync (some internal structures) .. so "File | Invalidate Caches..." should help here.

P.S. You can try it when you have "it worked fine yesterday/an hour ago .. and now the same code is broken" kind of situation (especially when upgrading to the newer minor version).

like image 125
LazyOne Avatar answered Mar 22 '26 14:03

LazyOne