Completed
Push — master ( e1c233...726cec )
by Igor
07:28
created

Http::exception()   C

Complexity

Conditions 9
Paths 10

Size

Total Lines 22
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 6.412
cc 9
eloc 19
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
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
23
            case 401:
24
                $msg = $msg ? $msg : Yii::t('app', 'Access is unauthorized');
25
                throw new \yii\web\UnauthorizedHttpException($msg);
26
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
27
            case 403:
28
                $msg = $msg ? $msg : Yii::t('app', 'Access Denied');
29
                throw new \yii\web\ForbiddenHttpException($msg);
30
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
31
            case 404:
32
            default:
33
                $msg = $msg ? $msg : Yii::t('app', 'Page not found');
34
                throw new \yii\web\NotFoundHttpException($msg);
35
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
36
        }
37
    }
38
}
39