入れ子になった IF ステートメントの大規模なグループがあり、速度、サイズ、読みやすさを最適化する方法について何か提案があるかどうか疑問に思っていました。
以下は、if ステートメントの 1 つとそのネストされたステートメントのサンプルです。ドキュメントには、これらのうち約 25 ~ 30 個が含まれます。
if( $row["inlet_moisture"] > $row["inlet_moisture_high_warning"] ) {
if( $row["inlet_moisture"] > $row["inlet_moisture_high_critical"] ) {
if( $row["inlet_high_critical"] == 0 ) {
if( $row["email_notification"] == 1 ) {
}
if( $row["mobile_notification"] == 1 ) {
}
}
} else {
if( $row["inlet_high_warning"] == 0 ) {
if( $row["email_notification"] == 1 ) {
}
if( $row["mobile_notification"] == 1 ) {
}
}
}
} else if( $row["inlet_moisture"] < $row["inlet_moisture_low_warning"] ) {
if( $row["inlet_moisture"] < $row["inlet_moisture_low_critical"] ) {
if( $row["inlet_low_critical"] == 0 ) {
if( $row["email_notification"] == 1 ) {
}
if( $row["mobile_notification"] == 1 ) {
}
}
} else {
if( $row["inlet_low_warning"] == 0 ) {
if( $row["email_notification"] == 1 ) {
}
if( $row["mobile_notification"] == 1 ) {
}
}
}
}
アイデアは次のとおりです。読み取り値(温度/速度/水分)があり、それがいずれかの制限 (高警告 / 高クリティカル / 低警告 / 低クリティカル) に達しているかどうかを確認する必要があります。そのためのアラーム。アラームが送信されていない場合は、ユーザーがアラーム通知 (モバイル/電子メール/両方) を要求したかどうかを確認する必要があります
現在、これは機能します。私はそれがどれほど重いのが好きではないのですか?これを改善できますか?
ありがとう。