PHP Code Specification Sonar version

Source: Internet
Author: User

    1. The curly brace of the class is not followed by another line

    2. Variable name initials lowercase hump mode [a-z][a-za-z0-9]*

    3. Note to start another line instead of following the code,

    4. The code snippet to remove the comment

    5. Swtich contains at least 3 case, otherwise use if.

    6. If etc cannot be nested more than 3 times

    7. The method in the class cannot be more than 20, and if it is more than one, split the

    8. Removing unused parameters

    9. Remove a useless variable

    10. If must be with else

    11. If always follow curly braces

    12. Don't have too many return in the code.

    13. Switch to add default

    14. The following code

if (condition) {return true;} else {return false;} or if (a==b) {return true;} Else{return false;} should be written as return Condition;return a==b;

Direct return function Compute_duration_in_milliseconds () {$duration = ((($hours *) + $minutes) * + $seconds) * 1000; return $duration;} Compliant Solutionfunction Compute_duration_in_milliseconds () {return (($hours * + $minutes) * + $seconds) * 10 00;}

Duplicate parameter function run () {Prepare (' action1 ') appears;  Non-compliant-' action1 ' is duplicated 3 times execute (' Action1 '); Release (' Action1 ');}  The correct procedure action_1 = ' action1 '; function run () {prepare (action_1);  Execute (action_1); Release (action_1);}

Boolean values directly determine if ($booleanVariable = = true) {/* ... */}if ($booleanVariable! = True) {/* ... */}if ($booleanVariable | | fal SE) {/* ... */}dosomething (!false);  Compliant solutionif ($booleanVariable) {/* ... */}if (! $booleanVariable) {/* ... */}if ($booleanVariable) {/* ... */ }dosomething (TRUE);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.