Browse Source

Remove method separators, update documentation building configuration

keep-around/73e4c35163f3579f2dbaf2971ca707928f58f541
Timothy Warren 1 year ago
parent
commit
f967aaf96e
25 changed files with 108 additions and 393 deletions
  1. +4
    -42
      RoboFile.php
  2. +0
    -0
      build/phpdoc.dist.xml
  3. +6
    -5
      composer.json
  4. +5
    -7
      phpdox.xml
  5. +0
    -3
      src/BadDBDriverException.php
  6. +1
    -1
      src/Drivers/AbstractDriver.php
  7. +1
    -4
      src/Drivers/AbstractSQL.php
  8. +0
    -4
      src/Drivers/Pgsql/Driver.php
  9. +1
    -4
      src/Drivers/SQLInterface.php
  10. +2
    -2
      src/Drivers/Sqlite/Driver.php
  11. +0
    -2
      src/Drivers/Sqlite/Util.php
  12. +27
    -29
      src/QueryBuilder.php
  13. +42
    -111
      src/QueryBuilderInterface.php
  14. +16
    -17
      src/State.php
  15. +0
    -11
      src/common.php
  16. +1
    -28
      tests/BaseDriverTest.php
  17. +0
    -12
      tests/ConnectionManagerTest.php
  18. +0
    -5
      tests/CoreTest.php
  19. +0
    -27
      tests/Drivers/MySQL/MySQLDriverTest.php
  20. +0
    -6
      tests/Drivers/MySQL/MySQLQueryBuilderTest.php
  21. +1
    -27
      tests/Drivers/PgSQL/PgSQLDriverTest.php
  22. +1
    -7
      tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php
  23. +0
    -30
      tests/Drivers/SQLite/SQLiteDriverTest.php
  24. +0
    -6
      tests/Drivers/SQLite/SQLiteQueryBuilderTest.php
  25. +0
    -3
      tests/bootstrap.php

+ 4
- 42
RoboFile.php View File

@@ -40,7 +40,7 @@ class RoboFile extends \Robo\Tasks {
*/
protected $cleanDirs = [
'coverage',
'docs',
'apiDocumentation',
'phpdoc',
'build/logs',
'build/phpdox',
@@ -76,14 +76,6 @@ class RoboFile extends \Robo\Tasks {
*/
public function clean()
{
$cleanFiles = [
'build/humbug.json',
'build/humbug-log.txt',
];
array_map(function ($file) {
@unlink($file);
}, $cleanFiles);

// So the task doesn't complain,
// make any 'missing' dirs to cleanup
array_map(function ($dir) {
@@ -102,10 +94,7 @@ class RoboFile extends \Robo\Tasks {
*/
public function coverage()
{
$this->taskPhpUnit()
->configFile('build/phpunit.xml')
->printed(true)
->run();
$this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']);
}

/**
@@ -113,10 +102,7 @@ class RoboFile extends \Robo\Tasks {
*/
public function docs()
{
$cmd_parts = [
'phpdoc'
];
$this->_run($cmd_parts, ' && ');
$this->_run(['vendor/bin/phpdox']);
}

/**
@@ -134,29 +120,6 @@ class RoboFile extends \Robo\Tasks {
}
}


/**
* Run mutation tests with humbug
*
* @param bool $stats - if true, generates stats rather than running mutation tests
*/
public function mutate($stats = FALSE)
{
$test_parts = [
'vendor/bin/humbug'
];

$stat_parts = [
'vendor/bin/humbug',
'--skip-killed=yes',
'-v',
'./build/humbug.json'
];

$cmd_parts = ($stats) ? $stat_parts : $test_parts;
$this->_run($cmd_parts);
}

/**
* Run the phpcs tool
*
@@ -226,9 +189,8 @@ class RoboFile extends \Robo\Tasks {
public function test()
{
$this->lint();
$this->taskPHPUnit()
$this->taskPhpUnit()
->configFile('phpunit.xml')
->printed(true)
->run();
$this->_run(["php tests/index.php"]);
}

phpdoc.dist.xml → build/phpdoc.dist.xml View File


+ 6
- 5
composer.json View File

@@ -21,20 +21,19 @@
"role": "Developer"
}],
"require": {
"php": "^7.0"
"php": "^7.1"
},
"require-dev": {
"consolidation/robo": "^1.0.0",
"infection/infection": "^0.7.0",
"monolog/monolog": "^1.21",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.4",
"phpstan/phpstan": "^0.9.1",
"phpunit/phpunit": "^6.5",
"sebastian/phpcpd": "^2.0",
"sebastian/phpcpd": "^3.0",
"simpletest/simpletest": "^1.1",
"squizlabs/php_codesniffer": "^3.0.0"
"squizlabs/php_codesniffer": "^3.0.0",
"theseer/phpdox": "^0.11.0"
},
"autoload": {
"psr-4": {
@@ -48,6 +47,8 @@
}
},
"scripts": {
"build": "robo build",
"clean": "robo clean",
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"phpstan": "phpstan analyse -l 3 -c phpstan.neon src tests",
"test": "phpunit -c build --no-coverage"

build/phpdox.xml → phpdox.xml View File

@@ -9,7 +9,7 @@
<bootstrap />

<!-- A phpDox project to process, you can have multiple projects in one config file -->
<project name="Query" source="../src" workdir="phpdox/xml">
<project name="Query" source="src" workdir="build/phpdox/xml">
<!-- @name - The name of the project -->
<!-- @source - The source directory of the application to process -->
<!-- @workdir - The directory to store the xml data files in -->
@@ -56,12 +56,12 @@
</collector>

<!-- Configuration of generation process -->
<generator output="../docs">
<generator output="apiDocumentation">
<!-- @output - (Base-)Directory to store output data in -->

<!-- A generation process consists of one or more build tasks and of (optional) enrich sources -->

<enrich base="logs">
<enrich base="build/logs">
<!-- @base - (Base-)Directory of datafiles used for enrich process -->

<!--<source type="...">-->
@@ -84,11 +84,9 @@
</source>

<!-- PHP Code Sniffer findings -->
<!--
<source type="phpcs">
<file name="logs/phpcs.xml" />
<file name="phpcs.xml" />
</source>
-->

<!-- PHPMessDetector -->
<!--
@@ -99,7 +97,7 @@

<!-- PHPUnit Coverage XML -->
<source type="phpunit">
<coverage path="logs/coverage.xml" />
<coverage path="coverage" />
<!-- <coverage path="clover.xml" />-->
<!-- @path - the directory where the xml code coverage report can be found -->
<!--<filter directory="${phpDox.project.source}" />-->

+ 0
- 3
src/BadDBDriverException.php View File

@@ -18,9 +18,6 @@ use InvalidArgumentException;

/**
* Generic exception for bad drivers
*
* @package Query
* @subpackage Core
*/
class BadDBDriverException extends InvalidArgumentException {
}

+ 1
- 1
src/Drivers/AbstractDriver.php View File

@@ -544,7 +544,7 @@ abstract class AbstractDriver

$sql = "INSERT INTO {$table} ("
. implode(',', $this->quoteIdent($fields))
. ") VALUES ";
. ') VALUES ';

// Create the placeholder groups
$params = array_fill(0, count($fields), '?');

+ 1
- 4
src/Drivers/AbstractSQL.php View File

@@ -15,10 +15,7 @@
namespace Query\Drivers;

/**
* parent for database manipulation subclasses
*
* @package Query
* @subpackage Drivers
* Parent for database-specific syntax subclasses
*/
abstract class AbstractSQL implements SQLInterface {


+ 0
- 4
src/Drivers/Pgsql/Driver.php View File

@@ -40,8 +40,6 @@ class Driver extends AbstractDriver {
parent::__construct($dsn, $username, $password, $options);
}

// --------------------------------------------------------------------------

/**
* Get a list of schemas for the current connection
*
@@ -58,8 +56,6 @@ SQL;
return $this->driverQuery($sql);
}

// --------------------------------------------------------------------------

/**
* Retrieve foreign keys for the table
*

+ 1
- 4
src/Drivers/SQLInterface.php View File

@@ -15,10 +15,7 @@
namespace Query\Drivers;

/**
* parent for database manipulation subclasses
*
* @package Query
* @subpackage Drivers
* Interface for database-specific syntax subclasses
*/
interface SQLInterface {


+ 2
- 2
src/Drivers/Sqlite/Driver.php View File

@@ -121,12 +121,12 @@ class Driver extends AbstractDriver {
{
$cols[] = $this->_quote($datum) . ' AS ' . $this->quoteIdent($colname);
}
$sql .= "SELECT " . implode(', ', $cols) . "\n";
$sql .= 'SELECT ' . implode(', ', $cols) . "\n";

foreach($data as $union)
{
$vals = array_map([$this, 'quote'], $union);
$sql .= "UNION SELECT " . implode(',', $vals) . "\n";
$sql .= 'UNION SELECT ' . implode(',', $vals) . "\n";
}

return [$sql, NULL];

+ 0
- 2
src/Drivers/Sqlite/Util.php View File

@@ -20,8 +20,6 @@ use Query\Drivers\AbstractUtil;
/**
* SQLite-specific backup, import and creation methods
*
* @package Query
* @subpackage Drivers
* @method mixed query(string $sql)
* @method string quote(string $str)
*/

+ 27
- 29
src/QueryBuilder.php View File

@@ -258,7 +258,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $tblname
* @return QueryBuilderInterface
*/
public function from($tblname): QueryBuilderInterface
public function from(string $tblname): QueryBuilderInterface
{
// Split identifiers on spaces
$identArray = explode(' ', \mb_trim($tblname));
@@ -286,7 +286,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $pos
* @return QueryBuilderInterface
*/
public function like($field, $val, $pos='both'): QueryBuilderInterface
public function like(string $field, $val, string $pos='both'): QueryBuilderInterface
{
return $this->_like($field, $val, $pos);
}
@@ -299,7 +299,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $pos
* @return QueryBuilderInterface
*/
public function orLike($field, $val, $pos='both'): QueryBuilderInterface
public function orLike(string $field, $val, string $pos='both'): QueryBuilderInterface
{
return $this->_like($field, $val, $pos, 'LIKE', 'OR');
}
@@ -312,9 +312,9 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $pos
* @return QueryBuilderInterface
*/
public function notLike($field, $val, $pos='both'): QueryBuilderInterface
public function notLike(string $field, $val, string $pos='both'): QueryBuilderInterface
{
return $this->_like($field, $val, $pos, 'NOT LIKE', 'AND');
return $this->_like($field, $val, $pos, 'NOT LIKE');
}

/**
@@ -325,7 +325,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $pos
* @return QueryBuilderInterface
*/
public function orNotLike($field, $val, $pos='both'): QueryBuilderInterface
public function orNotLike(string $field, $val, string $pos='both'): QueryBuilderInterface
{
return $this->_like($field, $val, $pos, 'NOT LIKE', 'OR');
}
@@ -343,7 +343,7 @@ class QueryBuilder implements QueryBuilderInterface {
*/
public function having($key, $val=[]): QueryBuilderInterface
{
return $this->_having($key, $val, 'AND');
return $this->_having($key, $val);
}

/**
@@ -422,7 +422,7 @@ class QueryBuilder implements QueryBuilderInterface {
*/
public function whereNotIn($field, $val=[]): QueryBuilderInterface
{
return $this->_whereIn($field, $val, 'NOT IN', 'AND');
return $this->_whereIn($field, $val, 'NOT IN');
}

/**
@@ -488,7 +488,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $type
* @return QueryBuilderInterface
*/
public function join($table, $condition, $type=''): QueryBuilderInterface
public function join(string $table, string $condition, string $type=''): QueryBuilderInterface
{
// Prefix and quote table name
$table = explode(' ', mb_trim($table));
@@ -537,7 +537,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $type
* @return QueryBuilderInterface
*/
public function orderBy($field, $type=''): QueryBuilderInterface
public function orderBy(string $field, string $type=''): QueryBuilderInterface
{
// When ordering by random, do an ascending order if the driver
// doesn't support random ordering
@@ -560,7 +560,7 @@ class QueryBuilder implements QueryBuilderInterface {
}

// Set the final string
$orderString = ( ! isset($rand))
$orderString = ! isset($rand)
? "\nORDER BY ".implode(', ', $orderClauses)
: "\nORDER BY".$rand;

@@ -576,7 +576,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param int|bool $offset
* @return QueryBuilderInterface
*/
public function limit($limit, $offset=FALSE): QueryBuilderInterface
public function limit(int $limit, $offset=FALSE): QueryBuilderInterface
{
$this->state->setLimit($limit);
$this->state->setOffset($offset);
@@ -668,7 +668,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param int|bool $offset
* @return PDOStatement
*/
public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement
public function get(string $table='', $limit=FALSE, $offset=FALSE): ?PDOStatement
{
// Set the table
if ( ! empty($table))
@@ -689,12 +689,12 @@ class QueryBuilder implements QueryBuilderInterface {
* Convenience method for get() with a where clause
*
* @param string $table
* @param array $where
* @param mixed $where
* @param int|bool $limit
* @param int|bool $offset
* @return PDOStatement
*/
public function getWhere($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement
public function getWhere(string $table, $where=[], $limit=FALSE, $offset=FALSE): ?PDOStatement
{
// Create the where clause
$this->where($where);
@@ -709,7 +709,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $table
* @return int
*/
public function countAll($table): int
public function countAll(string $table): int
{
$sql = 'SELECT * FROM '.$this->driver->quoteTable($table);
$res = $this->driver->query($sql);
@@ -745,7 +745,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param mixed $data
* @return PDOStatement
*/
public function insert($table, $data=[]): PDOStatement
public function insert(string $table, $data=[]): ?PDOStatement
{
if ( ! empty($data))
{
@@ -762,10 +762,10 @@ class QueryBuilder implements QueryBuilderInterface {
* @param array $data
* @return PDOStatement
*/
public function insertBatch($table, $data=[]): PDOStatement
public function insertBatch(string $table, $data=[]): ?PDOStatement
{
// Get the generated values and sql string
list($sql, $data) = $this->driver->insertBatch($table, $data);
[$sql, $data] = $this->driver->insertBatch($table, $data);

return $sql !== NULL
? $this->_run('', $table, $sql, $data)
@@ -779,7 +779,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param mixed $data
* @return PDOStatement
*/
public function update($table, $data=[]): PDOStatement
public function update(string $table, $data=[]): PDOStatement
{
if ( ! empty($data))
{
@@ -796,9 +796,9 @@ class QueryBuilder implements QueryBuilderInterface {
* @param string $table
* @param array|object $data
* @param string $where
* @return int|null
* @return PDOStatement|null
*/
public function updateBatch($table, $data, $where)
public function updateBatch(string $table, $data, $where): ?PDOStatement
{
// Get the generated values and sql string
list($sql, $data) = $this->driver->updateBatch($table, $data, $where);
@@ -815,7 +815,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param array $data
* @return \PDOStatement|null
*/
public function replace($table, $data=[])
public function replace(string $table, $data=[]): ?PDOStatement
{
if ( ! empty($data))
{
@@ -832,7 +832,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param mixed $where
* @return PDOStatement
*/
public function delete($table, $where=''): PDOStatement
public function delete(string $table, $where=''): ?PDOStatement
{
// Set the where clause
if ( ! empty($where))
@@ -916,8 +916,6 @@ class QueryBuilder implements QueryBuilderInterface {
$this->explain = FALSE;
}



/**
* Method to simplify select_ methods
*
@@ -1144,7 +1142,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param boolean $reset
* @return PDOStatement
*/
protected function _run(string $type, string $table, $sql=NULL, $vals=NULL, bool $reset=TRUE): PDOStatement
protected function _run(string $type, string $table, string $sql=NULL, array $vals=NULL, bool $reset=TRUE): PDOStatement
{
if ($sql === NULL)
{
@@ -1153,7 +1151,7 @@ class QueryBuilder implements QueryBuilderInterface {

if ($vals === NULL)
{
$vals = array_merge($this->state->getValues(), (array) $this->state->getWhereValues());
$vals = array_merge($this->state->getValues(), $this->state->getWhereValues());
}

$startTime = microtime(TRUE);
@@ -1185,7 +1183,7 @@ class QueryBuilder implements QueryBuilderInterface {
* @param int $totalTime
* @return void
*/
protected function _appendQuery($vals, string $sql, int $totalTime)
protected function _appendQuery(array $vals = NULL, string $sql, int $totalTime)
{
$evals = \is_array($vals) ? $vals : [];
$esql = str_replace('?', "%s", $sql);

+ 42
- 111
src/QueryBuilderInterface.php View File

@@ -18,9 +18,6 @@ use PDOStatement;

/**
* Interface defining the Query Builder class
*
* @package Query
* @subpackage QueryBuilder
*/
interface QueryBuilderInterface {

@@ -36,8 +33,6 @@ interface QueryBuilderInterface {
*/
public function select(string $fields): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Selects the maximum value of a field from a query
*
@@ -47,8 +42,6 @@ interface QueryBuilderInterface {
*/
public function selectMax(string $field, $as=FALSE): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Selects the minimum value of a field from a query
*
@@ -58,8 +51,6 @@ interface QueryBuilderInterface {
*/
public function selectMin(string $field, $as=FALSE): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Selects the average value of a field from a query
*
@@ -69,8 +60,6 @@ interface QueryBuilderInterface {
*/
public function selectAvg(string $field, $as=FALSE): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Selects the sum of a field from a query
*
@@ -80,8 +69,6 @@ interface QueryBuilderInterface {
*/
public function selectSum(string $field, $as=FALSE): QueryBuilderInterface;

// --------------------------------------------------------------------------q

/**
* Adds the 'distinct' keyword to a query
*
@@ -89,8 +76,6 @@ interface QueryBuilderInterface {
*/
public function distinct(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Shows the query plan for the query
*
@@ -98,15 +83,13 @@ interface QueryBuilderInterface {
*/
public function explain(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Specify the database table to select from
*
* @param string $tblname
* @return QueryBuilderInterface
*/
public function from($tblname): QueryBuilderInterface;
public function from(string $tblname): QueryBuilderInterface;

// --------------------------------------------------------------------------
// ! 'Like' methods
@@ -116,47 +99,41 @@ interface QueryBuilderInterface {
* Creates a Like clause in the sql statement
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @param string $pos
* @return QueryBuilderInterface
*/
public function like($field, $val, $pos='both'): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function like(string $field, $values, string $pos='both'): QueryBuilderInterface;

/**
* Generates an OR Like clause
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @param string $pos
* @return QueryBuilderInterface
*/
public function orLike($field, $val, $pos='both'): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function orLike(string $field, $values, string $pos='both'): QueryBuilderInterface;

/**
* Generates a NOT LIKE clause
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @param string $pos
* @return QueryBuilderInterface
*/
public function notLike($field, $val, $pos='both'): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function notLike(string $field, $values, string $pos='both'): QueryBuilderInterface;

/**
* Generates a OR NOT LIKE clause
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @param string $pos
* @return QueryBuilderInterface
*/
public function orNotLike($field, $val, $pos='both'): QueryBuilderInterface;
public function orNotLike(string $field, $values, string $pos='both'): QueryBuilderInterface;

// --------------------------------------------------------------------------
// ! Having methods
@@ -166,21 +143,19 @@ interface QueryBuilderInterface {
* Generates a 'Having' clause
*
* @param mixed $key
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function having($key, $val=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function having($key, $values=[]): QueryBuilderInterface;

/**
* Generates a 'Having' clause prefixed with 'OR'
*
* @param mixed $key
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function orHaving($key, $val=[]): QueryBuilderInterface;
public function orHaving($key, $values=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
// ! 'Where' methods
@@ -192,66 +167,56 @@ interface QueryBuilderInterface {
* passed array with key / value pairs
*
* @param mixed $key
* @param mixed $val
* @param mixed $values
* @param bool $escape
* @return QueryBuilderInterface
*/
public function where($key, $val=[], $escape = NULL): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function where($key, $values=[], $escape = NULL): QueryBuilderInterface;

/**
* Where clause prefixed with "OR"
*
* @param string $key
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function orWhere($key, $val=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function orWhere($key, $values=[]): QueryBuilderInterface;

/**
* Where clause with 'IN' statement
*
* @param mixed $field
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function whereIn($field, $val=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function whereIn($field, $values=[]): QueryBuilderInterface;

/**
* Where in statement prefixed with "or"
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function orWhereIn($field, $val=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function orWhereIn($field, $values=[]): QueryBuilderInterface;

/**
* WHERE NOT IN (FOO) clause
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function whereNotIn($field, $val=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function whereNotIn($field, $values=[]): QueryBuilderInterface;

/**
* OR WHERE NOT IN (FOO) clause
*
* @param string $field
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function orWhereNotIn($field, $val=[]): QueryBuilderInterface;
public function orWhereNotIn($field, $values=[]): QueryBuilderInterface;

// --------------------------------------------------------------------------
// ! Other Query Modifier methods
@@ -261,12 +226,10 @@ interface QueryBuilderInterface {
* Sets values for inserts / updates / deletes
*
* @param mixed $key
* @param mixed $val
* @param mixed $values
* @return QueryBuilderInterface
*/
public function set($key, $val = NULL): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function set($key, $values = NULL): QueryBuilderInterface;

/**
* Creates a join phrase in a compiled query
@@ -276,9 +239,7 @@ interface QueryBuilderInterface {
* @param string $type
* @return QueryBuilderInterface
*/
public function join($table, $condition, $type=''): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function join(string $table, string $condition, string $type=''): QueryBuilderInterface;

/**
* Group the results by the selected field(s)
@@ -288,8 +249,6 @@ interface QueryBuilderInterface {
*/
public function groupBy($field): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Order the results by the selected field(s)
*
@@ -297,9 +256,7 @@ interface QueryBuilderInterface {
* @param string $type
* @return QueryBuilderInterface
*/
public function orderBy($field, $type=""): QueryBuilderInterface;

// --------------------------------------------------------------------------
public function orderBy(string $field, string $type=''): QueryBuilderInterface;

/**
* Set a limit on the current sql statement
@@ -308,7 +265,7 @@ interface QueryBuilderInterface {
* @param int|bool $offset
* @return QueryBuilderInterface
*/
public function limit($limit, $offset=FALSE): QueryBuilderInterface;
public function limit(int $limit, $offset=FALSE): QueryBuilderInterface;

// --------------------------------------------------------------------------
// ! Query Grouping Methods
@@ -321,8 +278,6 @@ interface QueryBuilderInterface {
*/
public function groupStart(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Adds a paren to the current query for query grouping,
* prefixed with 'NOT'
@@ -331,8 +286,6 @@ interface QueryBuilderInterface {
*/
public function notGroupStart(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Adds a paren to the current query for query grouping,
* prefixed with 'OR'
@@ -341,8 +294,6 @@ interface QueryBuilderInterface {
*/
public function orGroupStart(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Adds a paren to the current query for query grouping,
* prefixed with 'OR NOT'
@@ -351,8 +302,6 @@ interface QueryBuilderInterface {
*/
public function orNotGroupStart(): QueryBuilderInterface;

// --------------------------------------------------------------------------

/**
* Ends a query group
*
@@ -373,9 +322,7 @@ interface QueryBuilderInterface {
* @param int|bool $offset
* @return PDOStatement
*/
public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement;

// --------------------------------------------------------------------------
public function get(string $table='', $limit=FALSE, $offset=FALSE): ?PDOStatement;

/**
* Convenience method for get() with a where clause
@@ -386,9 +333,7 @@ interface QueryBuilderInterface {
* @param int|bool $offset
* @return PDOStatement
*/
public function getWhere($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement;

// --------------------------------------------------------------------------
public function getWhere(string $table, $where=[], $limit=FALSE, $offset=FALSE): ?PDOStatement;

/**
* Retrieve the number of rows in the selected table
@@ -396,9 +341,7 @@ interface QueryBuilderInterface {
* @param string $table
* @return int
*/
public function countAll($table): int;

// --------------------------------------------------------------------------
public function countAll(string $table): int;

/**
* Retrieve the number of results for the generated query - used
@@ -410,8 +353,6 @@ interface QueryBuilderInterface {
*/
public function countAllResults(string $table='', bool $reset=TRUE): int;

// --------------------------------------------------------------------------

/**
* Creates an insert clause, and executes it
*
@@ -419,31 +360,25 @@ interface QueryBuilderInterface {
* @param mixed $data
* @return PDOStatement
*/
public function insert($table, $data=[]): PDOStatement;

// --------------------------------------------------------------------------
public function insert(string $table, $data=[]): ?PDOStatement;

/**
* Creates and executes a batch insertion query
*
* @param string $table
* @param array $data
* @return \PDOStatement|null
* @return PDOStatement
*/
public function insertBatch($table, $data=[]);

// --------------------------------------------------------------------------
public function insertBatch(string $table, $data=[]): ?PDOStatement;

/**
* Insertion with automatic overwrite, rather than attempted duplication
*
* @param string $table
* @param array $data
* @return \PDOStatement|null
* @return PDOStatement
*/
public function replace($table, $data=[]);

// --------------------------------------------------------------------------
public function replace(string $table, $data=[]): ?PDOStatement;

/**
* Creates an update clause, and executes it
@@ -452,9 +387,7 @@ interface QueryBuilderInterface {
* @param mixed $data
* @return PDOStatement
*/
public function update($table, $data=[]): PDOStatement;

// --------------------------------------------------------------------------
public function update(string $table, $data=[]): ?PDOStatement;

/**
* Creates a batch update, and executes it.
@@ -463,11 +396,9 @@ interface QueryBuilderInterface {
* @param string $table
* @param array|object $data
* @param string $where
* @return int|null
* @return PDOStatement
*/
public function updateBatch($table, $data, $where);

// --------------------------------------------------------------------------
public function updateBatch(string $table, $data, $where): ?PDOStatement;

/**
* Deletes data from a table
@@ -476,7 +407,7 @@ interface QueryBuilderInterface {
* @param mixed $where
* @return PDOStatement
*/
public function delete($table, $where=''): PDOStatement;
public function delete(string $table, $where=''): ?PDOStatement;

// --------------------------------------------------------------------------
// ! SQL Returning Methods

+ 16
- 17
src/State.php View File

@@ -6,12 +6,13 @@
*
* PHP version 7.1
*
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2012 - 2018 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
*/

namespace Query;

/**
@@ -92,7 +93,7 @@ class State {

/**
* Value for limit string
* @var int
* @var integer
*/
protected $limit;

@@ -123,22 +124,20 @@ class State {
*/
protected $havingMap = [];

// --------------------------------------------------------------------------

/**
* @param string $str
* @return State
*/
/**
* @param string $str
* @return State
*/
public function setSelectString(string $str): self
{
$this->selectString = $str;
return $this;
}
{
$this->selectString = $str;
return $this;
}

/**
* @return string
*/
public function getSelectString(): string
public function getSelectString(): string
{
return $this->selectString;
}
@@ -147,7 +146,7 @@ class State {
* @param string $str
* @return State
*/
public function appendSelectString(string $str): self
public function appendSelectString(string $str): self
{
$this->selectString .= $str;
return $this;

+ 0
- 11
src/common.php View File

@@ -13,14 +13,11 @@
* @link https://git.timshomepage.net/aviat4ion/Query
*/


use Query\{
ConnectionManager,
QueryBuilderInterface
};

// --------------------------------------------------------------------------

/**
* Global functions that don't really fit anywhere else
*/
@@ -36,8 +33,6 @@ function mb_trim(string $string): string
return preg_replace('/(^\s+)|(\s+$)/u', '', $string);
}

// --------------------------------------------------------------------------

/**
* Filter out db rows into one array
*
@@ -57,8 +52,6 @@ function dbFilter(array $array, $index): array
return $newArray;
}

// --------------------------------------------------------------------------

/**
* Zip a set of arrays together on common keys
*
@@ -87,8 +80,6 @@ function arrayZipper(array $zipperInput): array
return $output;
}

// --------------------------------------------------------------------------

/**
* Determine whether a value in the passed array matches the pattern
* passed
@@ -115,8 +106,6 @@ function regexInArray(array $array, string $pattern): bool
return FALSE;
}

// --------------------------------------------------------------------------

/**
* Connection function
*

+ 1
- 28
tests/BaseDriverTest.php View File

@@ -12,9 +12,8 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
*/
namespace Query\Tests;

// --------------------------------------------------------------------------
namespace Query\Tests;

/**
* Parent Database Test Class
@@ -28,15 +27,11 @@ abstract class BaseDriverTest extends TestCase {

abstract public function testConnection();

// --------------------------------------------------------------------------

public static function tearDownAfterClass()
{
self::$db = NULL;
}

// --------------------------------------------------------------------------

public function testGetTables()
{
$tables = self::$db->getTables();
@@ -44,8 +39,6 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue( ! empty($tables));
}

// --------------------------------------------------------------------------

public function testGetSystemTables()
{
$tables = self::$db->getSystemTables();
@@ -53,16 +46,12 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue( ! empty($tables));
}

// --------------------------------------------------------------------------

public function testBackupData()
{
$this->assertTrue(is_string(self::$db->getUtil()->backupData(array('create_delete', FALSE))));
$this->assertTrue(is_string(self::$db->getUtil()->backupData(array('create_delete', TRUE))));
}

// --------------------------------------------------------------------------

public function testGetColumns()
{
$cols = self::$db->getColumns('test');
@@ -70,8 +59,6 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue( ! empty($cols));
}

// --------------------------------------------------------------------------

public function testGetTypes()
{
$types = self::$db->getTypes();
@@ -79,8 +66,6 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue( ! empty($types));
}

// --------------------------------------------------------------------------

public function testGetFKs()
{
$expected = array(array(
@@ -95,16 +80,12 @@ abstract class BaseDriverTest extends TestCase {
$this->assertEqual($expected, $keys);
}

// --------------------------------------------------------------------------

public function testGetIndexes()
{
$keys = self::$db->getIndexes('test');
$this->assertTrue(is_array($keys));
}

// --------------------------------------------------------------------------

public function testGetViews()
{
$views = self::$db->getViews();
@@ -113,8 +94,6 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue(is_array($views));
}

// --------------------------------------------------------------------------

public function testGetTriggers()
{
// @TODO standardize trigger output for different databases
@@ -123,8 +102,6 @@ abstract class BaseDriverTest extends TestCase {
$this->assertTrue(is_array($triggers));
}

// --------------------------------------------------------------------------

public function testGetSequences()
{
$seqs = self::$db->getSequences();
@@ -138,16 +115,12 @@ abstract class BaseDriverTest extends TestCase {
$this->assertEqual($expected, $seqs);
}

// --------------------------------------------------------------------------

public function testGetProcedures()
{
$procedures = self::$db->getProcedures();
$this->assertTrue(is_array($procedures));
}

// --------------------------------------------------------------------------

public function testGetFunctions()
{
$funcs = self::$db->getFunctions();

+ 0
- 12
tests/ConnectionManagerTest.php View File

@@ -26,8 +26,6 @@ class ConnectionManagerTest extends TestCase {
self::$instance = ConnectionManager::getInstance();
}

// --------------------------------------------------------------------------

public function testNoClone()
{
$this->expectException('DomainException');
@@ -36,8 +34,6 @@ class ConnectionManagerTest extends TestCase {
$this->assertNull($clone);
}

// --------------------------------------------------------------------------

public function testNoSerialize()
{
$this->expectException(DomainException::class);
@@ -49,8 +45,6 @@ class ConnectionManagerTest extends TestCase {
self::$instance->__sleep();
}

// --------------------------------------------------------------------------

public function testNoUnserialize()
{
$this->expectException(DomainException::class);
@@ -58,8 +52,6 @@ class ConnectionManagerTest extends TestCase {
self::$instance->__wakeup();
}

// --------------------------------------------------------------------------

public function testParseParams()
{
$params = (object) array(
@@ -80,8 +72,6 @@ class ConnectionManagerTest extends TestCase {
$this->assertEqual($expected, self::$instance->parseParams($params));
}

// --------------------------------------------------------------------------

public function testConnect()
{
$params = (object) array(
@@ -101,8 +91,6 @@ class ConnectionManagerTest extends TestCase {
$this->assertEqual($conn, self::$instance->getConnection());
}

// --------------------------------------------------------------------------

public function testGetConnection()
{
$params = (object) array(

+ 0
- 5
tests/CoreTest.php View File

@@ -14,9 +14,6 @@
*/
namespace Query\Tests;


// --------------------------------------------------------------------------

/**
* CoreTest class - Compatibility and core functionality tests
*
@@ -36,8 +33,6 @@ class CoreTest extends TestCase {
$this->assertTrue(PHP_VERSION_ID >= 70000);
}

// --------------------------------------------------------------------------

/**
* TestHasPDO function.
*

+ 0
- 27
tests/Drivers/MySQL/MySQLDriverTest.php View File

@@ -22,7 +22,6 @@ use TypeError;
/**
* MySQLTest class.
*
* @extends DBTest
* @requires extension pdo_mysql
*/
class MySQLDriverTest extends BaseDriverTest {
@@ -47,22 +46,16 @@ class MySQLDriverTest extends BaseDriverTest {
self::$db->setTablePrefix('create_');
}

// --------------------------------------------------------------------------

public function testExists()
{
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE));
}

// --------------------------------------------------------------------------

public function testConnection()
{
$this->assertIsA(self::$db, Driver::class);
}

// --------------------------------------------------------------------------

public function testCreateTable()
{
self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/mysql.sql'));
@@ -101,8 +94,6 @@ class MySQLDriverTest extends BaseDriverTest {

}

// --------------------------------------------------------------------------

public function testTruncate()
{
self::$db->truncate('test');
@@ -112,8 +103,6 @@ class MySQLDriverTest extends BaseDriverTest {
$this->assertEquals(0, self::$db->countAll('join'));
}

// --------------------------------------------------------------------------

public function testPreparedStatements()
{
$sql = <<<SQL
@@ -128,8 +117,6 @@ SQL;

}

// --------------------------------------------------------------------------

public function testBadPreparedStatement()
{
$this->expectException(TypeError::class);
@@ -143,8 +130,6 @@ SQL;

}

// --------------------------------------------------------------------------

public function testPrepareExecute()
{
$sql = <<<SQL
@@ -159,8 +144,6 @@ SQL;

}

// --------------------------------------------------------------------------

public function testCommitTransaction()
{
$res = self::$db->beginTransaction();
@@ -172,8 +155,6 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testRollbackTransaction()
{
$res = self::$db->beginTransaction();
@@ -185,26 +166,18 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testGetSchemas()
{
$this->assertNull(self::$db->getSchemas());
}

// --------------------------------------------------------------------------

public function testGetSequences()
{
$this->assertNull(self::$db->getSequences());
}

// --------------------------------------------------------------------------

public function testBackup()
{
$this->assertTrue(is_string(self::$db->getUtil()->backupStructure()));
}


}

+ 0
- 6
tests/Drivers/MySQL/MySQLQueryBuilderTest.php View File

@@ -17,8 +17,6 @@ namespace Query\Tests\Drivers\MySQL;
use PDO;
use Query\Tests\BaseQueryBuilderTest;

// --------------------------------------------------------------------------

/**
* @requires extension pdo_mysql
*/
@@ -51,15 +49,11 @@ class MySQLQueryBuilderTest extends BaseQueryBuilderTest {
self::$db = Query($params);
}

// --------------------------------------------------------------------------

public function testExists()
{
$this->assertTrue(\in_array('mysql', PDO::getAvailableDrivers(), TRUE));
}

// --------------------------------------------------------------------------

public function testQueryExplain()
{
$query = self::$db->select('id, key as k, val')

+ 1
- 27
tests/Drivers/PgSQL/PgSQLDriverTest.php View File

@@ -12,11 +12,9 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
*/
namespace Query\Tests\Drivers\PgSQL;

// --------------------------------------------------------------------------
namespace Query\Tests\Drivers\PgSQL;

use InvalidArgumentException;
use PDO;
use Query\Drivers\Pgsql\Driver;
use Query\Tests\BaseDriverTest;
@@ -57,16 +55,12 @@ class PgSQLDriverTest extends BaseDriverTest {
self::$db->setTablePrefix('create_');
}

// --------------------------------------------------------------------------

public function testExists()
{
$drivers = PDO::getAvailableDrivers();
$this->assertTrue(in_array('pgsql', $drivers, TRUE));
}

// --------------------------------------------------------------------------

public function testConnection()
{
if (empty(self::$db)) return;
@@ -74,8 +68,6 @@ class PgSQLDriverTest extends BaseDriverTest {
$this->assertIsA(self::$db, Driver::class);
}

// --------------------------------------------------------------------------

public function testCreateTable()
{
self::$db->exec(file_get_contents(QTEST_DIR.'/db_files/pgsql.sql'));
@@ -126,8 +118,6 @@ class PgSQLDriverTest extends BaseDriverTest {

}

// --------------------------------------------------------------------------

public function testTruncate()
{
self::$db->truncate('test');
@@ -137,8 +127,6 @@ class PgSQLDriverTest extends BaseDriverTest {
$this->assertEquals(0, self::$db->countAll('join'));
}

// --------------------------------------------------------------------------

public function testPreparedStatements()
{
$sql = <<<SQL
@@ -159,8 +147,6 @@ SQL;
], $res);
}

// --------------------------------------------------------------------------

public function testBadPreparedStatement()
{
$this->expectException(TypeError::class);
@@ -173,8 +159,6 @@ SQL;
self::$db->prepareQuery($sql, 'foo');
}

// --------------------------------------------------------------------------

public function testPrepareExecute()
{
if (empty(self::$db)) return;
@@ -197,8 +181,6 @@ SQL;
], $res);
}

// --------------------------------------------------------------------------

public function testCommitTransaction()
{
if (empty(self::$db)) return;
@@ -212,8 +194,6 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testRollbackTransaction()
{
if (empty(self::$db)) return;
@@ -227,22 +207,16 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testGetSchemas()
{
$this->assertTrue(is_array(self::$db->getSchemas()));
}

// --------------------------------------------------------------------------

public function testGetDBs()
{
$this->assertTrue(is_array(self::$db->getDbs()));
}

// --------------------------------------------------------------------------

public function testGetFunctions()
{
$this->assertNull(self::$db->getFunctions());

+ 1
- 7
tests/Drivers/PgSQL/PgSQLQueryBuilderTest.php View File

@@ -17,8 +17,6 @@ namespace Query\Tests\Drivers\PgSQL;
use PDO;
use Query\Tests\BaseQueryBuilderTest;

// --------------------------------------------------------------------------

/**
* @requires extension pdo_pgsql
*/
@@ -58,19 +56,15 @@ class PgSQLQueryBuilderTest extends BaseQueryBuilderTest {
// If the database isn't installed, skip the tests
if ( ! \in_array('pgsql', PDO::getAvailableDrivers(), TRUE))
{
$this->markTestSkipped("Postgres extension for PDO not loaded");
$this->markTestSkipped('Postgres extension for PDO not loaded');
}
}

// --------------------------------------------------------------------------

public function testExists()
{
$this->assertTrue(\in_array('pgsql', PDO::getAvailableDrivers(), TRUE));
}

// --------------------------------------------------------------------------

public function testQueryExplain()
{
$query = self::$db->select('id, key as k, val')

+ 0
- 30
tests/Drivers/SQLite/SQLiteDriverTest.php View File

@@ -18,8 +18,6 @@ use PDO;
use Query\Drivers\Sqlite\Driver;
use Query\Tests\BaseDriverTest;

// --------------------------------------------------------------------------

/**
* SQLiteTest class.
*
@@ -64,8 +62,6 @@ class SQLiteDriverTest extends BaseDriverTest {
$this->assertTrue(\in_array('create_delete', $dbs, TRUE));
}

// --------------------------------------------------------------------------

/*public function testBackupData()
{
$sql = mb_trim(self::$db->getUtil()->backupData(array('create_join', 'create_test')));
@@ -83,8 +79,6 @@ SQL;
$this->assertEqual($expectedArray, $sqlArray);
}*/

// --------------------------------------------------------------------------

public function testBackupStructure()
{
$sql = mb_trim(self::$db->getUtil()->backupStructure());
@@ -159,8 +153,6 @@ SQL;
$this->assertEqual($expectedArray, $resultArray);
}

// --------------------------------------------------------------------------

public function testDeleteTable()
{
$sql = self::$db->getUtil()->deleteTable('create_delete');
@@ -188,16 +180,12 @@ SQL;
unset($db);
}

// --------------------------------------------------------------------------

public function testTruncate()
{
self::$db->truncate('create_test');
$this->assertEquals(0, self::$db->countAll('create_test'));
}

// --------------------------------------------------------------------------

public function testPreparedStatements()
{
$sql = <<<SQL
@@ -218,8 +206,6 @@ SQL;
], $res);
}

// --------------------------------------------------------------------------

public function testPrepareExecute()
{
$sql = <<<SQL
@@ -240,8 +226,6 @@ SQL;
], $res);
}

// --------------------------------------------------------------------------

public function testCommitTransaction()
{
$res = self::$db->beginTransaction();
@@ -253,8 +237,6 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testRollbackTransaction()
{
$res = self::$db->beginTransaction();
@@ -266,15 +248,11 @@ SQL;
$this->assertTrue($res);
}

// --------------------------------------------------------------------------

public function testGetDBs()
{
$this->assertTrue(is_array(self::$db->getDbs()));
}

// --------------------------------------------------------------------------

public function testGetSchemas()
{
$this->assertNull(self::$db->getSchemas());
@@ -296,30 +274,22 @@ SQL;
$this->assertEqual(NULL, $sql);
}

// --------------------------------------------------------------------------

public function testGetSystemTables()
{
$sql = self::$db->getSystemTables();
$this->assertTrue(\is_array($sql));
}

// --------------------------------------------------------------------------

public function testGetSequences()
{
$this->assertNull(self::$db->getSequences());
}

// --------------------------------------------------------------------------

public function testGetFunctions()
{
$this->assertNull(self::$db->getFunctions());
}

// --------------------------------------------------------------------------

public function testGetProcedures()
{
$this->assertNull(self::$db->getProcedures());

+ 0
- 6
tests/Drivers/SQLite/SQLiteQueryBuilderTest.php View File

@@ -17,8 +17,6 @@ namespace Query\Tests\Drivers\SQLite;
use PDO;
use Query\Tests\BaseQueryBuilderTest;

// --------------------------------------------------------------------------

/**
* Class for testing Query Builder with SQLite
*
@@ -32,8 +30,6 @@ use Query\Tests\BaseQueryBuilderTest;
self::$db = Query('test_sqlite');
}

// --------------------------------------------------------------------------

public function testQueryFunctionAlias()
{
$db = Query('test_sqlite');
@@ -41,8 +37,6 @@ use Query\Tests\BaseQueryBuilderTest;
$this->assertTrue(self::$db === $db, "Alias passed into query function gives the original object back");
}

// --------------------------------------------------------------------------

public function testQueryExplain()
{
$query = self::$db->select('id, key as k, val')

+ 0
- 3
tests/bootstrap.php View File

@@ -18,8 +18,6 @@ define('QTEST_DIR', realpath(__DIR__));
define('QBASE_DIR', realpath(QTEST_DIR.'/../') . '/');
define('QDS', DIRECTORY_SEPARATOR);

// --------------------------------------------------------------------------

function get_json_config()
{
$files = array(
@@ -38,7 +36,6 @@ function get_json_config()
return FALSE;
}

// --------------------------------------------------------------------------
$path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
@unlink($path);


Loading…
Cancel
Save