-1

I've searched for this but it is a difficult issue to concisely search.

I believe in strict language requirements and error/warning reporting.

I run PHP with All and Strict error reporting enabled. If a error or warning is generated, I fix the issue. I don't juggle the error reporting level to "hide" the message.

I want single-statement inline clauses to be flagged. For example, I want a warning, say something like:

"Single-statement inline if clause"

issued for the following:

if ($userLoggedIn === false) return;  // If the user is not logged in, return to caller.

or it could be:

if ($userLoggedIn === false)  // If the user is not logged in
    return;                      // return to the caller

I want any none-braced clauses reported.

I want PHP to tell me when there is an instance like the above instead of the following:

If ($userLoggedIn === false) { // If the user is not logged in
    return;                    // return to the caller.
}

Is there anyway to tell PHP to warn of this sort of coding?

I doubt there is, but I thought I'd go ahead and ask.

SimonT
  • 486
  • 1
  • 4
  • 16

1 Answers1

0

Sorry i don't know if there is any built-in function to report "Single-statement inline if clause".

But if you want to fix it, I think some PHP Formatters can be used.

Eg: Sublime-phpfmt

Before                                           After

<?php                                      <?php
 if($i%2==0)                                if ($i%2 == 0) {
 echo "Flipflop";                               echo "Flipflop";
?>                                          }
                                           ?>
J. Shiv
  • 144
  • 4
  • Thanks for the reply .Yes, I could use a formatter or I could use a syntax checker (aka a lint) to check the code. I am/was hoping that I had missed a setting when I looked at the various error reporting options. I'm looking at the setting and enforcement of coding standards for open source projects (read that as many cooks with their fingers in the soup). I'd like to have PHP catch such coding instances and report them so that "cooks" would be made aware of them and could then standardize the clauses - that is, use braces to make it perfectly clear the extent of the clause. – SimonT Apr 04 '16 at 07:55