Skip to content

Commit

Permalink
Merge pull request #98 from frankmayer/improvements_3_1x_branch
Browse files Browse the repository at this point in the history
Improvements #3
  • Loading branch information
mbabker committed Jun 26, 2017
2 parents cff7e7e + 9265441 commit 6e8bd95
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 144 deletions.
10 changes: 5 additions & 5 deletions Tests/Mock/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public static function create(\PHPUnit_Framework_TestCase $test, $nullDate = '00
$mockObject,
$test,
array(
'escape' => array((is_callable(array($test, 'mockEscape')) ? $test : __CLASS__), 'mockEscape'),
'getQuery' => array((is_callable(array($test, 'mockGetQuery')) ? $test : __CLASS__), 'mockGetQuery'),
'quote' => array((is_callable(array($test, 'mockQuote')) ? $test : __CLASS__), 'mockQuote'),
'quoteName' => array((is_callable(array($test, 'mockQuoteName')) ? $test : __CLASS__), 'mockQuoteName'),
'setQuery' => array((is_callable(array($test, 'mockSetQuery')) ? $test : __CLASS__), 'mockSetQuery'),
'escape' => array(is_callable(array($test, 'mockEscape')) ? $test : __CLASS__, 'mockEscape'),
'getQuery' => array(is_callable(array($test, 'mockGetQuery')) ? $test : __CLASS__, 'mockGetQuery'),
'quote' => array(is_callable(array($test, 'mockQuote')) ? $test : __CLASS__, 'mockQuote'),
'quoteName' => array(is_callable(array($test, 'mockQuoteName')) ? $test : __CLASS__, 'mockQuoteName'),
'setQuery' => array(is_callable(array($test, 'mockSetQuery')) ? $test : __CLASS__, 'mockSetQuery'),
)
);

Expand Down
4 changes: 2 additions & 2 deletions Tests/QueryElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function test__clone_array()

$baseElement->testArray = array();

$cloneElement = clone($baseElement);
$cloneElement = clone $baseElement;

$baseElement->testArray[] = 'a';

Expand All @@ -262,7 +262,7 @@ public function test__clone_object()

$baseElement->testObject = new \stdClass;

$cloneElement = clone($baseElement);
$cloneElement = clone $baseElement;

$this->assertFalse($baseElement === $cloneElement);
$this->assertFalse($baseElement->testObject === $cloneElement->testObject);
Expand Down
4 changes: 2 additions & 2 deletions Tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ public function test__clone_array()

$baseElement->testArray = array();

$cloneElement = clone($baseElement);
$cloneElement = clone $baseElement;

$baseElement->testArray[] = 'test';

Expand Down Expand Up @@ -1765,7 +1765,7 @@ public function test__clone_object()

$baseElement->testObject = new \stdClass;

$cloneElement = clone($baseElement);
$cloneElement = clone $baseElement;

$this->assertThat(
TestHelper::getValue($baseElement, 'db'),
Expand Down
1 change: 0 additions & 1 deletion Tests/Stubs/nosqldriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function connected()
*/
public function disconnect()
{
return;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static function getConnectors()
$class = '\\Joomla\\Database\\' . ucfirst(strtolower($baseName)) . '\\' . ucfirst(strtolower($baseName)) . 'Driver';

// If the class doesn't exist, or if it's not supported on this system, move on to the next type.
if (!class_exists($class) || !($class::isSupported()))
if (!class_exists($class) || !$class::isSupported())
{
continue;
}
Expand Down Expand Up @@ -271,9 +271,9 @@ public static function getConnectors()
public static function getInstance($options = array())
{
// Sanitize the database connector options.
$options['driver'] = (isset($options['driver'])) ? preg_replace('/[^A-Z0-9_\.-]/i', '', $options['driver']) : 'mysqli';
$options['database'] = (isset($options['database'])) ? $options['database'] : null;
$options['select'] = (isset($options['select'])) ? $options['select'] : true;
$options['driver'] = isset($options['driver']) ? preg_replace('/[^A-Z0-9_\.-]/i', '', $options['driver']) : 'mysqli';
$options['database'] = isset($options['database']) ? $options['database'] : null;
$options['select'] = isset($options['select']) ? $options['select'] : true;

// Get the options signature for the database connector.
$signature = md5(serialize($options));
Expand Down Expand Up @@ -397,7 +397,7 @@ public static function splitSql($sql)

if ($comment && $start < $i)
{
$query .= substr($sql, $start, ($i - $start));
$query .= substr($sql, $start, $i - $start);
}
}
}
Expand All @@ -412,7 +412,7 @@ public static function splitSql($sql)
{
if ($start <= $i)
{
$query .= substr($sql, $start, ($i - $start + 1));
$query .= substr($sql, $start, $i - $start + 1);
}

$query = trim($query);
Expand Down Expand Up @@ -502,9 +502,9 @@ public function __get($name)
public function __construct($options)
{
// Initialise object variables.
$this->database = (isset($options['database'])) ? $options['database'] : '';
$this->database = isset($options['database']) ? $options['database'] : '';

$this->tablePrefix = (isset($options['prefix'])) ? $options['prefix'] : 'jos_';
$this->tablePrefix = isset($options['prefix']) ? $options['prefix'] : 'jos_';
$this->count = 0;
$this->errorNum = 0;

Expand Down Expand Up @@ -1151,7 +1151,7 @@ public function loadAssocList($key = null, $column = null)
// Get all of the rows from the result set.
while ($row = $this->fetchAssoc($cursor))
{
$value = ($column) ? (isset($row[$column]) ? $row[$column] : $row) : $row;
$value = $column ? (isset($row[$column]) ? $row[$column] : $row) : $row;

if ($key)
{
Expand Down Expand Up @@ -1898,5 +1898,5 @@ abstract public function execute();
* @since 1.0
* @throws \RuntimeException
*/
public abstract function unlockTables();
abstract public function unlockTables();
}
4 changes: 2 additions & 2 deletions src/DatabaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function getDriver($name = 'mysqli', $options = array())
{
// Sanitize the database connector options.
$options['driver'] = preg_replace('/[^A-Z0-9_\.-]/i', '', $name);
$options['database'] = (isset($options['database'])) ? $options['database'] : null;
$options['select'] = (isset($options['select'])) ? $options['select'] : true;
$options['database'] = isset($options['database']) ? $options['database'] : null;
$options['select'] = isset($options['select']) ? $options['select'] : true;

// Derive the class name from the driver.
$class = __NAMESPACE__ . '\\' . ucfirst(strtolower($options['driver'])) . '\\' . ucfirst(strtolower($options['driver'])) . 'Driver';
Expand Down
9 changes: 3 additions & 6 deletions src/Mysql/MysqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct($options)
{
// Get some basic values from the options.
$options['driver'] = 'mysql';
$options['charset'] = (isset($options['charset'])) ? $options['charset'] : 'utf8';
$options['charset'] = isset($options['charset']) ? $options['charset'] : 'utf8';

$this->charset = $options['charset'];

Expand Down Expand Up @@ -355,9 +355,7 @@ public function getTableKeys($table)
// Get the details columns information.
$this->setQuery('SHOW KEYS FROM ' . $this->quoteName($table));

$keys = $this->loadObjectList();

return $keys;
return $this->loadObjectList();
}

/**
Expand All @@ -374,9 +372,8 @@ public function getTableList()

// Set the query to get the tables statement.
$this->setQuery('SHOW TABLES');
$tables = $this->loadColumn();

return $tables;
return $this->loadColumn();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Mysql/MysqlImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ protected function getDropKeySql($table, $name)
*/
protected function getDropPrimaryKeySql($table)
{
$sql = 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP PRIMARY KEY';

return $sql;
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP PRIMARY KEY';
}

/**
Expand Down
22 changes: 10 additions & 12 deletions src/Mysqli/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ class MysqliDriver extends DatabaseDriver
public function __construct($options)
{
// Get some basic values from the options.
$options['host'] = (isset($options['host'])) ? $options['host'] : 'localhost';
$options['user'] = (isset($options['user'])) ? $options['user'] : 'root';
$options['password'] = (isset($options['password'])) ? $options['password'] : '';
$options['database'] = (isset($options['database'])) ? $options['database'] : '';
$options['select'] = (isset($options['select'])) ? (bool) $options['select'] : true;
$options['port'] = (isset($options['port'])) ? (int) $options['port'] : null;
$options['socket'] = (isset($options['socket'])) ? $options['socket'] : null;
$options['utf8mb4'] = (isset($options['utf8mb4'])) ? (bool) $options['utf8mb4'] : false;
$options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
$options['user'] = isset($options['user']) ? $options['user'] : 'root';
$options['password'] = isset($options['password']) ? $options['password'] : '';
$options['database'] = isset($options['database']) ? $options['database'] : '';
$options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
$options['port'] = isset($options['port']) ? (int) $options['port'] : null;
$options['socket'] = isset($options['socket']) ? $options['socket'] : null;
$options['utf8mb4'] = isset($options['utf8mb4']) ? (bool) $options['utf8mb4'] : false;

// Finalize initialisation.
parent::__construct($options);
Expand Down Expand Up @@ -506,9 +506,8 @@ public function getTableKeys($table)

// Get the details columns information.
$this->setQuery('SHOW KEYS FROM ' . $this->quoteName($table));
$keys = $this->loadObjectList();

return $keys;
return $this->loadObjectList();
}

/**
Expand All @@ -525,9 +524,8 @@ public function getTableList()

// Set the query to get the tables statement.
$this->setQuery('SHOW TABLES');
$tables = $this->loadColumn();

return $tables;
return $this->loadColumn();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Mysqli/MysqliImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,7 @@ protected function getDropKeySql($table, $name)
*/
protected function getDropPrimaryKeySql($table)
{
$sql = 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP PRIMARY KEY';

return $sql;
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP PRIMARY KEY';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Oracle/OracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class OracleDriver extends PdoDriver
public function __construct($options)
{
$options['driver'] = 'oci';
$options['charset'] = (isset($options['charset'])) ? $options['charset'] : 'AL32UTF8';
$options['dateformat'] = (isset($options['dateformat'])) ? $options['dateformat'] : 'RRRR-MM-DD HH24:MI:SS';
$options['charset'] = isset($options['charset']) ? $options['charset'] : 'AL32UTF8';
$options['dateformat'] = isset($options['dateformat']) ? $options['dateformat'] : 'RRRR-MM-DD HH24:MI:SS';

$this->charset = $options['charset'];
$this->dateformat = $options['dateformat'];
Expand Down
Loading

0 comments on commit 6e8bd95

Please sign in to comment.