Я делал рефакторинг кода в проекте в структуре Yii2.рефакторинг простого кода в Yii2 (if-else)
Я просто спрашиваю, может ли это быть написано лучше, с меньшим количеством повторений (я стараюсь следовать DRY всякий раз, когда могу). Любая рекомендация по литературе по этой теме более чем приветствуется, извините за плохой английский.
$exception = Yii::$app->errorHandler->exception;
if ($exception !== null) {
if (isset($exception->statusCode)) {
if ($exception->statusCode == 500) {
return $this->render('error-500', ['exception' => $exception]);
} elseif ($exception->statusCode == 404) {
return $this->render('error-404', ['exception' => $exception]);
} else {
return $this->render('error', ['exception' => $exception]);
}
} elseif (isset($exception->code)) {
if ($exception->code == 500) {
return $this->render('error-500', ['exception' => $exception]);
} elseif ($exception->code == 404) {
return $this->render('error-404', ['exception' => $exception]);
} else {
return $this->render('error', ['exception' => $exception]);
}
}
} else {
$exception = new \yii\web\HttpException(500);
return $this->render('error-500', ['exception' => $exception]);
}
Спасибо и Vm человек. Мой ум прекратился после 10 часов работы. –
Мне повезло, что мой ум остановился после 8 часов работы – scaisEdge