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.

handleAuthenticationProcess()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 54
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 38
nc 7
nop 3
dl 0
loc 54
rs 8.3786
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Controller;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use LM\AuthAbstractor\Model\IAuthenticationCallback;
10
use LM\AuthAbstractor\Model\IAuthenticationProcess;
11
use LM\AuthAbstractor\Model\IAuthentifierResponse;
12
use LM\AuthAbstractor\Implementation\AuthentifierResponse;
13
14
/**
15
 * This is a class used by AuthenticationKernel to handle requests.
16
 *
17
 * @internal
18
 */
19
class AuthenticationProcessHandler
20
{
21
    /** @var ContainerInterface */
22
    private $container;
23
24
    /**
25
     * @param ContainerInterface $container The container of auth-abtractor.
26
     */
27
    public function __construct(ContainerInterface $container)
28
    {
29
        $this->container = $container;
30
    }
31
32
    /**
33
     * Used by the kernel to "apply" the current HTTP request on the current challenge.
34
     */
35
    public function handleAuthenticationProcess(
36
        ?ServerRequestInterface $httpRequest,
37
        IAuthenticationProcess $process,
38
        IAuthenticationCallback $callback
39
    ): IAuthentifierResponse {
40
        if ($process->isOngoing()) {
41
            $challenge = $this
42
                ->container
43
                ->get($process->getCurrentChallenge())
44
            ;
45
            $challengeResponse = $challenge->process($process, $httpRequest);
46
47
            $psrHttpResponse = $challengeResponse->getHttpResponse();
48
49
            if ($challengeResponse->isFinished()) {
50
                return new AuthentifierResponse(
51
                    $challengeResponse
52
                        ->getAuthenticationProcess()
53
                        ->resetNFailedAttempts()
54
                        ->setToNextChallenge(),
55
                    null
56
                );
57
            } elseif ($challengeResponse->isFailedAttempt()) {
58
                $updatedProcess = $challengeResponse
59
                    ->getAuthenticationProcess()
60
                    ->incrementNFailedAttempts()
61
                ;
62
                if ($updatedProcess->isFailed()) {
63
                    return new AuthentifierResponse(
64
                        $updatedProcess,
65
                        null
66
                    );
67
                } else {
68
                    return new AuthentifierResponse(
69
                        $updatedProcess,
70
                        $psrHttpResponse
71
                    );
72
                }
73
            } else {
74
                return new AuthentifierResponse(
75
                    $challengeResponse
76
                        ->getAuthenticationProcess(),
77
                    $psrHttpResponse
78
                );
79
            }
80
        } elseif ($process->isFailed()) {
81
            return new AuthentifierResponse(
82
                $process,
83
                $callback->handleFailedProcess($process)
84
            );
85
        } elseif ($process->isSucceeded()) {
86
            return new AuthentifierResponse(
87
                $process,
88
                $callback->handleSuccessfulProcess($process)
89
            );
90
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return LM\AuthAbstractor\Model\IAuthentifierResponse. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
91
    }
92
}
93