From 77df254a0c3000f81cd361fb4747cc61e9c8043b Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 19 Mar 2020 11:53:08 -0400 Subject: [PATCH] Implement basic 'returning' method for Postgres --- RoboFile.php | 86 +++++---- build/header_comment.txt | 2 +- build/phpunit.xml | 5 +- composer.json | 125 +++++++------ phpdox.xml | 12 +- src/QueryBuilder.php | 122 +++++++++--- src/QueryBuilderInterface.php | 9 + src/State.php | 177 ++++-------------- tests/BaseQueryBuilderTest.php | 52 +++++ tests/Drivers/MySQL/MySQLQueryBuilderTest.php | 12 +- .../Drivers/SQLite/SQLiteQueryBuilderTest.php | 12 +- 11 files changed, 342 insertions(+), 272 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 250395f..43efd50 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -1,4 +1,7 @@ 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,19 +95,15 @@ class RoboFile extends \Robo\Tasks { /** * Run unit tests and generate coverage reports */ - public function coverage() + public function coverage(): void { - $this->taskPhpUnit() - ->configFile('build/phpunit.xml') - ->run(); - // $this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']); - + $this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']); } /** * Generate documentation with phpdox */ - public function docs() + public function docs(): void { $this->_run(['vendor/bin/phpdox']); } @@ -112,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) { @@ -129,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__; @@ -149,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 = [ @@ -182,7 +205,7 @@ class RoboFile extends \Robo\Tasks { /** * Create temporary directories */ - public function prepare() + public function prepare(): void { array_map([$this, '_mkdir'], $this->taskDirs); } @@ -190,7 +213,7 @@ class RoboFile extends \Robo\Tasks { /** * Lint php files and run unit tests */ - public function test() + public function test(): void { $this->lint(); $this->taskPhpUnit() @@ -202,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() { @@ -217,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'), @@ -256,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) @@ -273,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', @@ -290,7 +298,7 @@ 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(); } diff --git a/build/header_comment.txt b/build/header_comment.txt index 3a6f96c..17cd15c 100644 --- a/build/header_comment.txt +++ b/build/header_comment.txt @@ -3,7 +3,7 @@ * * SQL Query Builder / Database Abstraction Layer * - * PHP version 7.2 + * PHP version 7.3 * * @package Query * @author Timothy J. Warren diff --git a/build/phpunit.xml b/build/phpunit.xml index 4215c21..97f3bb2 100644 --- a/build/phpunit.xml +++ b/build/phpunit.xml @@ -1,8 +1,11 @@ + bootstrap="./../tests/bootstrap.php" + verbose="true" +> ./../src/ diff --git a/composer.json b/composer.json index fe41c92..b68e73b 100644 --- a/composer.json +++ b/composer.json @@ -1,60 +1,71 @@ { - "name":"aviat/query", - "type":"library", - "description":"Database Query Builder and Abstraction layer", - "keywords":[ - "database", - "query builder", - "codeigniter", - "mysql", - "sqlite", - "postgres", - "pdo" - ], - "homepage":"https://git.timshomepage.net/aviat/Query", - "license":"MIT", - "authors": [{ - "name": "Timothy J. Warren", - "email": "tim@timshomepage.net", - "homepage": "https://timshomepage.net", - "role": "Developer" - }], - "require": { - "php": "^7.2", - "ext-pdo": "*" - }, - "require-dev": { - "consolidation/robo": "^2.0.0", - "monolog/monolog": "^2.0.1", - "pdepend/pdepend": "^2.5", - "phploc/phploc": "^5.0", - "phpstan/phpstan": "^0.12.2", - "phpunit/phpunit": "^8.5", - "sebastian/phpcpd": "^4.1", - "simpletest/simpletest": "^1.1", - "squizlabs/php_codesniffer": "^3.0.0", - "theseer/phpdox": "^0.12.0" - }, - "autoload": { - "psr-4": { - "Query\\": "src" - }, - "files": ["src/common.php"] - }, - "autoload-dev": { - "psr-4": { - "Query\\Tests\\": "tests" - } - }, - "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" - }, - "scripts-descriptions": { - "coverage": "Generate test coverage report", - "test": "Run unit tests" + "name": "aviat/query", + "type": "library", + "description": "Database Query Builder and Abstraction layer", + "keywords": [ + "database", + "query builder", + "codeigniter", + "mysql", + "sqlite", + "postgres", + "pdo" + ], + "homepage": "https://git.timshomepage.net/aviat/Query", + "license": "MIT", + "authors": [ + { + "name": "Timothy J. Warren", + "email": "tim@timshomepage.net", + "homepage": "https://timshomepage.net", + "role": "Developer" } + ], + "config": { + "lock": false, + "platform": { + "php": "7.3" + } + }, + "require": { + "php": ">=7.3", + "ext-pdo": "*" + }, + "require-dev": { + "consolidation/robo": "^2.0.0", + "monolog/monolog": "^2.0.1", + "phploc/phploc": "^5.0", + "phpmd/phpmd": "^2.8", + "phpstan/phpstan": "^0.12.2", + "phpunit/phpunit": "^8.5", + "sebastian/phpcpd": "^4.1", + "simpletest/simpletest": "^1.1", + "squizlabs/php_codesniffer": "^3.0.0", + "theseer/phpdox": "*" + }, + "autoload": { + "psr-4": { + "Query\\": "src" + }, + "files": [ + "src/common.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Query\\Tests\\": "tests" + } + }, + "scripts": { + "build": "robo build", + "clean": "robo clean", + "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build", + "pcov": "vendor/bin/phpunit -c build", + "phpstan": "phpstan analyse -l 3 -c phpstan.neon src tests", + "test": "phpunit -c build --no-coverage" + }, + "scripts-descriptions": { + "coverage": "Generate test coverage report", + "test": "Run unit tests" + } } diff --git a/phpdox.xml b/phpdox.xml index c90e130..d23f39e 100644 --- a/phpdox.xml +++ b/phpdox.xml @@ -78,24 +78,20 @@ - + - -