Completed
Push — master ( 9231cc...030c4e )
by Robbie
14s queued 11s
created

Method::getVerifyHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace SilverStripe\TOTP;
4
5
use SilverStripe\Core\Config\Configurable;
6
use SilverStripe\Core\Environment;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Core\Manifest\ModuleLoader;
9
use SilverStripe\MFA\Method\Handler\VerifyHandlerInterface;
0 ignored issues
show
Bug introduced by
The type SilverStripe\MFA\Method\...\VerifyHandlerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface;
11
use SilverStripe\MFA\Method\MethodInterface;
12
use SilverStripe\View\Requirements;
13
14
/**
15
 * Enables time-based one-time password (TOTP) authentication for the silverstripe/mfa module.
16
 */
17
class Method implements MethodInterface
18
{
19
    use Configurable;
20
21
    /**
22
     * The TOTP code length
23
     *
24
     * @config
25
     * @var int
26
     */
27
    private static $code_length = 6;
0 ignored issues
show
introduced by
The private property $code_length is not used, and could be removed.
Loading history...
28
29
    public function getURLSegment(): string
30
    {
31
        return 'totp';
32
    }
33
34
    public function getVerifyHandler(): VerifyHandlerInterface
35
    {
36
        return Injector::inst()->create(VerifyHandler::class);
37
    }
38
39
    public function getRegisterHandler(): RegisterHandlerInterface
40
    {
41
        return Injector::inst()->create(RegisterHandler::class);
42
    }
43
44
    public function getThumbnail(): string
45
    {
46
        return ModuleLoader::getModule('silverstripe/totp-authenticator')
47
            ->getResource('client/dist/images/totp.svg')
48
            ->getURL();
49
    }
50
51
    public function applyRequirements(): void
52
    {
53
        Requirements::javascript('silverstripe/totp-authenticator: client/dist/js/bundle.js');
54
        Requirements::css('silverstripe/totp-authenticator: client/dist/styles/bundle.css');
55
    }
56
57
    /**
58
     * TOTP authentication is only available if the required environment variable is set to enable encryption.
59
     *
60
     * @return bool
61
     */
62
    public function isAvailable(): bool
63
    {
64
        return !empty(Environment::getEnv('SS_MFA_SECRET_KEY'));
65
    }
66
67
    public function getUnavailableMessage(): string
68
    {
69
        return _t(__CLASS__ . '.NOT_CONFIGURED', 'This method has not been configured yet.');
70
    }
71
72
    /**
73
     * Get the length of the TOTP code
74
     *
75
     * @return int
76
     */
77
    public function getCodeLength(): int
78
    {
79
        return (int) $this->config()->get('code_length');
80
    }
81
}
82