Avoid having inline control statements (PHP) | CAST Appmarq

Avoid having inline control statements (PHP)

CRITICAL

Rule Definition
Using curly braces with the control statements increases readability and decreases the likelihood of logical errors being introduced when new code lines are added.

Remediation
Use curly braces with the control statements even in situations where they are technically optional.

Violation Code Sample
Sample 1 : if ($variable1==1) echo '1';

Sample 2:
foreach ($stringParade as $hit)
    $hitParade[] = $hit + 0; //cast to integer
Fixed Code Sample
Remediation for Sample 1:
if ($variable1==1) {
echo '1';
}

Remediation for Sample 2:
foreach ($stringParade as $hit) {
    $hitParade[] = $hit + 0; //cast to integer
}

Reference
https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php http://pear.php.net/package/PHP_CodeSniffer/docs/2.5.1/PHP_CodeSniffer/Generic_Sniffs_ControlStructures_InlineControlStructureSniff.html

Related Technologies

Health Factor

  Total Quality Index


Technical Criterion
Complexity - Algorithmic and Control Structure Complexity

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

97.76%

Total Violations
5,272
Total Opportunities
235,869
Average Violations / App.
142.49
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Select from drop-down

96.59%

IT & Business Consulting

95.37%

Telecommunications

96.38%