GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — filters ( 0da638...f31b5a )
by
unknown
16:04
created

LoadModel   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 59
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C loadModel() 0 46 11
1
<?php
2
3
namespace app\traits;
4
5
use devgroup\TagDependencyHelper\ActiveRecordHelper;
6
use Yii;
7
use yii\caching\TagDependency;
8
use yii\db\ActiveRecord;
9
use yii\web\NotFoundHttpException;
10
11
trait LoadModel
12
{
13
    /**
14
     * @param $modelName
15
     * @param $id
16
     * @param bool $createIfEmptyId
17
     * @param bool $useCache
18
     * @param int $cacheLifetime
19
     * @param bool $throwException
20
     * @return ActiveRecord|null
0 ignored issues
show
Documentation introduced by
Should the return type not be null|object?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
21
     * @throws NotFoundHttpException
22
     */
23
    public static function loadModel(
24
        $modelName,
25
        $id,
26
        $createIfEmptyId = false,
27
        $useCache = true,
28
        $cacheLifetime = 3600,
29
        $throwException = true
30
    ) {
31
        $model = null;
32
        if (empty($id)) {
33
            if ($createIfEmptyId === true) {
34
                $model = new $modelName;
35
            } else {
36
                if ($throwException) {
37
                    throw new NotFoundHttpException;
38
                } else {
39
                    return null;
40
                }
41
            }
42
        }
43
        if ($useCache === true && $model===null) {
44
            $model = Yii::$app->cache->get($modelName::className() . ":" . $id);
45
        }
46
        if (!is_object($model)) {
47
            $model = $modelName::findOne($id);
48
            
49
            if (is_object($model) && $useCache === true) {
50
                Yii::$app->cache->set(
51
                    $modelName::className() . ":" . $id,
52
                    $model,
53
                    $cacheLifetime,
54
                    new TagDependency([
55
                        'tags' => ActiveRecordHelper::getCommonTag($modelName::className()),
56
                    ])
57
                );
58
            }
59
        }
60
        if (!is_object($model)) {
61
            if ($throwException) {
62
                throw new NotFoundHttpException;
63
            } else {
64
                return null;
65
            }
66
        }
67
        return $model;
68
    }
69
}
70