MagicLink::sendMagicLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 3
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\ldapPasswordReset;
6
7
use SimpleSAML\{Configuration, Module, Utils};
8
9
/**
10
 * This class takes care of sending the magic links through email
11
 *
12
 * @package simplesamlphp/simplesamlphp-module-ldapPasswordReset
13
 */
14
class MagicLink
15
{
16
    /** @var \SimpleSAML\Configuration */
17
    protected Configuration $config;
18
19
    /** @var \SimpleSAML\Configuration */
20
    protected Configuration $moduleConfig;
21
22
23
    /**
24
     * @param \SimpleSAML\Configuration $config The configuration to use.
25
     */
26
    public function __construct(Configuration $config)
27
    {
28
        $this->config = $config;
29
        $this->moduleConfig = Configuration::getOptionalConfig('module_ldapPasswordReset.php');
30
    }
31
32
33
    /**
34
     * Send magic link
35
     *
36
     * @param string $email
37
     * @param string $token
38
     * @param int $validUntil
39
     * @return void
40
     */
41
    public function sendMagicLink(string $email, string $token, int $validUntil): void
42
    {
43
        $url = Module::getModuleURL('ldapPasswordReset/validateMagicLink', ['t' => $token]);
44
45
        $mail = new Utils\EMail(
46
            $this->moduleConfig->getOptionalString('email.subject', 'Password reset'),
0 ignored issues
show
Bug introduced by
It seems like $this->moduleConfig->get...ect', 'Password reset') can also be of type null; however, parameter $subject of SimpleSAML\Utils\EMail::__construct() does only seem to accept string, 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

46
            /** @scrutinizer ignore-type */ $this->moduleConfig->getOptionalString('email.subject', 'Password reset'),
Loading history...
47
            $this->moduleConfig->getOptionalString('email.from', $this->config->getString('technicalcontact_email')),
48
            $email,
49
            'ldapPasswordReset:mailtxt.twig',
50
            'ldapPasswordReset:mailhtml.twig'
51
        );
52
        $mail->setData(['url' => $url, 'validUntil' => $validUntil]);
53
        $mail->setText('{url}');
54
        $mail->send();
55
    }
56
}
57