Fix a bunch of one line if statements

This commit is contained in:
Timothy Warren 2015-11-11 09:25:21 -05:00
parent c64d693563
commit e62f5771a5
15 changed files with 125 additions and 34 deletions

View File

@ -220,7 +220,10 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
{ {
// Parameters are 1-based, the data is 0-based // Parameters are 1-based, the data is 0-based
// So, if the key is numeric, add 1 // So, if the key is numeric, add 1
if(is_numeric($k)) $k++; if(is_numeric($k))
{
$k++;
}
$this->statement->bindValue($k, $value); $this->statement->bindValue($k, $value);
} }
@ -533,7 +536,10 @@ abstract class AbstractDriver extends \PDO implements DriverInterface {
// Return if the values are returned instead of a query, // Return if the values are returned instead of a query,
// or if the query doesn't apply to the driver // or if the query doesn't apply to the driver
if ( ! is_string($query)) return $query; if ( ! is_string($query))
{
return $query;
}
// Run the query! // Run the query!
$res = $this->query($query); $res = $this->query($query);

View File

@ -229,7 +229,10 @@ abstract class AbstractQueryBuilder {
// Escape the identifiers // Escape the identifiers
$field = $this->db->quote_ident($field); $field = $this->db->quote_ident($field);
if ( ! is_string($as)) return $field; if ( ! is_string($as))
{
return $field;
}
$as = $this->db->quote_ident($as); $as = $this->db->quote_ident($as);
@ -251,7 +254,10 @@ abstract class AbstractQueryBuilder {
$sql = $this->_compile($type, $table); $sql = $this->_compile($type, $table);
// Reset the query builder for the next query // Reset the query builder for the next query
if ($reset) $this->reset_query(); if ($reset)
{
$this->reset_query();
}
return $sql; return $sql;
} }

View File

@ -87,7 +87,10 @@ final class ConnectionManager {
*/ */
public static function get_instance() public static function get_instance()
{ {
if (self::$instance === null) self::$instance = new self(); if (self::$instance === null)
{
self::$instance = new self();
}
return self::$instance; return self::$instance;
} }

View File

@ -79,7 +79,7 @@ class Driver extends \Query\AbstractDriver {
*/ */
public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = array()) public function __construct($dbpath, $user='SYSDBA', $pass='masterkey', array $options = array())
{ {
$connect_function = (isset($options[\PDO::ATTR_PERSISTENT]) && $options[\PDO::ATTR_PERSISTENT] == TRUE) $connect_function = (isset($options[\PDO::ATTR_PERSISTENT]) && $options[\PDO::ATTR_PERSISTENT])
? '\\fbird_pconnect' ? '\\fbird_pconnect'
: '\\fbird_connect'; : '\\fbird_connect';
@ -87,7 +87,10 @@ class Driver extends \Query\AbstractDriver {
$this->service = \fbird_service_attach('localhost', $user, $pass); $this->service = \fbird_service_attach('localhost', $user, $pass);
// Throw an exception to make this match other pdo classes // Throw an exception to make this match other pdo classes
if ( ! \is_resource($this->conn)) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL); if ( ! \is_resource($this->conn))
{
throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
}
// Load these classes here because this // Load these classes here because this
// driver does not call the constructor // driver does not call the constructor
@ -191,7 +194,10 @@ class Driver extends \Query\AbstractDriver {
// Throw the error as a exception // Throw the error as a exception
$err_string = \fbird_errmsg() . "Last query:" . $this->get_last_query(); $err_string = \fbird_errmsg() . "Last query:" . $this->get_last_query();
if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL); if ($this->statement_link === FALSE)
{
throw new \PDOException($err_string, \fbird_errcode(), NULL);
}
$this->statement = new Result($this->statement_link, $this); $this->statement = new Result($this->statement_link, $this);
@ -213,7 +219,10 @@ class Driver extends \Query\AbstractDriver {
$this->statement_link = \fbird_prepare($this->conn, $query); $this->statement_link = \fbird_prepare($this->conn, $query);
// Throw the error as an exception // Throw the error as an exception
if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL); if ($this->statement_link === FALSE)
{
throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
}
$this->statement = new Result($this->statement_link, $this); $this->statement = new Result($this->statement_link, $this);
@ -366,7 +375,10 @@ class Driver extends \Query\AbstractDriver {
public function insert_batch($table, $data=array()) public function insert_batch($table, $data=array())
{ {
// Each member of the data array needs to be an array // Each member of the data array needs to be an array
if ( ! is_array(current($data))) return NULL; if ( ! is_array(current($data)))
{
return NULL;
}
// Start the block of sql statements // Start the block of sql statements
$sql = "EXECUTE BLOCK AS BEGIN\n"; $sql = "EXECUTE BLOCK AS BEGIN\n";

View File

@ -61,7 +61,10 @@ class Result extends \PDOStatement {
*/ */
public function __construct($link, Driver $db = NULL) public function __construct($link, Driver $db = NULL)
{ {
if ( ! is_null($db)) $this->db = $db; if ( ! is_null($db))
{
$this->db = $db;
}
$this->statement = $link; $this->statement = $link;
$this->setFetchMode(\PDO::FETCH_ASSOC); $this->setFetchMode(\PDO::FETCH_ASSOC);
$this->row = -1; $this->row = -1;

View File

@ -98,7 +98,10 @@ class Util extends \Query\AbstractUtil {
$obj_res = $res->fetchAll(\PDO::FETCH_ASSOC); $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
// Don't add to the file if the table is empty // Don't add to the file if the table is empty
if (count($obj_res) < 1) continue; if (count($obj_res) < 1)
{
continue;
}
// Nab the column names by getting the keys of the first row // Nab the column names by getting the keys of the first row
$columns = @array_keys($obj_res[0]); $columns = @array_keys($obj_res[0]);

View File

@ -49,7 +49,10 @@ class Driver extends \Query\AbstractDriver {
)); ));
} }
if (strpos($dsn, 'mysql') === FALSE) $dsn = 'mysql:'.$dsn; if (strpos($dsn, 'mysql') === FALSE)
{
$dsn = 'mysql:'.$dsn;
}
parent::__construct($dsn, $username, $password, $options); parent::__construct($dsn, $username, $password, $options);
} }

View File

@ -88,7 +88,10 @@ class SQL extends \Query\AbstractSQL {
*/ */
public function table_list($database='') public function table_list($database='')
{ {
if ( ! empty($database)) return "SHOW TABLES FROM `{$database}`"; if ( ! empty($database))
{
return "SHOW TABLES FROM `{$database}`";
}
return 'SHOW TABLES'; return 'SHOW TABLES';
} }

View File

@ -38,7 +38,10 @@ class Util extends \Query\AbstractUtil {
foreach($dbs as &$d) foreach($dbs as &$d)
{ {
// Skip built-in dbs // Skip built-in dbs
if ($d == 'mysql') continue; if ($d == 'mysql')
{
continue;
}
// Get the list of tables // Get the list of tables
$tables = $this->get_driver()->driver_query("SHOW TABLES FROM `{$d}`", TRUE); $tables = $this->get_driver()->driver_query("SHOW TABLES FROM `{$d}`", TRUE);
@ -48,7 +51,10 @@ class Util extends \Query\AbstractUtil {
$array = $this->get_driver()->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE); $array = $this->get_driver()->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE);
$row = current($array); $row = current($array);
if ( ! isset($row['Create Table'])) continue; if ( ! isset($row['Create Table']))
{
continue;
}
$string[] = $row['Create Table']; $string[] = $row['Create Table'];
@ -86,7 +92,10 @@ class Util extends \Query\AbstractUtil {
$rows = $res->fetchAll(\PDO::FETCH_ASSOC); $rows = $res->fetchAll(\PDO::FETCH_ASSOC);
// Skip empty tables // Skip empty tables
if (count($rows) < 1) continue; if (count($rows) < 1)
{
continue;
}
// Nab the column names by getting the keys of the first row // Nab the column names by getting the keys of the first row
$columns = @array_keys($rows[0]); $columns = @array_keys($rows[0]);

View File

@ -34,7 +34,10 @@ class Driver extends \Query\AbstractDriver {
*/ */
public function __construct($dsn, $username=null, $password=null, array $options=array()) public function __construct($dsn, $username=null, $password=null, array $options=array())
{ {
if (strpos($dsn, 'pgsql') === FALSE) $dsn = 'pgsql:'.$dsn; if (strpos($dsn, 'pgsql') === FALSE)
{
$dsn = 'pgsql:'.$dsn;
}
parent::__construct($dsn, $username, $password, $options); parent::__construct($dsn, $username, $password, $options);
} }
@ -78,7 +81,10 @@ SQL;
{ {
foreach(array('update', 'delete') AS $type) foreach(array('update', 'delete') AS $type)
{ {
if ( ! isset($value_map[$key[$type]])) continue; if ( ! isset($value_map[$key[$type]]))
{
continue;
}
$key[$type] = $value_map[$key[$type]]; $key[$type] = $value_map[$key[$type]];
} }

View File

@ -62,7 +62,10 @@ class Util extends \Query\AbstractUtil {
$obj_res = $res->fetchAll(\PDO::FETCH_ASSOC); $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
// Don't add to the file if the table is empty // Don't add to the file if the table is empty
if (count($obj_res) < 1) continue; if (count($obj_res) < 1)
{
continue;
}
$res = NULL; $res = NULL;

View File

@ -47,7 +47,10 @@ class Driver extends \Query\AbstractDriver {
*/ */
public function __construct($dsn, $user=NULL, $pass=NULL, array $driver_options=array()) public function __construct($dsn, $user=NULL, $pass=NULL, array $driver_options=array())
{ {
if (strpos($dsn, 'sqlite:') === FALSE) $dsn = "sqlite:{$dsn}"; if (strpos($dsn, 'sqlite:') === FALSE)
{
$dsn = "sqlite:{$dsn}";
}
parent::__construct($dsn, $user, $pass); parent::__construct($dsn, $user, $pass);
} }
@ -117,7 +120,10 @@ class Driver extends \Query\AbstractDriver {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Each member of the data array needs to be an array // Each member of the data array needs to be an array
if ( ! is_array(current($data))) return NULL; if ( ! is_array(current($data)))
{
return NULL;
}
// Start the block of sql statements // Start the block of sql statements
$table = $this->quote_table($table); $table = $this->quote_table($table);

View File

@ -60,7 +60,10 @@ class Util extends \Query\AbstractUtil {
unset($res); unset($res);
// If the row is empty, continue; // If the row is empty, continue;
if (empty($obj_res)) continue; if (empty($obj_res))
{
continue;
}
// Nab the column names by getting the keys of the first row // Nab the column names by getting the keys of the first row
$columns = array_keys(current($obj_res)); $columns = array_keys(current($obj_res));

View File

@ -677,10 +677,16 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
public function get($table='', $limit=FALSE, $offset=FALSE) public function get($table='', $limit=FALSE, $offset=FALSE)
{ {
// Set the table // Set the table
if ( ! empty($table)) $this->from($table); if ( ! empty($table))
{
$this->from($table);
}
// Set the limit, if it exists // Set the limit, if it exists
if (is_int($limit)) $this->limit($limit, $offset); if (is_int($limit))
{
$this->limit($limit, $offset);
}
return $this->_run("get", $table); return $this->_run("get", $table);
} }
@ -732,7 +738,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
public function count_all_results($table='') public function count_all_results($table='')
{ {
// Set the table // Set the table
if ( ! empty($table)) $this->from($table); if ( ! empty($table))
{
$this->from($table);
}
$result = $this->_run('get', $table); $result = $this->_run('get', $table);
$rows = $result->fetchAll(); $rows = $result->fetchAll();
@ -751,8 +760,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
*/ */
public function insert($table, $data=array()) public function insert($table, $data=array())
{ {
// No use duplicating logic! if ( ! empty($data))
if ( ! empty($data)) $this->set($data); {
$this->set($data);
}
return $this->_run("insert", $table); return $this->_run("insert", $table);
} }
@ -787,8 +798,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
*/ */
public function update($table, $data=array()) public function update($table, $data=array())
{ {
// No use duplicating logic! if ( ! empty($data))
if ( ! empty($data)) $this->set($data); {
$this->set($data);
}
return $this->_run("update", $table); return $this->_run("update", $table);
} }
@ -805,7 +818,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
public function delete($table, $where='') public function delete($table, $where='')
{ {
// Set the where clause // Set the where clause
if ( ! empty($where)) $this->where($where); if ( ! empty($where))
{
$this->where($where);
}
return $this->_run("delete", $table); return $this->_run("delete", $table);
} }
@ -826,7 +842,10 @@ class QueryBuilder extends AbstractQueryBuilder implements QueryBuilderInterface
public function get_compiled_select($table='', $reset=TRUE) public function get_compiled_select($table='', $reset=TRUE)
{ {
// Set the table // Set the table
if ( ! empty($table)) $this->from($table); if ( ! empty($table))
{
$this->from($table);
}
return $this->_get_compile('select', $table, $reset); return $this->_get_compile('select', $table, $reset);
} }

View File

@ -147,7 +147,10 @@ if ( ! function_exists('array_column'))
$output = array(); $output = array();
// No point iterating over an empty array // No point iterating over an empty array
if (empty($array)) return $array; if (empty($array))
{
return $array;
}
foreach($array as $inner_array) foreach($array as $inner_array)
{ {
@ -175,7 +178,10 @@ if ( ! function_exists('regex_in_array'))
*/ */
function regex_in_array(Array $array, $pattern) function regex_in_array(Array $array, $pattern)
{ {
if (empty($array)) return FALSE; if (empty($array))
{
return FALSE;
}
foreach($array as $item) foreach($array as $item)
{ {