Passed
Push — master ( 99ed0e...bd8f44 )
by Nico
15:30 queued 06:48
created

UserDeletionHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unlockUser() 0 11 2
A delete() 0 9 1
A __construct() 0 1 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Player\Deletion\Handler;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
8
use Stu\Orm\Entity\User;
9
use Stu\Orm\Repository\SessionStringRepositoryInterface;
10
use Stu\Orm\Repository\UserLockRepositoryInterface;
11
use Stu\Orm\Repository\UserProfileVisitorRepositoryInterface;
12
use Stu\Orm\Repository\UserRepositoryInterface;
13
14
final class UserDeletionHandler implements PlayerDeletionHandlerInterface
15
{
16 2
    public function __construct(private SessionStringRepositoryInterface $sessionStringRepository, private UserProfileVisitorRepositoryInterface $userProfileVisitorRepository, private UserRepositoryInterface $userRepository, private UserLockRepositoryInterface $userLockRepository) {}
17
18 1
    #[Override]
19
    public function delete(User $user): void
20
    {
21 1
        $this->unlockUser($user);
22 1
        $this->sessionStringRepository->truncate($user);
23 1
        $this->userProfileVisitorRepository->truncateByUser($user);
24
25
        // delete user
26 1
        $this->userRepository->delete($user);
27
    }
28
29 1
    private function unlockUser(User $user): void
30
    {
31 1
        $lock = $user->getUserLock();
32
33 1
        if ($lock === null) {
34
            return;
35
        }
36
37 1
        $lock->setUser(null);
38 1
        $lock->setFormerUserId($user->getId());
39 1
        $this->userLockRepository->save($lock);
40
    }
41
}
42