Completed
Push — master ( 9ed240...526dfe )
by Razon
02:55
created

LogoutForm::handleInternal()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 10
cc 3
nc 3
nop 0
crap 12
1
<?php
2
namespace App\Http\Api\Backend\Form;
3
4
use App\Form\Form;
5
use App\Htpp\User\LogoutInterface;
0 ignored issues
show
Bug introduced by
The type App\Htpp\User\LogoutInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Yii;
7
use yii\web\IdentityInterface;
8
9
class LogoutForm extends Form
10
{
11
    protected function handleInternal()
12
    {
13
        $user = $this->getUser();
14
        if (!$user) {
15
            return;
16
        }
17
18
        if ($user instanceof LogoutInterface) {
19
            $user->logout();
0 ignored issues
show
Bug introduced by
The method logout() does not exist on yii\web\IdentityInterface. It seems like you code against a sub-type of yii\web\IdentityInterface such as App\Model\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            $user->/** @scrutinizer ignore-call */ 
20
                   logout();
Loading history...
20
            return;
21
        }
22
23
        Yii::$app->getUser()->logout();
24
    }
25
26
    private $user;
27
28
    /**
29
     * @return null|IdentityInterface
30
     */
31
    public function getUser()
32
    {
33
        if ($this->user === null) {
34
            $this->user = Yii::$app->getUser()->getIdentity();
35
        }
36
37
        return $this->user;
38
    }
39
}
40