diff options
author | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-08 21:32:02 -0200 |
---|---|---|
committer | Maurício Meneghini Fauth <mauriciofauth@gmail.com> | 2019-01-16 17:21:25 -0200 |
commit | 86c5baebda24c1721fb6881df8671a3c7df60e8b (patch) | |
tree | 0a76d58ea229d1008e169b1c5b25ce90dde91808 /tools/TestGenerator.php | |
parent | 28427543566b6dd32fe44db704ea41368ba55c0e (diff) | |
download | sql-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/TestGenerator.php')
-rw-r--r-- | tools/TestGenerator.php | 49 |
1 files changed, 29 insertions, 20 deletions
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.'); } |