Code Duplication    Length = 24-24 lines in 2 locations

src/Dbal/EncryptedColumn.php 1 location

@@ 74-97 (lines=24) @@
71
     * @return mixed
72
     * @throws ConversionException
73
     */
74
    private function decodeJson($value)
75
    {
76
        $decoded = json_decode($value, true);
77
78
        switch (json_last_error()) {
79
            case JSON_ERROR_NONE:
80
                if (!is_array($decoded)) {
81
                    throw ConversionException::conversionFailed($value, 'Json was not an array');
82
                }
83
                return $decoded;
84
            case JSON_ERROR_DEPTH:
85
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, maximum stack depth exceeded.');
86
            case JSON_ERROR_STATE_MISMATCH:
87
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, underflow or the nodes mismatch.');
88
            case JSON_ERROR_CTRL_CHAR:
89
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, unexpected control character found.');
90
            case JSON_ERROR_SYNTAX:
91
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, syntax error - malformed JSON.');
92
            case JSON_ERROR_UTF8:
93
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, malformed UTF-8 characters (incorrectly encoded?)');
94
            default:
95
                throw ConversionException::conversionFailed($value, 'Could not decode Json');
96
        }
97
    }
98
}
99

src/Dbal/EncryptedColumnLegacySupport.php 1 location

@@ 91-114 (lines=24) @@
88
     * @return mixed
89
     * @throws ConversionException
90
     */
91
    private function decodeJson($value)
92
    {
93
        $decoded = json_decode($value, true);
94
95
        switch (json_last_error()) {
96
            case JSON_ERROR_NONE:
97
                if (!is_array($decoded)) {
98
                    throw ConversionException::conversionFailed($value, 'Json was not an array');
99
                }
100
                return $decoded;
101
            case JSON_ERROR_DEPTH:
102
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, maximum stack depth exceeded.');
103
            case JSON_ERROR_STATE_MISMATCH:
104
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, underflow or the nodes mismatch.');
105
            case JSON_ERROR_CTRL_CHAR:
106
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, unexpected control character found.');
107
            case JSON_ERROR_SYNTAX:
108
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, syntax error - malformed JSON.');
109
            case JSON_ERROR_UTF8:
110
                throw ConversionException::conversionFailed($value, 'Could not decode JSON, malformed UTF-8 characters (incorrectly encoded?)');
111
            default:
112
                throw ConversionException::conversionFailed($value, 'Could not decode Json');
113
        }
114
    }
115
}
116