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.

ImageExist   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 7
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getFile() 0 32 6
1
<?php
2
3
namespace app\behaviors;
4
5
use app\modules\image\components\CompileSrcInterface;
6
use app\modules\image\models\ErrorImage;
7
use Yii;
8
use yii\base\Behavior;
9
use yii\helpers\ArrayHelper;
10
use yii\web\HttpException;
11
12
class ImageExist extends Behavior
13
{
14
    public $srcAttrName = 'filename';
15
16
    /**
17
     * @return mixed
18
     * @throws HttpException
19
     */
20
    public function getFile()
21
    {
22
        $src = $this->owner->{$this->srcAttrName};
23
        if (Yii::$app->fs->has($src) === false) {
24
            $src = Yii::$app->getModule('image')->noImageSrc;
25
            $errorImage = ErrorImage::findOne(
26
                ['img_id' => $this->owner->id, 'class_name' => $this->owner->className()]
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
27
            );
28
            if ($errorImage === null) {
29
                $errorImage = new ErrorImage;
30
                $errorImage->setAttributes(['img_id' => $this->owner->id, 'class_name' => $this->owner->className()]);
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
31
                $errorImage->save();
32
            }
33
        } else {
34
            $fs = Yii::$app->fs;
35
            $components = ArrayHelper::index(Yii::$app->getModule('image')->components, 'necessary.class');
36
            $adapterName = ArrayHelper::getValue($components, $fs::className() . '.necessary.srcAdapter', null);
37
            if ($adapterName === null) {
38
                throw new HttpException(Yii::t('app', 'Set src compiler adapter'));
39
            }
40
            if (class_exists($adapterName) === false) {
41
                throw new HttpException(Yii::t('app', "Class $adapterName not found"));
42
            }
43
            $adapter = new $adapterName;
44
            if ($adapter instanceof CompileSrcInterface) {
45
                $src = $adapter->CompileSrc($src);
46
            } else {
47
                throw new HttpException(Yii::t('app', "Class $adapterName should implement CompileSrcInterface"));
48
            }
49
        }
50
        return $src;
51
    }
52
}