DocumentNumberType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A convertToDatabaseValue() 0 17 4
A getSQLDeclaration() 0 3 1
A convertToPHPValue() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright 2014 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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupMiddleware\ApiBundle\Doctrine\Type;
22
23
use Doctrine\DBAL\Platforms\AbstractPlatform;
24
use Doctrine\DBAL\Types\ConversionException;
25
use Doctrine\DBAL\Types\Type;
26
use Surfnet\Stepup\Exception\InvalidArgumentException;
27
use Surfnet\Stepup\Identity\Value\DocumentNumber;
28
29
/**
30
 * Custom Type for the Surfnet\Stepup\Identity\Value\DocumentNumber Object
31
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
32
class DocumentNumberType extends Type
33
{
34
    public const NAME = 'stepup_document_number';
35
36
    public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
37
    {
38
        return $platform->getVarcharTypeDeclarationSQL($column);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Platforms\...harTypeDeclarationSQL() has been deprecated: Use {@link getStringTypeDeclarationSQL()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
        return /** @scrutinizer ignore-deprecated */ $platform->getVarcharTypeDeclarationSQL($column);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
39
    }
40
41
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $platform should have a doc-comment as per coding-style.
Loading history...
42
     * @throws ConversionException
43
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
44
    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
45
    {
46
        if (is_null($value)) {
47
            return null;
48
        }
49
50
        if (!$value instanceof DocumentNumber) {
51
            throw new ConversionException(
52
                sprintf(
53
                    "Encountered illegal document number of type %s '%s', expected a DocumentNumber instance",
54
                    get_debug_type($value),
55
                    is_scalar($value) ? (string)$value : '',
56
                ),
57
            );
58
        }
59
60
        return $value->getDocumentNumber();
61
    }
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $platform should have a doc-comment as per coding-style.
Loading history...
64
     * @throws InvalidArgumentException
65
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
66
    public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DocumentNumber
67
    {
68
        if (is_null($value)) {
69
            return null;
70
        }
71
72
        return new DocumentNumber($value);
73
    }
74
75
    public function getName(): string
76
    {
77
        return self::NAME;
78
    }
79
}
80