diff --git a/.gitignore b/.gitignore index c6b05f1..2e700e6 100644 --- a/.gitignore +++ b/.gitignore @@ -130,14 +130,13 @@ $RECYCLE.BIN/ test_config.json index.html -tests/db_files/* +tests/db_files/*.db build/api/* build/coverage/* build/logs/* build/pdepend/* build/phpdox/* cache.properties -._* tests/settings.json .php_cs coverage/* @@ -146,3 +145,4 @@ composer.lock docs/phpdoc* .project all_tests +build/.phpunit.result.cache diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index eecc367..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -before_script: - # Install dependencies - - bash build/docker_install.sh > /dev/null - -services: - - mysql:latest - - postgres:latest - -variables: - MYSQL_ROOT_PASSWORD: foo-bar-baz - MYSQL_DATABASE: test - MYSQL_USER: test - MYSQL_PASSWORD: test - POSTGRES_DB: test - POSTGRES_USER: test - POSTGRES_PASSWORD: test - -test:7.1: - image: php:7.1 - script: - - phpunit -c build --no-coverage - -test:7.2: - image: php:7.2 - script: - - phpunit -c build --no-coverage diff --git a/.travis.yml b/.travis.yml index 47984a8..e01e986 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,23 @@ -sudo: false +dist: xenial +os: linux + +arch: amd64 language: php +services: + - mysql + - postgresql + php: - - 7.1 - - 7.2 + - 7.4 - nightly before_script: - psql -c 'DROP DATABASE IF EXISTS test;' -U postgres - psql -c 'create database test;' -U postgres - mysql -e 'create database IF NOT EXISTS test;' - - composer install + - composer install --ignore-platform-reqs script: - mkdir -p build/logs @@ -20,9 +26,9 @@ script: - cd ../ after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml -matrix: +jobs: allow_failures: - php: nightly diff --git a/README.md b/README.md index b5df5fa..b58e4c0 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,20 @@ A query builder/database abstraction layer, using prepared statements for security. -[![Build Status](https://jenkins.timshomepage.net/buildStatus/icon?job=query)](https://jenkins.timshomepage.net/job/query/) [![Code Coverage](https://scrutinizer-ci.com/g/aviat4ion/Query/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/aviat4ion/Query/?branch=develop) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/aviat4ion/Query/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/aviat4ion/Query/?branch=develop) [![Latest Stable Version](https://poser.pugx.org/aviat/query/v/stable.png)](https://packagist.org/packages/aviat/query) [![Total Downloads](https://poser.pugx.org/aviat/query/downloads.png)](https://packagist.org/packages/aviat/query) [![Latest Unstable Version](https://poser.pugx.org/aviat/query/v/unstable.png)](https://packagist.org/packages/aviat/query) -[![License](https://poser.pugx.org/aviat/query/license.png)](http://www.dbad-license.org/) ## Requirements -* PDO extensions for the databases you wish to use (unless it's Firebird, in which case, the interbase extension is required) -* Supported version of PHP (Older versions may work, but are not supported) +* PDO extensions for the databases you wish to use +* PHP 7.4 or later ## Databases Supported -* MySQL -* PostgreSQL +* MySQL 5+ / MariaDB +* PostgreSQL 8.4+ * SQLite ## Including Query in your application @@ -32,7 +30,7 @@ Create a connection array or object similar to this: 'mysql', // mysql, pgsql, firebird, sqlite + 'type' => 'mysql', // mysql, pgsql, sqlite 'host' => 'localhost', // address or socket 'user' => 'root', 'pass' => '', @@ -40,10 +38,10 @@ $params = array( 'database' => 'test_db', // Only required for - // SQLite + // SQLite 'file' => '/path/to/db/file', - // Optional paramaters + // Optional parameters 'prefix' => 'tbl_', // Database table prefix 'alias' => 'old' // Connection name for the Query function ); @@ -78,8 +76,13 @@ Query('old')->query($sql); ``` ### Running Queries -Query uses the same interface as CodeIgniter's [Query Builder](http://www.codeigniter.com/user_guide/database/query_builder.html) class. However, it does not implement the `update_batch` or caching methods. For specific query builder methods, see the [class documentation](https://gitdev.timshomepage.net/Query/docs/classes/Query_QueryBuilder.html#methods). -Underscored methods are also aliased to camel case methods. +Query is based on CodeIgniter's [Query Builder](http://www.codeigniter.com/user_guide/database/query_builder.html) class. +However, it has camelCased method names, and does not implement the caching methods. +For specific query builder methods, see the [class documentation](https://gitdev.timshomepage.net/Query/apiDocumentation/classes/Query_QueryBuilder.html#methods). + +Other database methods not directly involved in building queries, are also available from the query builder object. +The methods available depend on the database, but common methods are documented +[here](https://gitdev.timshomepage.net/Query/apiDocumentation/classes/Query_Drivers_AbstractDriver.html#methods). #### You can also run queries manually. @@ -97,7 +100,7 @@ An example of a moderately complex query: $query = $db->select('id, key as k, val') ->from('table t') ->where('k >', 3) - ->orWhere('id !=' 5) + ->orWhere('id !=', 5) ->orderBy('val', 'DESC') ->limit(3, 1) ->get(); @@ -114,8 +117,10 @@ ORDER BY "val" DESC LIMIT 3 OFFSET 1 ``` - -To retrieve the results of a query, use the PDO method [fetch](http://php.net/manual/en/pdostatement.fetch.php) and/or [fetchAll](http://php.net/manual/en/pdostatement.fetchall.php). +The query execution methods `get`, `getWhere`, `insert`, + `insertBatch`,`update`, and `delete` return a native [PDOStatement](http://php.net/manual/en/class.pdostatement.php) object. +To retrieve the results of a query, use the PDOStatement method [fetch](http://php.net/manual/en/pdostatement.fetch.php) and/or +[fetchAll](http://php.net/manual/en/pdostatement.fetchall.php). ```php prepare(); $this->lint(); $this->phploc(TRUE); $this->phpcs(TRUE); - $this->dependencyReport(); + $this->phpmd(TRUE); $this->phpcpdReport(); } /** * Run all tests, generate coverage, generate docs, generate code statistics */ - public function build() + public function build(): void { $this->analyze(); $this->coverage(); @@ -74,11 +77,11 @@ class RoboFile extends \Robo\Tasks { /** * Cleanup temporary files */ - public function clean() + public function clean(): void { // So the task doesn't complain, // make any 'missing' dirs to cleanup - array_map(function ($dir) { + array_map(static function ($dir) { if ( ! is_dir($dir)) { `mkdir -p {$dir}`; @@ -92,7 +95,7 @@ class RoboFile extends \Robo\Tasks { /** * Run unit tests and generate coverage reports */ - public function coverage() + public function coverage(): void { $this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']); } @@ -100,7 +103,7 @@ class RoboFile extends \Robo\Tasks { /** * Generate documentation with phpdox */ - public function docs() + public function docs(): void { $this->_run(['vendor/bin/phpdox']); } @@ -108,11 +111,11 @@ class RoboFile extends \Robo\Tasks { /** * Verify that source files are valid */ - public function lint() + public function lint(): void { $files = $this->getAllSourceFiles(); - $chunks = array_chunk($files, (int)`getconf _NPROCESSORS_ONLN`); + $chunks = array_chunk($files, (int)shell_exec('getconf _NPROCESSORS_ONLN')); foreach($chunks as $chunk) { @@ -125,7 +128,7 @@ class RoboFile extends \Robo\Tasks { * * @param bool $report - if true, generates reports instead of direct output */ - public function phpcs($report = FALSE) + public function phpcs($report = FALSE): void { $dir = __DIR__; @@ -145,12 +148,36 @@ class RoboFile extends \Robo\Tasks { $this->_run($cmd_parts); } + public function phpmd($report = FALSE): void + { + $report_cmd_parts = [ + 'vendor/bin/phpmd', + './src', + 'xml', + 'cleancode,codesize,controversial,design,naming,unusedcode', + '--exclude ParallelAPIRequest', + '--reportfile ./build/logs/phpmd.xml' + ]; + + $normal_cmd_parts = [ + 'vendor/bin/phpmd', + './src', + 'ansi', + 'cleancode,codesize,controversial,design,naming,unusedcode', + '--exclude ParallelAPIRequest' + ]; + + $cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts; + + $this->_run($cmd_parts); + } + /** * Run the phploc tool * * @param bool $report - if true, generates reports instead of direct output */ - public function phploc($report = FALSE) + public function phploc($report = FALSE): void { // Command for generating reports $report_cmd_parts = [ @@ -178,7 +205,7 @@ class RoboFile extends \Robo\Tasks { /** * Create temporary directories */ - public function prepare() + public function prepare(): void { array_map([$this, '_mkdir'], $this->taskDirs); } @@ -186,11 +213,11 @@ class RoboFile extends \Robo\Tasks { /** * Lint php files and run unit tests */ - public function test() + public function test(): void { $this->lint(); $this->taskPhpUnit() - ->configFile('phpunit.xml') + ->configFile('build/phpunit.xml') ->run(); $this->_run(["php tests/index.php"]); } @@ -198,7 +225,7 @@ class RoboFile extends \Robo\Tasks { /** * Watches for file updates, and automatically runs appropriate actions */ - public function watch() + public function watch(): void { $this->taskWatch() ->monitor('composer.json', function() { @@ -213,27 +240,12 @@ class RoboFile extends \Robo\Tasks { ->run(); } - /** - * Create pdepend reports - */ - protected function dependencyReport() - { - $cmd_parts = [ - 'vendor/bin/pdepend', - '--jdepend-xml=build/logs/jdepend.xml', - '--jdepend-chart=build/pdepend/dependencies.svg', - '--overview-pyramid=build/pdepend/overview-pyramid.svg', - 'src' - ]; - $this->_run($cmd_parts); - } - /** * Get the total list of source files, including tests * * @return array */ - protected function getAllSourceFiles() + protected function getAllSourceFiles(): array { $files = array_merge( glob_recursive('build/*.php'), @@ -252,7 +264,7 @@ class RoboFile extends \Robo\Tasks { * * @param array $chunk */ - protected function parallelLint(array $chunk) + protected function parallelLint(array $chunk): void { $task = $this->taskParallelExec() ->timeout(5) @@ -269,7 +281,7 @@ class RoboFile extends \Robo\Tasks { /** * Generate copy paste detector report */ - protected function phpcpdReport() + protected function phpcpdReport(): void { $cmd_parts = [ 'vendor/bin/phpcpd', @@ -286,8 +298,8 @@ class RoboFile extends \Robo\Tasks { * @param array $cmd_parts - command arguments * @param string $join_on - what to join the command arguments with */ - protected function _run(array $cmd_parts, $join_on = ' ') + protected function _run(array $cmd_parts, $join_on = ' '): void { $this->taskExec(implode($join_on, $cmd_parts))->run(); } -} \ No newline at end of file +} diff --git a/apiDocumentation/classes.html b/apiDocumentation/classes.html index 63bf659..49a4db4 100644 --- a/apiDocumentation/classes.html +++ b/apiDocumentation/classes.html @@ -41,6 +41,26 @@
+Name | +Description | ++ |
---|---|---|
+ BadDBDriverException + | +Generic exception for bad drivers | +EMPTY + | +
+ NonExistentConnectionException + | +Exception for missing database connection | +EMPTY + | +
+ NotImplementedException + | +Exception for non-implemented method | +EMPTY + | +