排版
程式碼越靠左邊就越平易近人
限制每行字數
換行
// bad code, 條件太長了
if ($conditions['status'] === true && $conditions['is_test'] === false && $conditions['type'] === 'boolean') {
echo 'hello';
}
// good code, 換行,這種方式還能寫註解
if ($conditions['status'] === true
&& $conditions['is_test'] === false
&& $conditions['value'] === 'hello') {
echo 'hello';
}
// good code, 萃取出新的方法
if ($this->canEcho($conditions)) {
echo 'hello';
}使用匿名函式
三元運算子正確用法
使用雙引號或 Heredoc
Last updated