summaryrefslogtreecommitdiffstats
path: root/tools/TestGenerator.php
diff options
context:
space:
mode:
Diffstat (limited to 'tools/TestGenerator.php')
-rw-r--r--tools/TestGenerator.php49
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.');
}