Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 911 Bytes

IfConditionComplexity.md

File metadata and controls

48 lines (36 loc) · 911 Bytes

Usage of complex expressions in the "If" condition (IfConditionComplexity)

Description

Complex expressions (with more than 3 boolean constructs) must be extracted to separated method or variable.

Examples

Bad:

If Id = "Expr1"
    Or Id = "Expr2"
    Or Id = "Expr3"
    Or Id = "Expr4"
    Or Id = "Expr5"
    Or Id = "Expr6"
    Or Id = "Expr7"
    Or Id = "Expr8"
    Or Id = "Expr9" Then

   doSomeWork();

EndIf; 

Good:

If IsCorrectId(Id) Then
   doSomeWork();
КонецЕсли;

Function IsCorrectId(Id)

    Return Id = "Expr1"
            Or Id = "Expr2"
            Or Id = "Expr3"
            Or Id = "Expr4"
            Or Id = "Expr5"
            Or Id = "Expr6"
            Or Id = "Expr7"
            Or Id = "Expr8"
            Or Id = "Expr9";

EndFunction