1

In my theme's template.php file, I have a custom function as:

function _MYTHEME_content_grid($columns = 1) {

  $class = FALSE;
  switch($columns) {

    // No sidebars, just content.
    case 1:{
      $class = 'grid-100';
      break;
      } 

// etc...

When I run the code through http://ventral.org/, I get this message in regard to the switch statement line: switch($columns) {

ERROR | Expected "switch (...) {\n"; found "switch(...) {\n"

I googled around but I can't really find anything on this error. My function works perfectly fine though. I'm guessing it's a syntax error but it would seem weird to insert a ; after the curly brace...

  • RajeevK is right, there is no need for curly braces wrapping the case block. Nonetheless, my guess is that the PAReview error is about the need for a white space in front of the term "switch". Well, it is not exactly a need, but a code convention. – Francisco Luz Jul 1 '13 at 16:21
  • @FranciscoLuz - yes without the curly braces around the case block, that too throws an error with PAReview.sh so I added those based on its suggestion... I may end up ignoring this as I got the function from the bootstrap theme and that's already a fully promoted project and I have full commit rights so I could just ignore it but obviously I'm trying to follow best practices. – Danny Englander Jul 1 '13 at 17:28
2

The error says it all.

Put switch ($columns) instead of switch($columns)

Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.

For more info refer Drupal coding standards

3

Put simple switch, why put curly braces.

    function _MYTHEME_content_grid($columns = 1) {

      $class = FALSE;
      switch($columns) {

        // No sidebars, just content.
        case 1:
          $class = 'grid-100';
          break;
        case 2:
          //something
          break;   

       // etc...
     }
   }
  • Ironically, without the curly braces around case, that too throws an error with PAReview.sh so I added those because of that issue. – Danny Englander Jul 1 '13 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.