GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EmailRegistrationChallenge::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Challenge;
6
7
use LM\AuthAbstractor\Model\IAuthenticationProcess;
8
use LM\AuthAbstractor\Model\IChallengeResponse;
9
use LM\AuthAbstractor\Model\AuthenticationProcess;
10
use Psr\Http\Message\ServerRequestInterface;
11
use LM\Common\Enum\Scalar;
12
use LM\AuthAbstractor\Implementation\ChallengeResponse;
13
use Twig_Environment;
14
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
15
use Symfony\Component\Form\FormFactoryInterface;
16
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
17
use LM\AuthAbstractor\Configuration\IApplicationConfiguration;
18
use Symfony\Component\HttpFoundation\Response;
19
20
/**
21
 * A challenge for asking the user for their email address.
22
 *
23
 * @todo There should be an alternative, combined with
24
 * CredentialRegistrationChallenge.
25
 */
26
class EmailRegistrationChallenge implements IChallenge
27
{
28
    /** @var int */
29
    const CODE_MIN = 0;
30
31
    /** @var int */
32
    const CODE_MAX = 999999;
33
34
    /** @var IApplicationConfiguration */
35
    private $appConfig;
36
37
    /** @var FormFactoryInterface */
38
    private $formFactory;
39
40
    /** @var HttpFoundationFactory */
41
    private $httpFoundationFactory;
42
43
    /** @var Twig_Environment */
44
    private $twig;
45
46
    /**
47
     * @internal
48
     */
49
    public function __construct(
50
        IApplicationConfiguration $appConfig,
51
        FormFactoryInterface $formFactory,
52
        HttpFoundationFactory $httpFoundationFactory,
53
        Twig_Environment $twig
54
    ) {
55
        $this->appConfig = $appConfig;
56
        $this->formFactory = $formFactory;
57
        $this->httpFoundationFactory = $httpFoundationFactory;
58
        $this->twig = $twig;
59
    }
60
61
    /**
62
     * @internal
63
     */
64
    public function process(
65
        IAuthenticationProcess $authenticationProcess,
66
        ?ServerRequestInterface $httpRequest
67
    ): IChallengeResponse {
68
        $form = $this
69
            ->formFactory
70
            ->createBuilder()
71
            ->add('email')
72
            ->add('submit', SubmitType::class)
73
            ->getForm()
74
        ;
75
76
        if (null !== $httpRequest) {
77
            $form->handleRequest(
78
                $this->httpFoundationFactory->createRequest($httpRequest)
79
            );
80
        }
81
82
        if ($form->isSubmitted() && $form->isValid()) {
83
            return new ChallengeResponse(
84
                new AuthenticationProcess(
85
                    $authenticationProcess
0 ignored issues
show
Deprecated Code introduced by
The function LM\AuthAbstractor\Model\...nProcess::getTypedMap() has been deprecated. ( Ignorable by Annotation )

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

85
                    /** @scrutinizer ignore-deprecated */ $authenticationProcess
Loading history...
86
                    ->getTypedMap()
87
                    ->set(
88
                        'email',
89
                        $form['email']->getData(),
90
                        Scalar::_STR
91
                    )
92
                ),
93
                null,
94
                false,
95
                true
96
            )
97
            ;
98
        }
99
100
        $response = new Response($this->twig->render('email_registration.html.twig', [
101
            "form" => $form->createView(),
102
        ]));
103
104
        return new ChallengeResponse(
105
            $authenticationProcess,
106
            $response,
107
            false,
108
            false
109
        )
110
        ;
111
    }
112
}
113