Code Duplication    Length = 54-56 lines in 11 locations

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/ConfigurationContactInformationType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the ContactInformation Value Object for the Configuration domain
29
 */
30
class ConfigurationContactInformationType extends Type
31
{
32
    const NAME = 'stepup_configuration_contact_information';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return null;
43
        }
44
45
        if (!$value instanceof ContactInformation) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal contact information of type %s '%s', expected a ContactInformation instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->getContactInformation();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $contactInformation = new ContactInformation($value);
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $contactInformation;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/ConfigurationInstitutionType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the Institution Value Object for the Configuration domain
29
 */
30
class ConfigurationInstitutionType extends Type
31
{
32
    const NAME = 'stepup_configuration_institution';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof Institution) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal institution of type %s '%s', expected an Institution instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->getInstitution();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $institution = new Institution($value);
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $institution;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/ConfigurationLocationType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the Location Value Object for the Configuration domain
29
 */
30
class ConfigurationLocationType extends Type
31
{
32
    const NAME = 'stepup_configuration_location';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof Location) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a Location instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->getLocation();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $location = new Location($value);
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $location;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/NumberOfTokensPerIdentityType.php 1 location

@@ 30-84 (lines=55) @@
27
/**
28
 * Custom Type for the NumberOfTokensPerIdentityOption Value Object
29
 */
30
class NumberOfTokensPerIdentityType extends Type
31
{
32
    const NAME = 'stepup_number_of_tokens_per_identity_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof NumberOfTokensPerIdentityOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal number of tokens per identity %s '%s', expected a 
49
                    NumberOfTokensPerIdentityOption instance",
50
                    is_object($value) ? get_class($value) : gettype($value),
51
                    is_scalar($value) ? (string) $value : ''
52
                )
53
            );
54
        }
55
56
        return $value->getNumberOfTokensPerIdentity();
57
    }
58
59
    public function convertToPHPValue($value, AbstractPlatform $platform)
60
    {
61
        if (is_null($value)) {
62
            return $value;
63
        }
64
65
        try {
66
            $numberOfTokensPerIdentityOption = new NumberOfTokensPerIdentityOption((int) $value);
67
        } catch (InvalidArgumentException $e) {
68
            // get nice standard message, so we can throw it keeping the exception chain
69
            $doctrineExceptionMessage = ConversionException::conversionFailed(
70
                $value,
71
                $this->getName()
72
            )->getMessage();
73
74
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
75
        }
76
77
        return $numberOfTokensPerIdentityOption;
78
    }
79
80
    public function getName()
81
    {
82
        return self::NAME;
83
    }
84
}
85

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/RaLocationNameType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the RaLocationName Value Object
29
 */
30
class RaLocationNameType extends Type
31
{
32
    const NAME = 'stepup_ra_location_name';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getVarcharTypeDeclarationSQL([]);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof RaLocationName) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal RA location name of type %s '%s', expected a RaLocationName instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->getRaLocationName();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $raLocationName = new RaLocationName($value);
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $raLocationName;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/ShowRaaContactInformationOptionType.php 1 location

@@ 30-85 (lines=56) @@
27
/**
28
 * Custom Type for the ShowRaaContactInformationOption Value Object
29
 */
30
class ShowRaaContactInformationOptionType extends Type
31
{
32
    const NAME = 'stepup_show_raa_contact_information_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof ShowRaaContactInformationOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a ShowRaaContactInformationOption instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->isEnabled();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $showRaaContactInformationOption = new ShowRaaContactInformationOption(
66
                $platform->convertFromBoolean($value)
67
            );
68
        } catch (InvalidArgumentException $e) {
69
            // get nice standard message, so we can throw it keeping the exception chain
70
            $doctrineExceptionMessage = ConversionException::conversionFailed(
71
                $value,
72
                $this->getName()
73
            )->getMessage();
74
75
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
76
        }
77
78
        return $showRaaContactInformationOption;
79
    }
80
81
    public function getName()
82
    {
83
        return self::NAME;
84
    }
85
}
86

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/UseRaLocationsOptionType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the UseRaLocationsOption Value Object
29
 */
30
class UseRaLocationsOptionType extends Type
31
{
32
    const NAME = 'stepup_use_ra_locations_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof UseRaLocationsOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a UseRaLocationsOption instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->isEnabled();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $useRaLocationsOption = new UseRaLocationsOption($platform->convertFromBoolean($value));
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $useRaLocationsOption;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/VerifyEmailOptionType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the VerifyEmailOption Value Object
29
 */
30
class VerifyEmailOptionType extends Type
31
{
32
    const NAME = 'stepup_verify_email_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof VerifyEmailOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a VerifyEmailOption instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return $value->isEnabled();
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $verifyEmailOption = new VerifyEmailOption($platform->convertFromBoolean($value));
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $verifyEmailOption;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/SelectRaaOptionType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the SelectRaaOptionType Value Object
29
 */
30
class SelectRaaOptionType extends Type
31
{
32
    const NAME = 'stepup_select_raa_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof SelectRaaOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a SelectRaaOption instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string)$value : ''
51
                )
52
            );
53
        }
54
55
        return json_encode($value);
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $useRaLocationsOption = new SelectRaaOption(json_decode($value));
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $useRaLocationsOption;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/UseRaaOptionType.php 1 location

@@ 31-84 (lines=54) @@
28
/**
29
 * Custom Type for the UseRaaOptionType Value Object
30
 */
31
class UseRaaOptionType extends Type
32
{
33
    const NAME = 'stepup_select_raa_option';
34
35
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
36
    {
37
        return $platform->getJsonTypeDeclarationSQL($fieldDeclaration);
38
    }
39
40
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
41
    {
42
        if (is_null($value)) {
43
            return $value;
44
        }
45
46
        if (!$value instanceof UseRaaOption) {
47
            throw new ConversionException(
48
                sprintf(
49
                    "Encountered illegal location of type %s '%s', expected a UseRaaOption instance",
50
                    is_object($value) ? get_class($value) : gettype($value),
51
                    is_scalar($value) ? (string) $value : ''
52
                )
53
            );
54
        }
55
56
        return json_encode($value);
57
    }
58
59
    public function convertToPHPValue($value, AbstractPlatform $platform)
60
    {
61
        if (is_null($value)) {
62
            return $value;
63
        }
64
65
        try {
66
            $useRaLocationsOption = new UseRaaOption(json_decode($value));
67
        } catch (InvalidArgumentException $e) {
68
            // get nice standard message, so we can throw it keeping the exception chain
69
            $doctrineExceptionMessage = ConversionException::conversionFailed(
70
                $value,
71
                $this->getName()
72
            )->getMessage();
73
74
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
75
        }
76
77
        return $useRaLocationsOption;
78
    }
79
80
    public function getName()
81
    {
82
        return self::NAME;
83
    }
84
}
85

src/Surfnet/StepupMiddleware/ApiBundle/Doctrine/Type/UseRaOptionType.php 1 location

@@ 30-83 (lines=54) @@
27
/**
28
 * Custom Type for the UseRaOptionType Value Object
29
 */
30
class UseRaOptionType extends Type
31
{
32
    const NAME = 'stepup_select_ra_option';
33
34
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
35
    {
36
        return $platform->getJsonTypeDeclarationSQL($fieldDeclaration);
37
    }
38
39
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
40
    {
41
        if (is_null($value)) {
42
            return $value;
43
        }
44
45
        if (!$value instanceof UseRaOption) {
46
            throw new ConversionException(
47
                sprintf(
48
                    "Encountered illegal location of type %s '%s', expected a UseRaOption instance",
49
                    is_object($value) ? get_class($value) : gettype($value),
50
                    is_scalar($value) ? (string) $value : ''
51
                )
52
            );
53
        }
54
55
        return json_encode($value);
56
    }
57
58
    public function convertToPHPValue($value, AbstractPlatform $platform)
59
    {
60
        if (is_null($value)) {
61
            return $value;
62
        }
63
64
        try {
65
            $useRaLocationsOption = new UseRaOption(json_decode($value));
66
        } catch (InvalidArgumentException $e) {
67
            // get nice standard message, so we can throw it keeping the exception chain
68
            $doctrineExceptionMessage = ConversionException::conversionFailed(
69
                $value,
70
                $this->getName()
71
            )->getMessage();
72
73
            throw new ConversionException($doctrineExceptionMessage, 0, $e);
74
        }
75
76
        return $useRaLocationsOption;
77
    }
78
79
    public function getName()
80
    {
81
        return self::NAME;
82
    }
83
}
84