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.

ExistingUsernameChallenge   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
B process() 0 50 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Challenge;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use LM\AuthAbstractor\Configuration\IApplicationConfiguration;
9
use LM\AuthAbstractor\Model\AuthenticationProcess;
10
use LM\AuthAbstractor\Model\IAuthenticationProcess;
11
use LM\Common\Model\StringObject;
12
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
13
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
14
use Symfony\Component\Form\Extension\Core\Type\TextType;
15
use LM\AuthAbstractor\Implementation\ChallengeResponse;
16
use Symfony\Component\Form\FormError;
17
use LM\AuthAbstractor\Model\IChallengeResponse;
18
use Symfony\Component\Form\FormFactoryInterface;
19
use Symfony\Component\HttpFoundation\Response;
20
use Twig_Environment;
21
22
/**
23
 * A challenge for asking the user to enter an existing username, which can
24
 * be used by following challenges (e.g. PasswordChallenge or U2fChallenge).
25
 */
26
class ExistingUsernameChallenge implements IChallenge
27
{
28
    /** @var IApplicationConfiguration */
29
    private $appConfig;
30
31
    /** @var FormFactoryInterface */
32
    private $formFactory;
33
34
    /** @var HttpFoundationFactory */
35
    private $httpFoundationFactory;
36
37
    /** @var Twig_Environment */
38
    private $twig;
39
40
    /**
41
     * @internal
42
     */
43
    public function __construct(
44
        IApplicationConfiguration $appConfig,
45
        FormFactoryInterface $formFactory,
46
        HttpFoundationFactory $httpFoundationFactory,
47
        Twig_Environment $twig
48
    ) {
49
        $this->appConfig = $appConfig;
50
        $this->formFactory = $formFactory;
51
        $this->httpFoundationFactory = $httpFoundationFactory;
52
        $this->twig = $twig;
53
    }
54
55
    /**
56
     * @internal
57
     */
58
    public function process(
59
        IAuthenticationProcess $process,
60
        ?ServerRequestInterface $httpRequest
61
    ): IChallengeResponse {
62
        $form = $this
63
            ->formFactory
64
            ->createBuilder()
65
            ->add('username', TextType::class)
66
            ->add('submit', SubmitType::class)
67
            ->getForm()
68
        ;
69
70
        if (null !== $httpRequest) {
71
            $form->handleRequest($this->httpFoundationFactory->createRequest($httpRequest));
72
        }
73
        if ($form->isSubmitted() && !$this->appConfig->isExistingMember($form['username']->getData())) {
74
            $form
75
                ->get('username')
76
                ->addError(new FormError('The username is invalid.'))
77
            ;
78
        }
79
80
        if ($form->isSubmitted() && $form->isValid()) {
81
            $newDm = $process
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

81
            $newDm = /** @scrutinizer ignore-deprecated */ $process
Loading history...
82
                ->getTypedMap()
83
                ->add(
84
                    'username',
85
                    new StringObject($form->get('username')->getData()),
86
                    StringObject::class
87
                )
88
            ;
89
90
            return new ChallengeResponse(
91
                new AuthenticationProcess($newDm),
92
                null,
93
                false,
94
                true
95
            )
96
            ;
97
        }
98
99
        $response = new Response($this->twig->render('existing_username.html.twig', [
100
            "form" => $form->createView(),
101
        ]));
102
103
        return new ChallengeResponse(
104
            $process,
105
            $response,
106
            $form->isSubmitted(),
107
            false
108
        )
109
        ;
110
    }
111
}
112