summaryrefslogtreecommitdiffstats
path: root/src/Utils
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-06-24 19:53:40 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-06-24 19:53:47 +0300
commit8bfff84044f750d32e2c8e4a7c6ec668d435d409 (patch)
tree957892f4ac25627c67b0db4f5ee256eebcd9c18b /src/Utils
parent5621738b8deb2df87d874559399139599377d14b (diff)
downloadsql-parser-8bfff84044f750d32e2c8e4a7c6ec668d435d409.zip
sql-parser-8bfff84044f750d32e2c8e4a7c6ec668d435d409.tar.gz
sql-parser-8bfff84044f750d32e2c8e4a7c6ec668d435d409.tar.bz2
Less strict type hinting in Utilities subpackage.
Diffstat (limited to 'src/Utils')
-rw-r--r--src/Utils/Misc.php12
-rw-r--r--src/Utils/Routine.php38
-rw-r--r--src/Utils/Table.php10
3 files changed, 33 insertions, 27 deletions
diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php
index 4e818c6..4332ae0 100644
--- a/src/Utils/Misc.php
+++ b/src/Utils/Misc.php
@@ -2,7 +2,7 @@
namespace SqlParser\Utils;
-use SqlParser\Statements\SelectStatement;
+use SqlParser\Statement;
/**
* Miscellaneous utilities.
@@ -19,13 +19,17 @@ class Misc
/**
* Gets a list of all aliases and their original names.
*
- * @param SelectStatement $tree The tree that was generated after parsing.
- * @param string $database The name of the database.
+ * @param Statement $tree The tree that was generated after parsing.
+ * @param string $database The name of the database.
*
* @return array
*/
- public static function getAliases(SelectStatement $tree, $database)
+ public static function getAliases(Statement $tree, $database)
{
+ if ((empty($tree->from)) || (empty($tree->expr))) {
+ return array();
+ }
+
$retval = array();
$tables = array();
diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php
index 8be7db1..740ace3 100644
--- a/src/Utils/Routine.php
+++ b/src/Utils/Routine.php
@@ -4,9 +4,9 @@ namespace SqlParser\Utils;
use SqlParser\Lexer;
use SqlParser\Parser;
+use SqlParser\Statement;
use SqlParser\Fragments\DataTypeFragment;
use SqlParser\Fragments\ParamDefFragment;
-use SqlParser\Statements\CreateStatement;
/**
* Routine utilities.
@@ -89,11 +89,11 @@ class Routine
/**
* Gets the parameters of a routine from the parse tree.
*
- * @param CreateStatement $tree The tree that was generated after parsing.
+ * @param Statement $tree The tree that was generated after parsing.
*
* @return array
*/
- public static function getParameters(CreateStatement $tree)
+ public static function getParameters(Statement $tree)
{
$retval = array(
'num' => 0,
@@ -105,23 +105,25 @@ class Routine
'opts' => array(),
);
- $idx = 0;
- foreach ($tree->parameters as $param) {
- $retval['dir'][$idx] = $param->inOut;
- $retval['name'][$idx] = $param->name;
- $retval['type'][$idx] = $param->type->name;
- $retval['length'][$idx] = implode(',', $param->type->parameters);
- $retval['length_arr'][$idx] = $param->type->parameters;
- $retval['opts'][$idx] = array();
- foreach ($param->type->options->options as $opt) {
- $retval['opts'][$idx][] = is_string($opt) ?
- $opt : $opt['value'];
+ if (!empty($tree->parameters)) {
+ $idx = 0;
+ foreach ($tree->parameters as $param) {
+ $retval['dir'][$idx] = $param->inOut;
+ $retval['name'][$idx] = $param->name;
+ $retval['type'][$idx] = $param->type->name;
+ $retval['length'][$idx] = implode(',', $param->type->parameters);
+ $retval['length_arr'][$idx] = $param->type->parameters;
+ $retval['opts'][$idx] = array();
+ foreach ($param->type->options->options as $opt) {
+ $retval['opts'][$idx][] = is_string($opt) ?
+ $opt : $opt['value'];
+ }
+ $retval['opts'][$idx] = implode(' ', $retval['opts'][$idx]);
+ ++$idx;
}
- $retval['opts'][$idx] = implode(' ', $retval['opts'][$idx]);
- ++$idx;
- }
- $retval['num'] = $idx;
+ $retval['num'] = $idx;
+ }
return $retval;
}
diff --git a/src/Utils/Table.php b/src/Utils/Table.php
index a814075..7be3eac 100644
--- a/src/Utils/Table.php
+++ b/src/Utils/Table.php
@@ -4,9 +4,9 @@ namespace SqlParser\Utils;
use SqlParser\Lexer;
use SqlParser\Parser;
+use SqlParser\Statement;
use SqlParser\Fragments\DataTypeFragment;
use SqlParser\Fragments\ParamDefFragment;
-use SqlParser\Statements\CreateStatement;
/**
* Table utilities.
@@ -20,9 +20,9 @@ use SqlParser\Statements\CreateStatement;
class Table
{
- public static function getForeignKeys(CreateStatement $tree)
+ public static function getForeignKeys(Statement $tree)
{
- if (($tree->fields === null) || (!$tree->options->has('TABLE'))) {
+ if ((empty($tree->fields)) || (!$tree->options->has('TABLE'))) {
return array();
}
@@ -63,9 +63,9 @@ class Table
return $ret;
}
- public static function getFields(CreateStatement $tree)
+ public static function getFields(Statement $tree)
{
- if (($tree->fields === null) || (!$tree->options->has('TABLE'))) {
+ if ((empty($tree->fields)) || (!$tree->options->has('TABLE'))) {
return array();
}