Passed
Push — master ( 25a926...39145a )
by
unknown
20:30
created

MfaProviderManifest   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
eloc 36
c 1
b 0
f 0
dl 0
loc 119
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A unlock() 0 3 1
A __construct() 0 18 1
A verify() 0 3 1
A isActive() 0 3 1
A getIdentifier() 0 3 1
A deactivate() 0 3 1
A getInstance() 0 3 1
A getDescription() 0 3 1
A isDefaultProviderAllowed() 0 3 1
A getSetupInstructions() 0 3 1
A getTitle() 0 3 1
A update() 0 3 1
A getIconIdentifier() 0 3 1
A activate() 0 3 1
A isLocked() 0 3 1
A handleRequest() 0 6 1
A createInstance() 0 4 1
A canProcess() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Core\Authentication\Mfa;
19
20
use Psr\Container\ContainerInterface;
21
use Psr\Http\Message\ResponseInterface;
22
use Psr\Http\Message\ServerRequestInterface;
23
24
/**
25
 * Adapter for MFA providers
26
 *
27
 * @internal
28
 */
29
final class MfaProviderManifest implements MfaProviderManifestInterface
30
{
31
    private string $identifier;
32
    private string $title;
33
    private string $description;
34
    private string $setupInstructions;
35
    private string $iconIdentifier;
36
    private bool $isDefaultProviderAllowed;
37
    private string $serviceName;
38
    private ContainerInterface $container;
39
    private ?MfaProviderInterface $instance = null;
40
41
    public function __construct(
42
        string $identifier,
43
        string $title,
44
        string $description,
45
        string $setupInstructions,
46
        string $iconIdentifier,
47
        bool $isDefaultProviderAllowed,
48
        string $serviceName,
49
        ContainerInterface $container
50
    ) {
51
        $this->identifier = $identifier;
52
        $this->title = $title;
53
        $this->description = $description;
54
        $this->setupInstructions = $setupInstructions;
55
        $this->iconIdentifier = $iconIdentifier;
56
        $this->isDefaultProviderAllowed = $isDefaultProviderAllowed;
57
        $this->serviceName = $serviceName;
58
        $this->container = $container;
59
    }
60
61
    public function getIdentifier(): string
62
    {
63
        return $this->identifier;
64
    }
65
66
    public function getTitle(): string
67
    {
68
        return $this->title;
69
    }
70
71
    public function getDescription(): string
72
    {
73
        return $this->description;
74
    }
75
76
    public function getIconIdentifier(): string
77
    {
78
        return $this->iconIdentifier;
79
    }
80
81
    public function getSetupInstructions(): string
82
    {
83
        return $this->setupInstructions;
84
    }
85
86
    public function isDefaultProviderAllowed(): bool
87
    {
88
        return $this->isDefaultProviderAllowed;
89
    }
90
91
    public function canProcess(ServerRequestInterface $request): bool
92
    {
93
        return $this->getInstance()->canProcess($request);
94
    }
95
96
    public function isActive(MfaProviderPropertyManager $propertyManager): bool
97
    {
98
        return $this->getInstance()->isActive($propertyManager);
99
    }
100
101
    public function isLocked(MfaProviderPropertyManager $propertyManager): bool
102
    {
103
        return $this->getInstance()->isLocked($propertyManager);
104
    }
105
106
    public function verify(ServerRequestInterface $request, MfaProviderPropertyManager $propertyManager): bool
107
    {
108
        return $this->getInstance()->verify($request, $propertyManager);
109
    }
110
111
    public function handleRequest(
112
        ServerRequestInterface $request,
113
        MfaProviderPropertyManager $propertyManager,
114
        string $type
115
    ): ResponseInterface {
116
        return $this->getInstance()->handleRequest($request, $propertyManager, $type);
117
    }
118
119
    public function activate(ServerRequestInterface $request, MfaProviderPropertyManager $propertyManager): bool
120
    {
121
        return $this->getInstance()->activate($request, $propertyManager);
122
    }
123
124
    public function deactivate(ServerRequestInterface $request, MfaProviderPropertyManager $propertyManager): bool
125
    {
126
        return $this->getInstance()->deactivate($request, $propertyManager);
127
    }
128
129
    public function unlock(ServerRequestInterface $request, MfaProviderPropertyManager $propertyManager): bool
130
    {
131
        return $this->getInstance()->unlock($request, $propertyManager);
132
    }
133
134
    public function update(ServerRequestInterface $request, MfaProviderPropertyManager $propertyManager): bool
135
    {
136
        return $this->getInstance()->update($request, $propertyManager);
137
    }
138
139
    private function getInstance(): MfaProviderInterface
140
    {
141
        return $this->instance ?? $this->createInstance();
142
    }
143
144
    private function createInstance(): MfaProviderInterface
145
    {
146
        $this->instance = $this->container->get($this->serviceName);
147
        return $this->instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->instance could return the type null which is incompatible with the type-hinted return TYPO3\CMS\Core\Authentic...fa\MfaProviderInterface. Consider adding an additional type-check to rule them out.
Loading history...
148
    }
149
}
150