Passed
Push — feature/updates-nov25 ( 8eba28...986d8f )
by Johan
15:38 queued 09:59
created

SsoRegistrationBypassOptionType   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 18 4
A getSQLDeclaration() 0 3 1
A convertToPHPValue() 0 19 3
A getName() 0 3 1
A requiresSQLCommentHint() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Doctrine\Type;
20
21
use Doctrine\DBAL\Platforms\AbstractPlatform;
22
use Doctrine\DBAL\Types\ConversionException;
23
use Doctrine\DBAL\Types\IntegerType;
24
use Surfnet\Stepup\Configuration\Value\SsoRegistrationBypassOption;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Configura...egistrationBypassOption 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...
25
use TypeError;
26
27
/**
28
 * Custom Type for the SsoRegistrationBypassOption Value Object
29
 *
30
 * This option enables and disables the "GSSP fallback" option in the Stepup-Gateway for an institution.
31
 * "GSSP fallback" forwards the second factor authentications at LoA 1.5 to the fallback GSSP when a user does not have
32
 * any active tokens
33
 */
34
class SsoRegistrationBypassOptionType extends IntegerType
35
{
36
    public const NAME = 'stepup_sso_registration_bypass_option';
37
38
    public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
39
    {
40
        return $platform->getIntegerTypeDeclarationSQL($column);
41
    }
42
43
    public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?int
44
    {
45
        if (is_null($value)) {
46
            return null;
47
        }
48
49
        if (!$value instanceof SsoRegistrationBypassOption) {
50
            throw new ConversionException(
51
                sprintf(
52
                    "Encountered illegal sso registration bypass option %s '%s', expected a 
53
                    SsoRegistrationBypassOption instance",
54
                    get_debug_type($value),
55
                    is_scalar($value) ? (string)$value : '',
56
                ),
57
            );
58
        }
59
60
        return (int)$value->isEnabled();
61
    }
62
63
    public function convertToPHPValue($value, AbstractPlatform $platform): ?SsoRegistrationBypassOption
64
    {
65
        if (is_null($value)) {
66
            return null;
67
        }
68
69
        try {
70
            $ssoRegistrationBypassOption = new SsoRegistrationBypassOption((bool)$value);
71
        } catch (TypeError $e) {
72
            // get nice standard message, so we can throw it keeping the exception chain
73
            $doctrineExceptionMessage = ConversionException::conversionFailed(
74
                $value,
75
                $this->getName(),
76
            )->getMessage();
77
78
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
79
        }
80
81
        return $ssoRegistrationBypassOption;
82
    }
83
84
    public function getName(): string
85
    {
86
        return self::NAME;
87
    }
88
89
    public function requiresSQLCommentHint(AbstractPlatform $platform): bool
90
    {
91
        return false;
92
    }
93
}
94