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.

U2fRegistrationManager::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 1
dl 0
loc 21
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\U2f;
6
7
use LM\AuthAbstractor\Factory\U2fRegistrationFactory;
8
use LM\AuthAbstractor\Model\IU2fRegistration;
9
use LM\AuthAbstractor\Model\U2fRegistrationRequest;
10
use LM\Common\Model\ArrayObject;
11
use Firehed\U2F\RegisterRequest;
12
use Firehed\U2F\RegisterResponse;
13
use Firehed\U2F\SignRequest;
14
15
/**
16
 * This class is used for generating U2F register requests and processing their
17
 * responses.
18
 *
19
 * @internal
20
 */
21
class U2fRegistrationManager
22
{
23
    /** @var U2fRegistrationFactory */
24
    private $u2fRegistrationFactory;
25
26
    /** @var U2fServerGenerator */
27
    private $u2fServerGenerator;
28
29
    public function __construct(
30
        U2fRegistrationFactory $u2fRegistrationFactory,
31
        U2fServerGenerator $u2fServerGenerator
32
    ) {
33
        $this->u2fRegistrationFactory = $u2fRegistrationFactory;
34
        $this->u2fServerGenerator = $u2fServerGenerator;
35
    }
36
37
    /**
38
     * Generates a new U2F register requset.
39
     *
40
     * @param null|ArrayObject $registrations An array of IU2fRegistration.
41
     * @todo Use an ArrayObject instead?
42
     */
43
    public function generate(?ArrayObject $registrations = null): U2fRegistrationRequest
44
    {
45
        $server = $this
46
            ->u2fServerGenerator
47
            ->getServer()
48
        ;
49
        $request = $server->generateRegisterRequest();
50
51
        $signRequests = null;
52
        if (null !== $registrations) {
53
            $firehedRegs = array_map(
54
                [$this->u2fRegistrationFactory, 'toFirehed'],
55
                $registrations->toArray(IU2fRegistration::class)
56
            );
57
            $signRequests = new ArrayObject(
0 ignored issues
show
Deprecated Code introduced by
The class LM\Common\Model\ArrayObject 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

57
            $signRequests = /** @scrutinizer ignore-deprecated */ new ArrayObject(
Loading history...
58
                $server->generateSignRequests($firehedRegs),
59
                SignRequest::class
60
            );
61
        }
62
63
        return new U2fRegistrationRequest($request, $signRequests);
64
    }
65
66
    /**
67
     * Verifies and returns a new U2F registration from a response.
68
     *
69
     * @param string $u2fKeyResponse The response from the U2F token.
70
     * @param RegisterRequest $request The U2F register request.
71
     * @return IU2fRegistration The new U2F registration.
72
     * @todo Rename $u2fKeyResponse to $u2fTokenResponse
73
     */
74
    public function getU2fRegistrationFromResponse(
75
        string $u2fKeyResponse,
76
        RegisterRequest $request
77
    ): IU2fRegistration {
78
        $server = $this
79
            ->u2fServerGenerator
80
            ->getServer()
81
        ;
82
        $server
83
            ->setRegisterRequest($request)
84
        ;
85
        $response = RegisterResponse::fromJson($u2fKeyResponse);
86
        $registration = $server->register($response);
87
88
        return $this
89
            ->u2fRegistrationFactory
90
            ->fromFirehed($registration)
91
        ;
92
    }
93
}
94