Passed
Push — master ( c4afc2...9cde23 )
by Pieter van der
27:49 queued 12:42
created

RecoveryTokenConfig::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright 2022 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens;
22
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\Exception\RecoveryTokenConfigurationException;
24
25
class RecoveryTokenConfig
26
{
27
    /**
28
     * @var bool
29
     */
30
    private $smsEnabled;
31
32
    /**
33
     * @var bool
34
     */
35
    private $safeStoreCodeEnabled;
36
37
    public function __construct(bool $smsEnabled, bool $safeStoreCodeEnabled)
38
    {
39
        if ($smsEnabled === false && $safeStoreCodeEnabled === false) {
40
            throw new RecoveryTokenConfigurationException('The SMS or safe-store code recovery token must be enabled');
41
        }
42
        $this->smsEnabled = $smsEnabled;
43
        $this->safeStoreCodeEnabled = $safeStoreCodeEnabled;
44
    }
45
46
    public function isSmsDisabled(): bool
47
    {
48
        return !$this->smsEnabled;
49
    }
50
51
    public function isSafeStoreCodeDisabled(): bool
52
    {
53
        return !$this->safeStoreCodeEnabled;
54
    }
55
}
56