Test Failed
Push — master ( de46cf...ec82a1 )
by Alexander
03:16
created

AuthService::signup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 12
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A AuthService::isGuest() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth;
6
7
use App\User\UserRepository;
8
use Throwable;
9
use Yiisoft\Auth\IdentityInterface;
10
use Yiisoft\User\CurrentUser;
11
12
final class AuthService
13
{
14
    public function __construct(
15
        private CurrentUser $currentUser,
16
        private UserRepository $userRepository,
17
        private IdentityRepository $identityRepository,
18
    ) {
19 10
    }
20
21
    public function login(string $login, string $password): bool
22
    {
23
        $user = $this->userRepository->findByLoginWithAuthIdentity($login);
24 10
25 10
        if ($user === null || !$user->validatePassword($password)) {
26 10
            return false;
27
        }
28
29 4
        return $this->currentUser->login($user->getIdentity());
30
    }
31 4
32
    /**
33 4
     * @throws Throwable
34 3
     */
35
    public function logout(): bool
36
    {
37 1
        $identity = $this->currentUser->getIdentity();
38
39
        if ($identity instanceof Identity) {
40
            $identity->regenerateCookieLoginKey();
41
            $this->identityRepository->save($identity);
42
        }
43 1
44
        return $this->currentUser->logout();
45 1
    }
46
47 1
    public function getIdentity(): IdentityInterface
48 1
    {
49 1
        return $this->currentUser->getIdentity();
50
    }
51
52 1
    public function isGuest(): bool
53
    {
54
        return $this->currentUser->isGuest();
55
    }
56
}
57