summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauriciofauth@gmail.com>2019-01-08 21:32:02 -0200
committerMaurício Meneghini Fauth <mauriciofauth@gmail.com>2019-01-16 17:21:25 -0200
commit86c5baebda24c1721fb6881df8671a3c7df60e8b (patch)
tree0a76d58ea229d1008e169b1c5b25ce90dde91808 /tools
parent28427543566b6dd32fe44db704ea41368ba55c0e (diff)
downloadsql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.zip
sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.gz
sql-parser-86c5baebda24c1721fb6881df8671a3c7df60e8b.tar.bz2
Apply phpmyadmin/coding-standard
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/ContextGenerator.php38
-rw-r--r--tools/TestGenerator.php49
2 files changed, 48 insertions, 39 deletions
diff --git a/tools/ContextGenerator.php b/tools/ContextGenerator.php
index 503c0e9..5c6b747 100644
--- a/tools/ContextGenerator.php
+++ b/tools/ContextGenerator.php
@@ -18,19 +18,19 @@ class ContextGenerator
*
* @var array
*/
- public static $LABELS_FLAGS = array(
+ public static $LABELS_FLAGS = [
'(R)' => 2, // reserved
'(D)' => 8, // data type
'(K)' => 16, // keyword
'(F)' => 32, // function name
- );
+ ];
/**
* Documentation links for each context.
*
* @var array
*/
- public static $LINKS = array(
+ public static $LINKS = [
'MySql50000' => 'https://dev.mysql.com/doc/refman/5.0/en/keywords.html',
'MySql50100' => 'https://dev.mysql.com/doc/refman/5.1/en/keywords.html',
'MySql50500' => 'https://dev.mysql.com/doc/refman/5.5/en/keywords.html',
@@ -41,7 +41,7 @@ class ContextGenerator
'MariaDb100100' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
'MariaDb100200' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
'MariaDb100300' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/',
- );
+ ];
/**
* The template of a context.
@@ -124,12 +124,12 @@ class ContextGenerator
*/
public static function readWords(array $files)
{
- $words = array();
+ $words = [];
foreach ($files as $file) {
$words = array_merge($words, file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
}
- $types = array();
+ $types = [];
for ($i = 0, $count = count($words); $i !== $count; ++$i) {
$type = 1;
@@ -155,21 +155,21 @@ class ContextGenerator
}
$value = strtoupper($value);
- if (!isset($types[$value])) {
+ if (! isset($types[$value])) {
$types[$value] = $type;
} else {
$types[$value] |= $type;
}
}
- $ret = array();
+ $ret = [];
foreach ($types as $word => $type) {
$len = strlen($word);
- if (!isset($ret[$type])) {
- $ret[$type] = array();
+ if (! isset($ret[$type])) {
+ $ret[$type] = [];
}
- if (!isset($ret[$type][$len])) {
- $ret[$type][$len] = array();
+ if (! isset($ret[$type][$len])) {
+ $ret[$type][$len] = [];
}
$ret[$type][$len][] = $word;
}
@@ -254,7 +254,7 @@ class ContextGenerator
public static function formatName($name)
{
/* Split name and version */
- $parts = array();
+ $parts = [];
if (preg_match('/([^[0-9]*)([0-9]*)/', $name, $parts) === false) {
return $name;
}
@@ -334,18 +334,18 @@ class ContextGenerator
file_put_contents(
$output . '/' . $class . '.php',
static::generate(
- array(
+ [
'name' => $formattedName,
'class' => $class,
'link' => static::$LINKS[$name],
'keywords' => static::readWords(
- array(
+ [
$directory . '_common.txt',
$directory . '_functions' . $file,
$directory . $file,
- )
+ ]
),
- )
+ ]
)
);
}
@@ -389,9 +389,9 @@ if (count($argv) >= 3) {
$output = rtrim($argv[2], '/');
// Checking if all directories are valid.
- if (!is_dir($input)) {
+ if (! is_dir($input)) {
throw new \Exception('The input directory does not exist.');
- } elseif (!is_dir($output)) {
+ } elseif (! is_dir($output)) {
throw new \Exception('The output directory does not exist.');
}
diff --git a/tools/TestGenerator.php b/tools/TestGenerator.php
index 7598af3..599387f 100644
--- a/tools/TestGenerator.php
+++ b/tools/TestGenerator.php
@@ -46,14 +46,14 @@ class TestGenerator
*
* @var array
*/
- $lexerErrors = array();
+ $lexerErrors = [];
/**
* Parser's errors.
*
* @var array
*/
- $parserErrors = array();
+ $parserErrors = [];
// Both the lexer and the parser construct exception for errors.
// Usually, exceptions contain a full stack trace and other details that
@@ -61,30 +61,39 @@ class TestGenerator
// The code below extracts only the relevant information.
// Extracting lexer's errors.
- if (!empty($lexer->errors)) {
+ if (! empty($lexer->errors)) {
foreach ($lexer->errors as $err) {
- $lexerErrors[] = array($err->getMessage(), $err->ch, $err->pos, $err->getCode());
+ $lexerErrors[] = [
+ $err->getMessage(),
+ $err->ch,
+ $err->pos,
+ $err->getCode(),
+ ];
}
- $lexer->errors = array();
+ $lexer->errors = [];
}
// Extracting parser's errors.
- if (!empty($parser->errors)) {
+ if (! empty($parser->errors)) {
foreach ($parser->errors as $err) {
- $parserErrors[] = array($err->getMessage(), $err->token, $err->getCode());
+ $parserErrors[] = [
+ $err->getMessage(),
+ $err->token,
+ $err->getCode(),
+ ];
}
- $parser->errors = array();
+ $parser->errors = [];
}
- return array(
+ return [
'query' => $query,
'lexer' => $lexer,
'parser' => $parser,
- 'errors' => array(
+ 'errors' => [
'lexer' => $lexerErrors,
'parser' => $parserErrors,
- ),
- );
+ ],
+ ];
}
/**
@@ -100,7 +109,7 @@ class TestGenerator
public static function build($type, $input, $output, $debug = null)
{
// Support query types: `lexer` / `parser`.
- if (!in_array($type, array('lexer', 'parser'))) {
+ if (! in_array($type, ['lexer', 'parser'])) {
throw new \Exception('Unknown test type (expected `lexer` or `parser`).');
}
@@ -122,7 +131,7 @@ class TestGenerator
file_put_contents($output, serialize($test));
// Dumping test's data in human readable format too (if required).
- if (!empty($debug)) {
+ if (! empty($debug)) {
file_put_contents($debug, print_r($test, true));
}
}
@@ -152,10 +161,10 @@ class TestGenerator
if (is_dir($inputFile)) {
// Creating required directories to maintain the structure.
// Ignoring errors if the folder structure exists already.
- if (!is_dir($outputFile)) {
+ if (! is_dir($outputFile)) {
mkdir($outputFile);
}
- if (($debug !== null) && (!is_dir($debugFile))) {
+ if (($debug !== null) && (! is_dir($debugFile))) {
mkdir($debugFile);
}
@@ -170,7 +179,7 @@ class TestGenerator
}
// Building the test.
- if (!file_exists($outputFile)) {
+ if (! file_exists($outputFile)) {
sprintf("Building test for %s...\n", $inputFile);
static::build(
strpos($inputFile, 'lex') !== false ? 'lexer' : 'parser',
@@ -203,11 +212,11 @@ if (count($argv) >= 3) {
$debug = empty($argv[3]) ? null : rtrim($argv[3], '/');
// Checking if all directories are valid.
- if (!is_dir($input)) {
+ if (! is_dir($input)) {
throw new \Exception('The input directory does not exist.');
- } elseif (!is_dir($output)) {
+ } elseif (! is_dir($output)) {
throw new \Exception('The output directory does not exist.');
- } elseif (($debug !== null) && (!is_dir($debug))) {
+ } elseif (($debug !== null) && (! is_dir($debug))) {
throw new \Exception('The debug directory does not exist.');
}