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

Http   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C exception() 0 22 9
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