Registration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateLink() 0 16 1
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Mediapart LaPresseLibre Library.
5
 *
6
 * CC BY-NC-SA <https://github.com/mediapart/lapresselibre>
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mediapart\LaPresseLibre;
13
14
use Mediapart\LaPresseLibre\Security\Encryption;
15
16
class Registration
17
{
18
    /**
19
     * @var string Route where your user will register into La Presse Libre platform.
20
     */
21
    const LINK_ROUTE = 'https://www.lapresselibre.fr/inscription-partenaire';
22
23
    /**
24
     * @var int
25
     */
26
    private $public_key;
27
28
    /**
29
     * @var Encryption
30
     */
31
    private $encryption;
32
33
    /**
34
     * @param int        $public_key
35
     * @param Encryption $encryption
36
     */
37
    public function __construct($public_key, Encryption $encryption)
38
    {
39
        $this->public_key = $public_key;
40
        $this->encryption = $encryption;
41
    }
42
43
    /**
44
     * Generate the link that allows you former users to
45
     * register themselves into La Presse Libre platform.
46
     *
47
     * @param string $email
48
     * @param string $userName
49
     * @param string $guid
50
     * @see https://github.com/NextINpact/LaPresseLibreSDK/wiki/Int%C3%A9gration-et-configuration-du-SDK#inscription-%C3%A0-la-presse-libre-depuis-une-plateforme-partenaire
51
     *
52
     * @return string
53
     */
54
    public function generateLink($email, $userName, $guid = null)
55
    {
56
        $user = $this->encryption->encrypt(
57
            [
0 ignored issues
show
Bug introduced by
array('Email' => $email,...rName, 'Guid' => $guid) of type array<string,null|string> is incompatible with the type string expected by parameter $message of Mediapart\LaPresseLibre\...y\Encryption::encrypt(). ( Ignorable by Annotation )

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

57
            /** @scrutinizer ignore-type */ [
Loading history...
58
                'Email' => $email,
59
                'Pseudo' => $userName,
60
                'Guid' => $guid,
61
            ],
62
            OPENSSL_RAW_DATA & OPENSSL_NO_PADDING
63
        );
64
65
        return sprintf(
66
            '%s?user=%s&partId=%s',
67
            self::LINK_ROUTE,
68
            rawurlencode($user),
69
            $this->public_key
70
        );
71
    }
72
}
73