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 ( f17bc5...16aa08 )
by Ivan
13:41
created

UpdateNameAction::run()   C

Complexity

Conditions 8
Paths 9

Size

Total Lines 30
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 30
rs 5.3846
cc 8
eloc 19
nc 9
nop 0
1
<?php
2
3
4
namespace app\modules\image\actions;
5
6
7
use app\modules\image\models\Image;
8
9
use creocoder\flysystem\Filesystem;
10
use Yii;
11
use yii\base\Action;
12
use yii\base\Exception;
13
use yii\web\NotAcceptableHttpException;
14
15
class UpdateNameAction extends Action
16
{
17
    public function run()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
18
    {
19
        if (Yii::$app->request->isAjax === false) {
20
            throw new NotAcceptableHttpException();
21
        }
22
        $oldName = Yii::$app->request->post('oldname', '');
23
        $newName = Yii::$app->request->post('newname', '');
24
        if (!empty($oldName) && !empty($newName) && $oldName !== $newName) {
25
            try {
26
                /**
27
                 * @var Filesystem $fs
28
                 */
29
                $fs = Yii::$app->getModule('image')->fsComponent;
30
                if ($fs->has($oldName)) {
31
                    if ($fs->rename($oldName, $newName)) {
32
                        Image::updateAll(['filename' => $newName], ['filename' => $oldName]);
33
                    } else {
34
                        throw new Exception('Error in renaming');
35
                    }
36
                } else {
37
                    throw new Exception('No files to rename');
38
                }
39
40
            } catch (Exception $except) {
41
                return $except->getMessage();
42
            }
43
            return $newName;
44
        }
45
        return '';
46
    }
47
}