Passed
Push — master ( 4d4f83...d89b39 )
by Nico
39:26 queued 25:42
created

RequestDeletionConfirmation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 8.33%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 44
ccs 2
cts 24
cp 0.0833
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A request() 0 35 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Player\Deletion\Confirmation;
6
7
use Noodlehaus\ConfigInterface;
8
use RuntimeException;
9
use Stu\Lib\Mail\MailFactoryInterface;
10
use Stu\Module\Control\StuHashInterface;
11
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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...
12
use Stu\Orm\Entity\UserInterface;
13
use Stu\Orm\Repository\UserRepositoryInterface;
14
15
final class RequestDeletionConfirmation implements RequestDeletionConfirmationInterface
16
{
17 1
    public function __construct(
18
        private UserRepositoryInterface $userRepository,
19
        private MailFactoryInterface $mailFactory,
20
        private ConfigInterface $config,
21
        private StuHashInterface $stuHash
22 1
    ) {}
23
24
    public function request(UserInterface $user): void
25
    {
26
        $registration = $user->getRegistration();
27
        $token = $this->stuHash->hash(time() . $registration->getCreationDate());
28
29
        $registration->setDeletionMark(UserEnum::DELETION_REQUESTED);
30
        $registration->setPasswordToken($token);
31
32
        $body = <<<EOT
33
            Hallo\n\n
34
            Du hast eine Accountlöschung in Star Trek Universe angefordert.\n\n
35
            Bitte bestätige die Löschung mittels Klick auf folgenden Link:\n
36
            %s/?CONFIRM_ACCOUNT_DELETION=1&token=%s\n
37
            Das STU-Team\n\n,
38
            EOT;
39
40
        $mail = $this->mailFactory->createStuMail()
41
            ->withDefaultSender()
42
            ->addTo($registration->getEmail())
43
            ->setSubject('Star Trek Universe - Accountlöschung')
44
            ->setBody(
45
                sprintf(
46
                    $body,
47
                    $this->config->get('game.base_url'),
48
                    $token,
49
                )
50
            );
51
52
        try {
53
            $mail->send();
54
        } catch (RuntimeException) {
55
            return;
56
        }
57
58
        $this->userRepository->save($user);
59
    }
60
}
61