InstitutionType::getSQLDeclaration()   A
last analyzed

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 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
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\Type;
24
use Surfnet\Stepup\Exception\InvalidArgumentException;
25
use Surfnet\Stepup\Identity\Value\Institution;
26
27
/**
28
 * Custom Type for the Institution Value Object
29
 */
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...
30
class InstitutionType extends Type
31
{
32
    public const NAME = 'institution';
33
34
    public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
35
    {
36
        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

36
        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...
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
40
    {
41
        if (is_null($value)) {
42
            return null;
43
        }
44
45
        return (string)$value;
46
    }
47
48
    public function convertToPHPValue($value, AbstractPlatform $platform): ?Institution
49
    {
50
        if (is_null($value)) {
51
            return null;
52
        }
53
54
        try {
55
            $institution = new Institution($value);
56
        } catch (InvalidArgumentException $e) {
57
            // get nice standard message, so we can throw it keeping the exception chain
58
            $doctrineExceptionMessage = ConversionException::conversionFailed(
59
                $value,
60
                $this->getName(),
61
            )->getMessage();
62
63
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
64
        }
65
66
        return $institution;
67
    }
68
69
    public function getName(): string
70
    {
71
        return self::NAME;
72
    }
73
}
74