Issues (75)

app/Http/Api/Backend/Form/LoginForm.php (4 issues)

1
<?php
2
namespace App\Http\Api\Backend\Form;
3
4
use App\Factory\SessionFactory;
5
use App\Http\Form\LoginForm as BaseLoginForm;
6
use Yii;
7
8
class LoginForm extends BaseLoginForm
9
{
10
    /**
11
     * Logs in a user using the provided username and password.
12
     *
13
     * @return bool whether the user is logged in successfully
14
     */
15 1
    protected function handleInternal()
16
    {
17 1
        $transaction = Yii::$app->getDb()->beginTransaction();
18
        try {
19 1
            $user = $this->getUser();
20
21 1
            $session = SessionFactory::create(
22 1
                $user->id,
23 1
                Yii::$app->params['user.session.duration'],
24 1
                Yii::$app->params['user.session.refreshTokenDuration'],
25 1
                Yii::$app->getRequest()
0 ignored issues
show
It seems like Yii::app->getRequest() can also be of type yii\console\Request; however, parameter $request of App\Factory\SessionFactory::create() does only seem to accept yii\web\Request, maybe add an additional type check? ( Ignorable by Annotation )

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

25
                /** @scrutinizer ignore-type */ Yii::$app->getRequest()
Loading history...
26
            );
27 1
            if (!$session->save()) {
28
                Yii::error($session->getErrors(), __METHOD__);
29
                throw new \RuntimeException('Unable to save session' . \yii\helpers\VarDumper::dumpAsString($session->getErrors()));
30
            }
31
32 1
            Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
0 ignored issues
show
It seems like $user can also be of type null; however, parameter $identity of yii\web\User::login() does only seem to accept yii\web\IdentityInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

32
            Yii::$app->user->login(/** @scrutinizer ignore-type */ $user, $this->rememberMe ? 3600 * 24 * 30 : 0);
Loading history...
The method login() does not exist on null. ( Ignorable by Annotation )

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

32
            Yii::$app->user->/** @scrutinizer ignore-call */ 
33
                             login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33 1
            $transaction->commit();
34
35
            return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('id' => $us...efreshTokenExpiresIn()) returns the type array<string,integer|string> which is incompatible with the documented return type boolean.
Loading history...
36 1
                'id' => $user->id,
37 1
                'username' => $user->username,
38 1
                'email' => $user->email,
39 1
                'token' => $session->token,
40 1
                'expires_in' => $session->getExpiresIn(),
41 1
                'refresh_token' => $session->refresh_token,
42 1
                'refresh_token_expire_in' => $session->getRefreshTokenExpiresIn(),
43
            ];
44
        } catch (\Throwable $e) {
45
            $transaction->rollBack();
46
            throw $e;
47
        }
48
    }
49
}
50