summaryrefslogtreecommitdiffstats
path: root/tools/TestGenerator.php
diff options
context:
space:
mode:
Diffstat (limited to 'tools/TestGenerator.php')
-rw-r--r--tools/TestGenerator.php51
1 files changed, 24 insertions, 27 deletions
diff --git a/tools/TestGenerator.php b/tools/TestGenerator.php
index 5f59f01..c5838b8 100644
--- a/tools/TestGenerator.php
+++ b/tools/TestGenerator.php
@@ -1,18 +1,16 @@
<?php
+declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tools;
require_once '../vendor/autoload.php';
+use Exception;
use PhpMyAdmin\SqlParser\Lexer;
use PhpMyAdmin\SqlParser\Parser;
/**
* Used for test generation.
- *
- * @category Tests
- *
- * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class TestGenerator
{
@@ -39,21 +37,21 @@ class TestGenerator
*
* @var Parser
*/
- $parser = ($type === 'parser') ? new Parser($lexer->list) : null;
+ $parser = $type === 'parser' ? new Parser($lexer->list) : null;
/**
* Lexer's errors.
*
* @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
@@ -63,37 +61,37 @@ class TestGenerator
// Extracting lexer's errors.
if (! empty($lexer->errors)) {
foreach ($lexer->errors as $err) {
- $lexerErrors[] = array(
+ $lexerErrors[] = [
$err->getMessage(),
$err->ch,
$err->pos,
- $err->getCode()
- );
+ $err->getCode(),
+ ];
}
- $lexer->errors = array();
+ $lexer->errors = [];
}
// Extracting parser's errors.
if (! empty($parser->errors)) {
foreach ($parser->errors as $err) {
- $parserErrors[] = array(
+ $parserErrors[] = [
$err->getMessage(),
$err->token,
- $err->getCode()
- );
+ $err->getCode(),
+ ];
}
- $parser->errors = array();
+ $parser->errors = [];
}
- return array(
+ return [
'query' => $query,
'lexer' => $lexer,
'parser' => $parser,
- 'errors' => array(
+ 'errors' => [
'lexer' => $lexerErrors,
'parser' => $parserErrors,
- )
- );
+ ],
+ ];
}
/**
@@ -109,8 +107,8 @@ class TestGenerator
public static function build($type, $input, $output, $debug = null)
{
// Support query types: `lexer` / `parser`.
- if (! in_array($type, array('lexer', 'parser'))) {
- throw new \Exception('Unknown test type (expected `lexer` or `parser`).');
+ if (! in_array($type, ['lexer', 'parser'])) {
+ throw new Exception('Unknown test type (expected `lexer` or `parser`).');
}
/**
@@ -122,7 +120,7 @@ class TestGenerator
// There is no point in generating a test without a query.
if (empty($query)) {
- throw new \Exception('No input query specified.');
+ throw new Exception('No input query specified.');
}
$test = static::generate($query, $type);
@@ -156,7 +154,7 @@ class TestGenerator
// Appending the filename to directories.
$inputFile = $input . '/' . $file;
$outputFile = $output . '/' . $file;
- $debugFile = ($debug !== null) ? $debug . '/' . $file : null;
+ $debugFile = $debug !== null ? $debug . '/' . $file : null;
if (is_dir($inputFile)) {
// Creating required directories to maintain the structure.
@@ -203,7 +201,6 @@ class TestGenerator
//
// Input data must be in the `../tests/data` folder.
// The output will be generated in the same `../tests/data` folder.
-//
if (count($argv) >= 3) {
// Extracting directories' name from command line and trimming unnecessary
// slashes at the end.
@@ -213,11 +210,11 @@ if (count($argv) >= 3) {
// Checking if all directories are valid.
if (! is_dir($input)) {
- throw new \Exception('The input directory does not exist.');
+ throw new Exception('The input directory does not exist.');
} elseif (! is_dir($output)) {
- throw new \Exception('The output directory does not exist.');
+ throw new Exception('The output directory does not exist.');
} elseif (($debug !== null) && (! is_dir($debug))) {
- throw new \Exception('The debug directory does not exist.');
+ throw new Exception('The debug directory does not exist.');
}
// Finally, building the tests.