Completed
Push — master ( 726cec...790bd2 )
by Igor
02:55
created

Http::exception()   B

Complexity

Conditions 9
Paths 10

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 7.756
cc 9
eloc 15
nc 10
nop 2
1
<?php
2
3
namespace app\helpers;
4
5
use Yii;
6
7
class Http
8
{
9
    /**
10
     * Call HTTP Exception
11
     *
12
     * @param int $code HTTP Status
13
     * @param string $msg Message
14
     * @throws HttpException when invoked
15
     */
16
    public static function exception($code, $msg = null)
17
    {
18
        switch ($code) {
19
            case 400:
20
                $msg = $msg ? $msg : Yii::t('app', 'Bad request');
21
                throw new \yii\web\BadRequestHttpException($msg);
22
            case 401:
23
                $msg = $msg ? $msg : Yii::t('app', 'Access is unauthorized');
24
                throw new \yii\web\UnauthorizedHttpException($msg);
25
            case 403:
26
                $msg = $msg ? $msg : Yii::t('app', 'Access Denied');
27
                throw new \yii\web\ForbiddenHttpException($msg);
28
            case 404:
29
            default:
30
                $msg = $msg ? $msg : Yii::t('app', 'Page not found');
31
                throw new \yii\web\NotFoundHttpException($msg);
32
        }
33
    }
34
}
35