@@ -240,6 +240,46 @@ public static function generate($options)
240240 );
241241 }
242242
243+ /**
244+ * Formats context name.
245+ *
246+ * @param string $name Name to format.
247+ *
248+ * @return string
249+ */
250+ public static function formatName ($ name )
251+ {
252+ /* Split name and version */
253+ $ parts = array ();
254+ if (preg_match ('/([^[0-9]*)([0-9]*)/ ' , $ name , $ parts ) === false ) {
255+ return $ name ;
256+ }
257+
258+ /* Format name */
259+ $ base = $ parts [1 ];
260+ switch ($ base ) {
261+ case 'MySql ' :
262+ $ base = 'MySQL ' ;
263+ break ;
264+ case 'MariaDb ' :
265+ $ base = 'MariaDB ' ;
266+ break ;
267+ }
268+
269+ /* Parse version to array */
270+ $ ver_str = $ parts [2 ];
271+ if (strlen ($ ver_str ) % 2 == 1 ) {
272+ $ ver_str = '0 ' . $ ver_str ;
273+ }
274+ $ version = array_map ('intval ' , str_split ($ ver_str , 2 ));
275+ /* Remove trailing zero */
276+ if ($ version [count ($ version ) - 1 ] === 0 ) {
277+ $ version = array_slice ($ version , 0 , count ($ version ) - 1 );
278+ }
279+ /* Create name */
280+ return $ base . ' ' . implode ('. ' , $ version );
281+ }
282+
243283 /**
244284 * Builds a test.
245285 *
@@ -285,11 +325,7 @@ public static function build($input, $output)
285325 *
286326 * @var string
287327 */
288- $ formattedName = str_replace (
289- array ('Context ' , 'MySql ' , 'MariaDb ' , '00 ' , '0 ' ),
290- array ('' , 'MySQL ' , 'MariaDB ' , '' , '. ' ),
291- $ class
292- );
328+ $ formattedName = static ::formatName ($ name );
293329
294330 file_put_contents (
295331 $ output . '/ ' . $ class . '.php ' ,
0 commit comments