Skip to content

Commit 709da09

Browse files
committed
Improve formatting of context name for major releases
Signed-off-by: Michal Čihař <[email protected]>
1 parent 8229304 commit 709da09

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

src/Contexts/ContextMariaDb100000.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Context for MariaDB 1..
4+
* Context for MariaDB 10.0.
55
*
66
* This file was auto-generated.
77
*
@@ -13,7 +13,7 @@
1313
use PhpMyAdmin\SqlParser\Context;
1414

1515
/**
16-
* Context for MariaDB 1..
16+
* Context for MariaDB 10.0.
1717
*
1818
* @category Contexts
1919
*

src/Contexts/ContextMariaDb100100.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Context for MariaDB 11.
4+
* Context for MariaDB 10.1.
55
*
66
* This file was auto-generated.
77
*
@@ -13,7 +13,7 @@
1313
use PhpMyAdmin\SqlParser\Context;
1414

1515
/**
16-
* Context for MariaDB 11.
16+
* Context for MariaDB 10.1.
1717
*
1818
* @category Contexts
1919
*

src/Contexts/ContextMariaDb100200.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Context for MariaDB 12.
4+
* Context for MariaDB 10.2.
55
*
66
* This file was auto-generated.
77
*
@@ -13,7 +13,7 @@
1313
use PhpMyAdmin\SqlParser\Context;
1414

1515
/**
16-
* Context for MariaDB 12.
16+
* Context for MariaDB 10.2.
1717
*
1818
* @category Contexts
1919
*

src/Contexts/ContextMySql50000.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Context for MySQL 5.
4+
* Context for MySQL 5.0.
55
*
66
* This file was auto-generated.
77
*
@@ -13,7 +13,7 @@
1313
use PhpMyAdmin\SqlParser\Context;
1414

1515
/**
16-
* Context for MySQL 5.
16+
* Context for MySQL 5.0.
1717
*
1818
* @category Contexts
1919
*

src/Contexts/ContextMySql80000.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Context for MySQL 8.
4+
* Context for MySQL 8.0.
55
*
66
* This file was auto-generated.
77
*
@@ -13,7 +13,7 @@
1313
use PhpMyAdmin\SqlParser\Context;
1414

1515
/**
16-
* Context for MySQL 8.
16+
* Context for MySQL 8.0.
1717
*
1818
* @category Contexts
1919
*

tools/ContextGenerator.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)