1.2.1208. Too Many Stringed Elseif

Too many if/then structures are linked. If a pattern emerges, such as with the illustration below, they might be replaced with a loop, a switch() or a match() statement.

This rule also takes into account else if structures.

<?php

if      ($a === 1) {   }
elseif  ($a === 2) {   }
elseif  ($a === 3) {   }
else if ($a === 4) {   } // else if
elseif  ($a === 5) {   }

?>

Name

Default

Type

Description

maxIf

5

integer

Maximum number of allowed stringed if-then-elseif structure.

See also Bail Out Early.

1.2.1208.1. Suggestions

  • Replace the if-then with a loop

  • Use the bail early strategy to isolate the if-then

1.2.1208.2. Specs

Short name

Structures/TooManyElseif

Rulesets

All, Suggestions

Exakat since

2.3.6

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud