【发布时间】:2013-04-16 23:59:33
【问题描述】:
我有一个很长的 if 条件,如下所示。有两个条件必须不满足,才能评估语句。我确实将它作为一个带有很多 && 和的衬里!但它变得不可读。我尝试将其拆分为if elsif else,它更具可读性但读起来不太好,因为第一个if elsif 块中没有代码。
整理此代码块的最佳做法是什么?
if ($instructionObject->instruction=='nesting_grammar' && $instructionObject->match=='>'){ //if instruction is a '>' child indicator
//don't change the child depth
}else if ($instructionObject->instruction=='selector' && is_object($this->instructions[$key+1]) && $this->instructions[$key+1]->instruction == 'nesting_grammar' && $this->instructions[$key+1]->match == '>'){ //if instruction is a selector followed by a '>'
//don't change the child depth
}else{
$insertOffset += $childDepth;
unset($childDepth);
}
【问题讨论】:
标签: php coding-style