From e20c729c9493f9f563d8c687348b37e498214923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Wed, 27 May 2020 10:38:42 +0200 Subject: [PATCH 1/5] preparing php7 upgrade --- .gitignore | 1 + composer.json | 14 +++++++++----- tests/Builder/GenericBuilderTest.php | 5 +++-- tests/Builder/MySqlBuilderTest.php | 7 ++++--- tests/Builder/Syntax/ColumnWriterTest.php | 5 +++-- tests/Builder/Syntax/DeleteWriterTest.php | 5 +++-- tests/Builder/Syntax/InsertWriterTest.php | 7 ++++--- tests/Builder/Syntax/IntersectWriterTest.php | 7 ++++--- tests/Builder/Syntax/MinusWriterTest.php | 7 ++++--- tests/Builder/Syntax/PlaceholderWriterTest.php | 5 +++-- tests/Builder/Syntax/SelectWriterTest.php | 9 +++++---- tests/Builder/Syntax/UnionAllWriterTest.php | 7 ++++--- tests/Builder/Syntax/UnionWriterTest.php | 7 ++++--- tests/Builder/Syntax/UpdateWriterTest.php | 7 ++++--- tests/Builder/Syntax/WhereWriterTest.php | 5 +++-- tests/Builder/Syntax/WriterFactoryTest.php | 5 +++-- tests/Manipulation/BaseQueryTest.php | 7 ++++--- tests/Manipulation/DeleteTest.php | 5 +++-- tests/Manipulation/InsertTest.php | 5 +++-- tests/Manipulation/IntersectTest.php | 11 ++++++----- tests/Manipulation/MinusTest.php | 11 ++++++----- tests/Manipulation/QueryFactoryTest.php | 3 ++- tests/Manipulation/SelectTest.php | 5 +++-- tests/Manipulation/UnionAllTest.php | 11 ++++++----- tests/Manipulation/UnionTest.php | 11 ++++++----- tests/Manipulation/UpdateTest.php | 5 +++-- tests/Syntax/ColumnTest.php | 5 +++-- tests/Syntax/OrderByTest.php | 5 +++-- tests/Syntax/TableTest.php | 3 ++- tests/Syntax/WhereTest.php | 7 ++++--- 30 files changed, 115 insertions(+), 82 deletions(-) diff --git a/.gitignore b/.gitignore index 16730ad..9de2a4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea build/ vendor/ bin/ diff --git a/composer.json b/composer.json index 81134b0..c527535 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,9 @@ "role":"Contributor" } ], + "scripts": { + "test": "php vendor/pestphp/pest/bin/pest" + }, "autoload":{ "psr-4":{ "NilPortugues\\Sql\\QueryBuilder\\":"src/" @@ -32,19 +35,20 @@ }, "require": { - "php": ">=5.5", + "php": ">=7", "nilportugues/sql-query-formatter": "~1.2" }, "require-dev": { - "phpunit/phpunit": "4.*", - "fabpot/php-cs-fixer": "~1.9", - "nilportugues/php_backslasher": "~0.2" + "phpunit/phpunit": "^9.0", + "friendsofphp/php-cs-fixer": "^2.16", + "pestphp/pest": "^0.1.5" }, "config": { "bin-dir": "bin" }, - "minimum-stability": "stable", + "minimum-stability": "dev", + "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "1.0.x-dev" diff --git a/tests/Builder/GenericBuilderTest.php b/tests/Builder/GenericBuilderTest.php index 86eafd2..5b38fba 100644 --- a/tests/Builder/GenericBuilderTest.php +++ b/tests/Builder/GenericBuilderTest.php @@ -12,8 +12,9 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; -class GenericBuilderTest extends \PHPUnit_Framework_TestCase +class GenericBuilderTest extends TestCase { /** * @var GenericBuilder @@ -23,7 +24,7 @@ class GenericBuilderTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); } diff --git a/tests/Builder/MySqlBuilderTest.php b/tests/Builder/MySqlBuilderTest.php index da9288f..7c8d8ac 100644 --- a/tests/Builder/MySqlBuilderTest.php +++ b/tests/Builder/MySqlBuilderTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\MySqlBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class MySqlBuilderTest. */ -class MySqlBuilderTest extends \PHPUnit_Framework_TestCase +class MySqlBuilderTest extends TestCase { /** * @var MySqlBuilder @@ -26,7 +27,7 @@ class MySqlBuilderTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new MySqlBuilder(); } @@ -34,7 +35,7 @@ protected function setUp() /** * */ - protected function tearDown() + protected function tearDown(): void { $this->writer = null; } diff --git a/tests/Builder/Syntax/ColumnWriterTest.php b/tests/Builder/Syntax/ColumnWriterTest.php index a8eb8e9..77a1907 100644 --- a/tests/Builder/Syntax/ColumnWriterTest.php +++ b/tests/Builder/Syntax/ColumnWriterTest.php @@ -15,11 +15,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; use NilPortugues\Sql\QueryBuilder\Syntax\Column; +use PHPUnit\Framework\TestCase; /** * Class ColumnWriterTest. */ -class ColumnWriterTest extends \PHPUnit_Framework_TestCase +class ColumnWriterTest extends TestCase { /** * @var ColumnWriter @@ -39,7 +40,7 @@ class ColumnWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Select(); diff --git a/tests/Builder/Syntax/DeleteWriterTest.php b/tests/Builder/Syntax/DeleteWriterTest.php index 3ecfec0..b96ef11 100644 --- a/tests/Builder/Syntax/DeleteWriterTest.php +++ b/tests/Builder/Syntax/DeleteWriterTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Delete; +use PHPUnit\Framework\TestCase; /** * Class DeleteWriterTest. */ -class DeleteWriterTest extends \PHPUnit_Framework_TestCase +class DeleteWriterTest extends TestCase { /** * @var GenericBuilder @@ -31,7 +32,7 @@ class DeleteWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Delete(); diff --git a/tests/Builder/Syntax/InsertWriterTest.php b/tests/Builder/Syntax/InsertWriterTest.php index ea41333..d3c5756 100644 --- a/tests/Builder/Syntax/InsertWriterTest.php +++ b/tests/Builder/Syntax/InsertWriterTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Insert; +use PHPUnit\Framework\TestCase; /** * Class InsertWriterTest. */ -class InsertWriterTest extends \PHPUnit_Framework_TestCase +class InsertWriterTest extends TestCase { /** * @var GenericBuilder @@ -36,7 +37,7 @@ class InsertWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Insert(); @@ -47,7 +48,7 @@ protected function setUp() */ public function itShouldThrowQueryExceptionBecauseNoColumnsWereDefined() { - $this->setExpectedException($this->exceptionClass, 'No columns were defined for the current schema.'); + $this->expectException($this->exceptionClass, 'No columns were defined for the current schema.'); $this->query->setTable('user'); $this->writer->write($this->query); diff --git a/tests/Builder/Syntax/IntersectWriterTest.php b/tests/Builder/Syntax/IntersectWriterTest.php index cb1aef2..dc154a0 100644 --- a/tests/Builder/Syntax/IntersectWriterTest.php +++ b/tests/Builder/Syntax/IntersectWriterTest.php @@ -13,11 +13,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\Syntax\IntersectWriter; use NilPortugues\Sql\QueryBuilder\Manipulation\Intersect; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class IntersectWriterTest. */ -class IntersectWriterTest extends \PHPUnit_Framework_TestCase +class IntersectWriterTest extends TestCase { /** * @var GenericBuilder @@ -32,13 +33,13 @@ class IntersectWriterTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->intersectWriter = new IntersectWriter(new GenericBuilder()); $this->writer = new GenericBuilder(); } - public function tearDown() + public function tearDown(): void { $this->intersectWriter = null; $this->writer = null; diff --git a/tests/Builder/Syntax/MinusWriterTest.php b/tests/Builder/Syntax/MinusWriterTest.php index 32bee93..b0e78c6 100644 --- a/tests/Builder/Syntax/MinusWriterTest.php +++ b/tests/Builder/Syntax/MinusWriterTest.php @@ -14,11 +14,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\Syntax\MinusWriter; use NilPortugues\Sql\QueryBuilder\Manipulation\Minus; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class MinusWriterTest. */ -class MinusWriterTest extends \PHPUnit_Framework_TestCase +class MinusWriterTest extends TestCase { /** * @var MinusWriter @@ -33,13 +34,13 @@ class MinusWriterTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->minusWriter = new MinusWriter(new GenericBuilder()); $this->writer = new GenericBuilder(); } - public function tearDown() + public function tearDown(): void { $this->minusWriter = null; $this->writer = null; diff --git a/tests/Builder/Syntax/PlaceholderWriterTest.php b/tests/Builder/Syntax/PlaceholderWriterTest.php index f9d6a6d..4bcd873 100644 --- a/tests/Builder/Syntax/PlaceholderWriterTest.php +++ b/tests/Builder/Syntax/PlaceholderWriterTest.php @@ -11,11 +11,12 @@ namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax; use NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter; +use PHPUnit\Framework\TestCase; /** * Class PlaceholderWriterTest. */ -class PlaceholderWriterTest extends \PHPUnit_Framework_TestCase +class PlaceholderWriterTest extends TestCase { /** * @var PlaceholderWriter @@ -25,7 +26,7 @@ class PlaceholderWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new PlaceholderWriter(); } diff --git a/tests/Builder/Syntax/SelectWriterTest.php b/tests/Builder/Syntax/SelectWriterTest.php index 834e065..b6bb83f 100644 --- a/tests/Builder/Syntax/SelectWriterTest.php +++ b/tests/Builder/Syntax/SelectWriterTest.php @@ -14,11 +14,12 @@ use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; +use PHPUnit\Framework\TestCase; /** * Class SelectWriterTest. */ -class SelectWriterTest extends \PHPUnit_Framework_TestCase +class SelectWriterTest extends TestCase { /** * @var GenericBuilder @@ -38,7 +39,7 @@ class SelectWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Select(); @@ -89,7 +90,7 @@ public function itShouldBeAbleToWriteCommentInQuery() */ public function itShouldThrowExceptionWhenGettingColumnsButNoTableIsSet() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query = new Select(); $this->query->getColumns(); @@ -537,7 +538,7 @@ public function itShouldBeAbleToGroupByOperator() */ public function itShouldThrowExceptionInvalidHavingConjunction() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query ->setTable('user') diff --git a/tests/Builder/Syntax/UnionAllWriterTest.php b/tests/Builder/Syntax/UnionAllWriterTest.php index fbcd3ea..80c2e72 100644 --- a/tests/Builder/Syntax/UnionAllWriterTest.php +++ b/tests/Builder/Syntax/UnionAllWriterTest.php @@ -13,11 +13,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\Syntax\UnionAllWriter; use NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class UnionAllWriterTest. */ -class UnionAllWriterTest extends \PHPUnit_Framework_TestCase +class UnionAllWriterTest extends TestCase { /** * @var UnionAllWriter @@ -32,13 +33,13 @@ class UnionAllWriterTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->unionAllWriter = new UnionAllWriter(new GenericBuilder()); $this->writer = new GenericBuilder(); } - public function tearDown() + public function tearDown(): void { $this->unionAllWriter = null; $this->writer = null; diff --git a/tests/Builder/Syntax/UnionWriterTest.php b/tests/Builder/Syntax/UnionWriterTest.php index 6d6c2d3..c04f558 100644 --- a/tests/Builder/Syntax/UnionWriterTest.php +++ b/tests/Builder/Syntax/UnionWriterTest.php @@ -13,11 +13,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\Syntax\UnionWriter; use NilPortugues\Sql\QueryBuilder\Manipulation\Union; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class UnionWriterTest. */ -class UnionWriterTest extends \PHPUnit_Framework_TestCase +class UnionWriterTest extends TestCase { /** * @var UnionWriter @@ -32,13 +33,13 @@ class UnionWriterTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->unionWriter = new UnionWriter(new GenericBuilder()); $this->writer = new GenericBuilder(); } - public function tearDown() + public function tearDown(): void { $this->unionWriter = null; $this->writer = null; diff --git a/tests/Builder/Syntax/UpdateWriterTest.php b/tests/Builder/Syntax/UpdateWriterTest.php index 9001ec2..91c79fe 100644 --- a/tests/Builder/Syntax/UpdateWriterTest.php +++ b/tests/Builder/Syntax/UpdateWriterTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Update; +use PHPUnit\Framework\TestCase; /** * Class UpdateWriterTest. */ -class UpdateWriterTest extends \PHPUnit_Framework_TestCase +class UpdateWriterTest extends TestCase { /** * @var array @@ -41,7 +42,7 @@ class UpdateWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Update(); @@ -58,7 +59,7 @@ protected function setUp() */ public function itShouldThrowQueryException() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->setTable('user'); $this->writer->write($this->query); diff --git a/tests/Builder/Syntax/WhereWriterTest.php b/tests/Builder/Syntax/WhereWriterTest.php index da4f70f..1a0dd8e 100644 --- a/tests/Builder/Syntax/WhereWriterTest.php +++ b/tests/Builder/Syntax/WhereWriterTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class WhereWriterTest. */ -class WhereWriterTest extends \PHPUnit_Framework_TestCase +class WhereWriterTest extends TestCase { /** * @var GenericBuilder @@ -31,7 +32,7 @@ class WhereWriterTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->query = new Select(); diff --git a/tests/Builder/Syntax/WriterFactoryTest.php b/tests/Builder/Syntax/WriterFactoryTest.php index 11f88b3..792c9b6 100644 --- a/tests/Builder/Syntax/WriterFactoryTest.php +++ b/tests/Builder/Syntax/WriterFactoryTest.php @@ -13,11 +13,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter; use NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory; +use PHPUnit\Framework\TestCase; /** * Class WriterFactoryTest. */ -class WriterFactoryTest extends \PHPUnit_Framework_TestCase +class WriterFactoryTest extends TestCase { /** * @var PlaceholderWriter @@ -32,7 +33,7 @@ class WriterFactoryTest extends \PHPUnit_Framework_TestCase /** * */ - public function setUp() + protected function setUp(): void { $this->writer = new GenericBuilder(); $this->placeholder = new PlaceholderWriter(); diff --git a/tests/Manipulation/BaseQueryTest.php b/tests/Manipulation/BaseQueryTest.php index e8f0518..c59d319 100644 --- a/tests/Manipulation/BaseQueryTest.php +++ b/tests/Manipulation/BaseQueryTest.php @@ -9,11 +9,12 @@ */ namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation; +use PHPUnit\Framework\TestCase; /** * Class BaseQueryTest. */ -class BaseQueryTest extends \PHPUnit_Framework_TestCase +class BaseQueryTest extends TestCase { /** * @var \NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources\DummyQuery @@ -28,7 +29,7 @@ class BaseQueryTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Resources\DummyQuery(); $this->query->setTable('tablename'); @@ -37,7 +38,7 @@ protected function setUp() /** * */ - protected function tearDown() + protected function tearDown(): void { $this->query = null; } diff --git a/tests/Manipulation/DeleteTest.php b/tests/Manipulation/DeleteTest.php index 5673c10..00c5960 100644 --- a/tests/Manipulation/DeleteTest.php +++ b/tests/Manipulation/DeleteTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; use NilPortugues\Sql\QueryBuilder\Manipulation\Delete; +use PHPUnit\Framework\TestCase; /** * Class DeleteTest. */ -class DeleteTest extends \PHPUnit_Framework_TestCase +class DeleteTest extends TestCase { /** * @var GenericBuilder @@ -31,7 +32,7 @@ class DeleteTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Delete(); } diff --git a/tests/Manipulation/InsertTest.php b/tests/Manipulation/InsertTest.php index f1c6eba..c7d3413 100644 --- a/tests/Manipulation/InsertTest.php +++ b/tests/Manipulation/InsertTest.php @@ -11,11 +11,12 @@ namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation; use NilPortugues\Sql\QueryBuilder\Manipulation\Insert; +use PHPUnit\Framework\TestCase; /** * Class InsertTest. */ -class InsertTest extends \PHPUnit_Framework_TestCase +class InsertTest extends TestCase { /** * @var Insert @@ -24,7 +25,7 @@ class InsertTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Insert(); } diff --git a/tests/Manipulation/IntersectTest.php b/tests/Manipulation/IntersectTest.php index 0b01f2e..0575cfd 100644 --- a/tests/Manipulation/IntersectTest.php +++ b/tests/Manipulation/IntersectTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\Intersect; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class IntersectTest. */ -class IntersectTest extends \PHPUnit_Framework_TestCase +class IntersectTest extends TestCase { /** * @var Intersect @@ -31,7 +32,7 @@ class IntersectTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Intersect(); } @@ -49,7 +50,7 @@ public function itShouldGetPartName() */ public function itShouldThrowExceptionForUnsupportedGetTable() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getTable(); } @@ -58,7 +59,7 @@ public function itShouldThrowExceptionForUnsupportedGetTable() */ public function itShouldThrowExceptionForUnsupportedGetWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getWhere(); } @@ -67,7 +68,7 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() */ public function itShouldThrowExceptionForUnsupportedWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->where(); } diff --git a/tests/Manipulation/MinusTest.php b/tests/Manipulation/MinusTest.php index 0ebe1f9..afaee63 100644 --- a/tests/Manipulation/MinusTest.php +++ b/tests/Manipulation/MinusTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\Minus; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class MinusTest. */ -class MinusTest extends \PHPUnit_Framework_TestCase +class MinusTest extends TestCase { /** * @var Minus @@ -31,7 +32,7 @@ class MinusTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Minus(new Select('user'), new Select('user_email')); } @@ -49,7 +50,7 @@ public function itShouldGetPartName() */ public function itShouldThrowExceptionForUnsupportedGetTable() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getTable(); } @@ -58,7 +59,7 @@ public function itShouldThrowExceptionForUnsupportedGetTable() */ public function itShouldThrowExceptionForUnsupportedGetWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getWhere(); } @@ -67,7 +68,7 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() */ public function itShouldThrowExceptionForUnsupportedWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->where(); } diff --git a/tests/Manipulation/QueryFactoryTest.php b/tests/Manipulation/QueryFactoryTest.php index 0bd6829..549d482 100644 --- a/tests/Manipulation/QueryFactoryTest.php +++ b/tests/Manipulation/QueryFactoryTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\QueryFactory; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class QueryFactoryTest. */ -class QueryFactoryTest extends \PHPUnit_Framework_TestCase +class QueryFactoryTest extends TestCase { /** * @test diff --git a/tests/Manipulation/SelectTest.php b/tests/Manipulation/SelectTest.php index fe445b9..4a69e28 100644 --- a/tests/Manipulation/SelectTest.php +++ b/tests/Manipulation/SelectTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\Select; use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; +use PHPUnit\Framework\TestCase; /** * Class SelectTest. */ -class SelectTest extends \PHPUnit_Framework_TestCase +class SelectTest extends TestCase { /** * @var Select @@ -25,7 +26,7 @@ class SelectTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Select(); } diff --git a/tests/Manipulation/UnionAllTest.php b/tests/Manipulation/UnionAllTest.php index 869eef8..293201a 100644 --- a/tests/Manipulation/UnionAllTest.php +++ b/tests/Manipulation/UnionAllTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class UnionAllTest. */ -class UnionAllTest extends \PHPUnit_Framework_TestCase +class UnionAllTest extends TestCase { /** * @var UnionAll @@ -31,7 +32,7 @@ class UnionAllTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new UnionAll(); } @@ -49,7 +50,7 @@ public function itShouldGetPartName() */ public function itShouldThrowExceptionForUnsupportedGetTable() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getTable(); } @@ -58,7 +59,7 @@ public function itShouldThrowExceptionForUnsupportedGetTable() */ public function itShouldThrowExceptionForUnsupportedGetWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getWhere(); } @@ -67,7 +68,7 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() */ public function itShouldThrowExceptionForUnsupportedWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->where(); } diff --git a/tests/Manipulation/UnionTest.php b/tests/Manipulation/UnionTest.php index f5c394e..53b950b 100644 --- a/tests/Manipulation/UnionTest.php +++ b/tests/Manipulation/UnionTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\Union; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; +use PHPUnit\Framework\TestCase; /** * Class UnionTest. */ -class UnionTest extends \PHPUnit_Framework_TestCase +class UnionTest extends TestCase { /** * @var Union @@ -31,7 +32,7 @@ class UnionTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Union(); } @@ -49,7 +50,7 @@ public function itShouldGetPartName() */ public function itShouldThrowExceptionForUnsupportedGetTable() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getTable(); } @@ -58,7 +59,7 @@ public function itShouldThrowExceptionForUnsupportedGetTable() */ public function itShouldThrowExceptionForUnsupportedGetWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->getWhere(); } @@ -67,7 +68,7 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() */ public function itShouldThrowExceptionForUnsupportedWhere() { - $this->setExpectedException($this->exceptionClass); + $this->expectException($this->exceptionClass); $this->query->where(); } diff --git a/tests/Manipulation/UpdateTest.php b/tests/Manipulation/UpdateTest.php index e417c1c..6be34b2 100644 --- a/tests/Manipulation/UpdateTest.php +++ b/tests/Manipulation/UpdateTest.php @@ -11,11 +11,12 @@ namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation; use NilPortugues\Sql\QueryBuilder\Manipulation\Update; +use PHPUnit\Framework\TestCase; /** * Class UpdateTest. */ -class UpdateTest extends \PHPUnit_Framework_TestCase +class UpdateTest extends TestCase { /** * @var Update @@ -24,7 +25,7 @@ class UpdateTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $this->query = new Update(); } diff --git a/tests/Syntax/ColumnTest.php b/tests/Syntax/ColumnTest.php index 3794ca2..f50b4cb 100644 --- a/tests/Syntax/ColumnTest.php +++ b/tests/Syntax/ColumnTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Syntax\Column; use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use PHPUnit\Framework\TestCase; /** * Class ColumnTest. */ -class ColumnTest extends \PHPUnit_Framework_TestCase +class ColumnTest extends TestCase { /** * @var string @@ -89,7 +90,7 @@ public function itShouldSetAliasName() */ public function itShouldThrowExceptionIfAliasOnAllSelection() { - $this->setExpectedException($this->queryException); + $this->expectException($this->queryException); new Column('*', 'user', 'userId'); } diff --git a/tests/Syntax/OrderByTest.php b/tests/Syntax/OrderByTest.php index a529359..ae214b4 100644 --- a/tests/Syntax/OrderByTest.php +++ b/tests/Syntax/OrderByTest.php @@ -12,11 +12,12 @@ use NilPortugues\Sql\QueryBuilder\Syntax\Column; use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; +use PHPUnit\Framework\TestCase; /** * Class OrderByTest. */ -class OrderByTest extends \PHPUnit_Framework_TestCase +class OrderByTest extends TestCase { /** * @var string @@ -57,7 +58,7 @@ public function itShouldThrowExceptionIfDirectionNotValid() $column = new Column('registration_date', 'user'); $order = new OrderBy($column, OrderBy::ASC); - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException('\InvalidArgumentException'); $order->setDirection('this is not a valid direction'); } } diff --git a/tests/Syntax/TableTest.php b/tests/Syntax/TableTest.php index 6810e97..5897a44 100644 --- a/tests/Syntax/TableTest.php +++ b/tests/Syntax/TableTest.php @@ -11,11 +11,12 @@ namespace NilPortugues\Tests\Sql\QueryBuilder\Syntax; use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use PHPUnit\Framework\TestCase; /** * Class TableTest. */ -class TableTest extends \PHPUnit_Framework_TestCase +class TableTest extends TestCase { /** * @test diff --git a/tests/Syntax/WhereTest.php b/tests/Syntax/WhereTest.php index c045875..2a30e40 100644 --- a/tests/Syntax/WhereTest.php +++ b/tests/Syntax/WhereTest.php @@ -13,11 +13,12 @@ use NilPortugues\Sql\QueryBuilder\Manipulation\Select; use NilPortugues\Sql\QueryBuilder\Syntax\Where; use NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources\DummyQuery; +use PHPUnit\Framework\TestCase; /** * Class WhereTest. */ -class WhereTest extends \PHPUnit_Framework_TestCase +class WhereTest extends TestCase { /** * @var Where @@ -42,7 +43,7 @@ class WhereTest extends \PHPUnit_Framework_TestCase /** * */ - protected function setUp() + protected function setUp(): void { $query = new DummyQuery(); $query->setTable('users'); @@ -378,7 +379,7 @@ public function ItShouldChangeAndToOrOperator() */ public function itShouldThrowExceptionOnUnknownConjunction() { - $this->setExpectedException($this->queryException); + $this->expectException($this->queryException); $this->where->conjunction('NOT_VALID_CONJUNCTION'); } From b6ab18c844ff1d9be69eef86303fa28e35794c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Wed, 27 May 2020 10:52:29 +0200 Subject: [PATCH 2/5] Basic update to php 7.4 code --- composer.json | 6 ++-- rector.yaml | 25 +++++++++++++++ src/Builder/BuilderException.php | 3 +- src/Builder/GenericBuilder.php | 32 ++++++++++++------- src/Builder/Syntax/ColumnWriter.php | 25 ++++++--------- src/Builder/Syntax/PlaceholderWriter.php | 3 +- src/Builder/Syntax/WhereWriter.php | 12 ++++--- src/Manipulation/AbstractBaseQuery.php | 8 +++-- src/Manipulation/AbstractSetQuery.php | 8 +++-- src/Manipulation/ColumnQuery.php | 5 +-- src/Manipulation/Intersect.php | 16 ++++------ src/Manipulation/Minus.php | 22 +++++-------- src/Manipulation/QueryException.php | 3 +- src/Manipulation/QueryInterface.php | 8 +++-- src/Manipulation/Select.php | 3 +- src/Manipulation/Union.php | 2 +- src/Manipulation/UnionAll.php | 4 +-- src/Syntax/OrderBy.php | 5 +-- src/Syntax/Where.php | 16 +++++----- tests/Builder/GenericBuilderTest.php | 3 -- tests/Builder/MySqlBuilderTest.php | 6 ---- tests/Builder/Syntax/ColumnWriterTest.php | 3 -- tests/Builder/Syntax/DeleteWriterTest.php | 3 -- tests/Builder/Syntax/InsertWriterTest.php | 3 -- tests/Builder/Syntax/IntersectWriterTest.php | 3 -- tests/Builder/Syntax/MinusWriterTest.php | 3 -- .../Builder/Syntax/PlaceholderWriterTest.php | 3 -- tests/Builder/Syntax/SelectWriterTest.php | 3 -- tests/Builder/Syntax/UnionAllWriterTest.php | 3 -- tests/Builder/Syntax/UnionWriterTest.php | 3 -- tests/Builder/Syntax/UpdateWriterTest.php | 3 -- tests/Builder/Syntax/WhereWriterTest.php | 3 -- tests/Builder/Syntax/WriterFactoryTest.php | 3 -- tests/Manipulation/BaseQueryTest.php | 11 ++----- tests/Manipulation/DeleteTest.php | 11 ------- tests/Manipulation/InsertTest.php | 3 -- tests/Manipulation/IntersectTest.php | 3 -- tests/Manipulation/MinusTest.php | 3 -- tests/Manipulation/SelectTest.php | 3 -- tests/Manipulation/UnionAllTest.php | 3 -- tests/Manipulation/UnionTest.php | 3 -- tests/Manipulation/UpdateTest.php | 3 -- tests/Syntax/WhereTest.php | 3 -- 43 files changed, 123 insertions(+), 174 deletions(-) create mode 100644 rector.yaml diff --git a/composer.json b/composer.json index c527535..57ea2cd 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ } ], "scripts": { - "test": "php vendor/pestphp/pest/bin/pest" + "test": "php vendor/pestphp/pest/bin/pest", + "rector": "php vendor/rector/rector/bin/rector" }, "autoload":{ "psr-4":{ @@ -41,7 +42,8 @@ "require-dev": { "phpunit/phpunit": "^9.0", "friendsofphp/php-cs-fixer": "^2.16", - "pestphp/pest": "^0.1.5" + "pestphp/pest": "^0.1.5", + "rector/rector": "^0.7.26" }, "config": { diff --git a/rector.yaml b/rector.yaml new file mode 100644 index 0000000..db3e63a --- /dev/null +++ b/rector.yaml @@ -0,0 +1,25 @@ +imports: + - { resource: "create-rector.yaml", ignore_errors: 'not_found' } + +parameters: + # bleeding edge feature + # is_cache_enabled: true + + auto_import_names: true + + sets: + # - solid + - 'dead-code' + + paths: + - src + - tests + + exclude_paths: + - "/vendor/" + + php_version_features: '7.4' + +services: + Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateConstantRector: null + Rector\SOLID\Rector\Class_\RepeatedLiteralToClassConstantRector: null diff --git a/src/Builder/BuilderException.php b/src/Builder/BuilderException.php index c65caaa..3846aaf 100644 --- a/src/Builder/BuilderException.php +++ b/src/Builder/BuilderException.php @@ -10,9 +10,10 @@ namespace NilPortugues\Sql\QueryBuilder\Builder; +use Exception; /** * Class BuilderException. */ -final class BuilderException extends \Exception +final class BuilderException extends Exception { } diff --git a/src/Builder/GenericBuilder.php b/src/Builder/GenericBuilder.php index f31df44..e7b741a 100644 --- a/src/Builder/GenericBuilder.php +++ b/src/Builder/GenericBuilder.php @@ -10,6 +10,16 @@ namespace NilPortugues\Sql\QueryBuilder\Builder; +use NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter; +use NilPortugues\Sql\QueryBuilder\Builder\Syntax\WhereWriter; +use NilPortugues\Sql\QueryFormatter\Formatter; +use NilPortugues\Sql\QueryBuilder\Manipulation\Delete; +use NilPortugues\Sql\QueryBuilder\Manipulation\Intersect; +use NilPortugues\Sql\QueryBuilder\Manipulation\Union; +use NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll; +use NilPortugues\Sql\QueryBuilder\Manipulation\Minus; +use ReflectionClass; +use RuntimeException; use NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory; use NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery; use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface; @@ -26,21 +36,21 @@ class GenericBuilder implements BuilderInterface /** * The placeholder parameter bag. * - * @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\PlaceholderWriter + * @var PlaceholderWriter */ protected $placeholderWriter; /** * The Where writer. * - * @var \NilPortugues\Sql\QueryBuilder\Builder\Syntax\WhereWriter + * @var WhereWriter */ protected $whereWriter; /** * The SQL formatter. * - * @var \NilPortugues\Sql\QueryFormatter\Formatter + * @var Formatter */ protected $sqlFormatter; @@ -139,7 +149,7 @@ public function update($table = null, array $values = null) /** * @param string $table * - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Delete + * @return Delete */ public function delete($table = null) { @@ -147,7 +157,7 @@ public function delete($table = null) } /** - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Intersect + * @return Intersect */ public function intersect() { @@ -155,7 +165,7 @@ public function intersect() } /** - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Union + * @return Union */ public function union() { @@ -163,7 +173,7 @@ public function union() } /** - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\UnionAll + * @return UnionAll */ public function unionAll() { @@ -174,7 +184,7 @@ public function unionAll() * @param \NilPortugues\Sql\QueryBuilder\Manipulation\Select $first * @param \NilPortugues\Sql\QueryBuilder\Manipulation\Select $second * - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Minus + * @return Minus */ public function minus(Select $first, Select $second) { @@ -199,7 +209,7 @@ public function getValues() public function writeFormatted(QueryInterface $query) { if (null === $this->sqlFormatter) { - $this->sqlFormatter = (new \ReflectionClass($this->sqlFormatterClass))->newInstance(); + $this->sqlFormatter = (new ReflectionClass($this->sqlFormatterClass))->newInstance(); } return $this->sqlFormatter->format($this->write($query)); @@ -211,7 +221,7 @@ public function writeFormatted(QueryInterface $query) * * @return string * - * @throws \RuntimeException + * @throws RuntimeException */ public function write(QueryInterface $query, $resetPlaceholders = true) { @@ -227,7 +237,7 @@ public function write(QueryInterface $query, $resetPlaceholders = true) return $this->queryWriterInstances[$queryPart]->write($query); } - throw new \RuntimeException('Query builder part not defined.'); + throw new RuntimeException('Query builder part not defined.'); } /** diff --git a/src/Builder/Syntax/ColumnWriter.php b/src/Builder/Syntax/ColumnWriter.php index 999db08..16bf052 100644 --- a/src/Builder/Syntax/ColumnWriter.php +++ b/src/Builder/Syntax/ColumnWriter.php @@ -95,13 +95,11 @@ public function writeValueAsColumns(Select $select) $valueAsColumns = $select->getColumnValues(); $newColumns = []; - if (!empty($valueAsColumns)) { - foreach ($valueAsColumns as $alias => $value) { - $value = $this->writer->writePlaceholderValue($value); - $newValueColumn = array($alias => $value); + foreach ($valueAsColumns as $alias => $value) { + $value = $this->writer->writePlaceholderValue($value); + $newValueColumn = array($alias => $value); - $newColumns[] = SyntaxFactory::createColumn($newValueColumn, null); - } + $newColumns[] = SyntaxFactory::createColumn($newValueColumn, null); } return $newColumns; @@ -117,14 +115,12 @@ public function writeFuncAsColumns(Select $select) $funcAsColumns = $select->getColumnFuncs(); $newColumns = []; - if (!empty($funcAsColumns)) { - foreach ($funcAsColumns as $alias => $value) { - $funcName = $value['func']; - $funcArgs = (!empty($value['args'])) ? '('.implode(', ', $value['args']).')' : ''; + foreach ($funcAsColumns as $alias => $value) { + $funcName = $value['func']; + $funcArgs = (!empty($value['args'])) ? '('.implode(', ', $value['args']).')' : ''; - $newFuncColumn = array($alias => $funcName.$funcArgs); - $newColumns[] = SyntaxFactory::createColumn($newFuncColumn, null); - } + $newFuncColumn = array($alias => $funcName.$funcArgs); + $newColumns[] = SyntaxFactory::createColumn($newFuncColumn, null); } return $newColumns; @@ -155,8 +151,7 @@ public function writeColumn(Column $column) $table = ($alias) ? $this->writer->writeTableAlias($alias) : $this->writer->writeTable($column->getTable()); $columnString = (empty($table)) ? '' : "{$table}."; - $columnString .= $this->writer->writeColumnName($column); - return $columnString; + return $columnString . $this->writer->writeColumnName($column); } } diff --git a/src/Builder/Syntax/PlaceholderWriter.php b/src/Builder/Syntax/PlaceholderWriter.php index de78f09..9953652 100644 --- a/src/Builder/Syntax/PlaceholderWriter.php +++ b/src/Builder/Syntax/PlaceholderWriter.php @@ -68,9 +68,8 @@ protected function setValidSqlValue($value) { $value = $this->writeNullSqlString($value); $value = $this->writeStringAsSqlString($value); - $value = $this->writeBooleanSqlString($value); - return $value; + return $this->writeBooleanSqlString($value); } /** diff --git a/src/Builder/Syntax/WhereWriter.php b/src/Builder/Syntax/WhereWriter.php index aa2345a..baac1b9 100644 --- a/src/Builder/Syntax/WhereWriter.php +++ b/src/Builder/Syntax/WhereWriter.php @@ -12,6 +12,8 @@ */ class WhereWriter extends AbstractBaseWriter { + private const SUBJECT = 'subject'; + /** * @var array */ @@ -172,7 +174,7 @@ protected function writeWhereBetweens(Where $where, array &$whereArray) function (&$between) { $between = '(' - .$this->columnWriter->writeColumn($between['subject']) + .$this->columnWriter->writeColumn($between[self::SUBJECT]) .' BETWEEN ' .$this->writer->writePlaceholderValue($between['a']) .' AND ' @@ -198,7 +200,7 @@ protected function writeWhereNotBetweens(Where $where, array &$whereArray) function (&$between) { $between = '(' - .$this->columnWriter->writeColumn($between['subject']) + .$this->columnWriter->writeColumn($between[self::SUBJECT]) .' NOT BETWEEN ' .$this->writer->writePlaceholderValue($between['a']) .' AND ' @@ -227,7 +229,7 @@ function (&$comparison) { return; } - $str = $this->writeWherePartialCondition($comparison['subject']); + $str = $this->writeWherePartialCondition($comparison[self::SUBJECT]); $str .= $this->writer->writeConjunction($comparison['conjunction']); $str .= $this->writeWherePartialCondition($comparison['target']); @@ -286,7 +288,7 @@ protected function writeWhereIsNullable(Where $where, $getMethod, $writeMethod) $collection, function (&$collection) use ($writeMethod) { $collection = - '('.$this->columnWriter->writeColumn($collection['subject']) + '('.$this->columnWriter->writeColumn($collection[self::SUBJECT]) .$this->writer->$writeMethod().')'; } ); @@ -322,7 +324,7 @@ protected function writeWhereBooleans(Where $where, array &$whereArray) \array_walk( $booleans, function (&$boolean) use (&$placeholderWriter) { - $column = $this->columnWriter->writeColumn($boolean['subject']); + $column = $this->columnWriter->writeColumn($boolean[self::SUBJECT]); $value = $this->placeholderWriter->add($boolean['value']); $boolean = '(ISNULL('.$column.', 0) = '.$value.')'; diff --git a/src/Manipulation/AbstractBaseQuery.php b/src/Manipulation/AbstractBaseQuery.php index a9845a2..5bc3a78 100644 --- a/src/Manipulation/AbstractBaseQuery.php +++ b/src/Manipulation/AbstractBaseQuery.php @@ -10,6 +10,8 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use RuntimeException; +use Exception; use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; use NilPortugues\Sql\QueryBuilder\Syntax\QueryPartInterface; use NilPortugues\Sql\QueryBuilder\Syntax\SyntaxFactory; @@ -97,12 +99,12 @@ final public function setBuilder(BuilderInterface $builder) /** * @return BuilderInterface * - * @throws \RuntimeException when builder has not been injected + * @throws RuntimeException when builder has not been injected */ final public function getBuilder() { if (!$this->builder) { - throw new \RuntimeException('Query builder has not been injected with setBuilder'); + throw new RuntimeException('Query builder has not been injected with setBuilder'); } return $this->builder; @@ -117,7 +119,7 @@ public function __toString() { try { return $this->getSql(); - } catch (\Exception $e) { + } catch (Exception $e) { return \sprintf('[%s] %s', \get_class($e), $e->getMessage()); } } diff --git a/src/Manipulation/AbstractSetQuery.php b/src/Manipulation/AbstractSetQuery.php index bb4b18b..8e3ea48 100644 --- a/src/Manipulation/AbstractSetQuery.php +++ b/src/Manipulation/AbstractSetQuery.php @@ -10,6 +10,8 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use NilPortugues\Sql\QueryBuilder\Syntax\Where; use NilPortugues\Sql\QueryBuilder\Syntax\QueryPartInterface; /** @@ -45,7 +47,7 @@ public function getUnions() /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Table + * @return Table */ public function getTable() { @@ -57,7 +59,7 @@ public function getTable() /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function getWhere() { @@ -69,7 +71,7 @@ public function getWhere() /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function where() { diff --git a/src/Manipulation/ColumnQuery.php b/src/Manipulation/ColumnQuery.php index 8a1ff6d..43ad96e 100644 --- a/src/Manipulation/ColumnQuery.php +++ b/src/Manipulation/ColumnQuery.php @@ -10,6 +10,7 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Where; use NilPortugues\Sql\QueryBuilder\Syntax\Column; use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; use NilPortugues\Sql\QueryBuilder\Syntax\SyntaxFactory; @@ -87,7 +88,7 @@ public function limit($start, $count = 0) /** * @param string $whereOperator * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function where($whereOperator = 'AND') { @@ -233,7 +234,7 @@ public function getAllColumns() } /** - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Column + * @return Column * * @throws QueryException */ diff --git a/src/Manipulation/Intersect.php b/src/Manipulation/Intersect.php index 66b77bf..876d1e1 100644 --- a/src/Manipulation/Intersect.php +++ b/src/Manipulation/Intersect.php @@ -10,6 +10,8 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use NilPortugues\Sql\QueryBuilder\Syntax\Where; use NilPortugues\Sql\QueryBuilder\Syntax\QueryPartInterface; /** @@ -17,13 +19,12 @@ */ class Intersect implements QueryInterface, QueryPartInterface { - const INTERSECT = 'INTERSECT'; + const INTERSECT='INTERSECT'; /** * @var array */ protected $intersect = []; - /** * @return string */ @@ -31,7 +32,6 @@ public function partName() { return 'INTERSECT'; } - /** * @param Select $select * @@ -43,7 +43,6 @@ public function add(Select $select) return $this; } - /** * @return array */ @@ -51,31 +50,28 @@ public function getIntersects() { return $this->intersect; } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Table + * @return Table */ public function getTable() { throw new QueryException('INTERSECT does not support tables'); } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function getWhere() { throw new QueryException('INTERSECT does not support WHERE.'); } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function where() { diff --git a/src/Manipulation/Minus.php b/src/Manipulation/Minus.php index a551e11..361a5cc 100644 --- a/src/Manipulation/Minus.php +++ b/src/Manipulation/Minus.php @@ -10,6 +10,8 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use NilPortugues\Sql\QueryBuilder\Syntax\Where; use NilPortugues\Sql\QueryBuilder\Syntax\QueryPartInterface; /** @@ -17,18 +19,16 @@ */ class Minus implements QueryInterface, QueryPartInterface { - const MINUS = 'MINUS'; + const MINUS='MINUS'; /** * @var Select */ protected $first; - /** * @var Select */ protected $second; - /** * @return string */ @@ -36,7 +36,6 @@ public function partName() { return 'MINUS'; } - /*** * @param Select $first * @param Select $second @@ -46,47 +45,42 @@ public function __construct(Select $first, Select $second) $this->first = $first; $this->second = $second; } - /** - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Select + * @return Select */ public function getFirst() { return $this->first; } - /** - * @return \NilPortugues\Sql\QueryBuilder\Manipulation\Select + * @return Select */ public function getSecond() { return $this->second; } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Table + * @return Table */ public function getTable() { throw new QueryException('MINUS does not support tables'); } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function getWhere() { throw new QueryException('MINUS does not support WHERE.'); } - /** * @throws QueryException * - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function where() { diff --git a/src/Manipulation/QueryException.php b/src/Manipulation/QueryException.php index 657212a..13d4a9a 100644 --- a/src/Manipulation/QueryException.php +++ b/src/Manipulation/QueryException.php @@ -10,9 +10,10 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use Exception; /** * Class QueryException. */ -final class QueryException extends \Exception +final class QueryException extends Exception { } diff --git a/src/Manipulation/QueryInterface.php b/src/Manipulation/QueryInterface.php index 809d517..2f9118e 100644 --- a/src/Manipulation/QueryInterface.php +++ b/src/Manipulation/QueryInterface.php @@ -10,6 +10,8 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Table; +use NilPortugues\Sql\QueryBuilder\Syntax\Where; /** * Interface QueryInterface. */ @@ -21,17 +23,17 @@ interface QueryInterface public function partName(); /** - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Table + * @return Table */ public function getTable(); /** - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function getWhere(); /** - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where + * @return Where */ public function where(); } diff --git a/src/Manipulation/Select.php b/src/Manipulation/Select.php index 1580df4..d99006d 100644 --- a/src/Manipulation/Select.php +++ b/src/Manipulation/Select.php @@ -10,6 +10,7 @@ namespace NilPortugues\Sql\QueryBuilder\Manipulation; +use NilPortugues\Sql\QueryBuilder\Syntax\Column; use NilPortugues\Sql\QueryBuilder\Syntax\SyntaxFactory; use NilPortugues\Sql\QueryBuilder\Syntax\Table; use NilPortugues\Sql\QueryBuilder\Syntax\Where; @@ -237,7 +238,7 @@ public function getAllColumns() } /** - * @return \NilPortugues\Sql\QueryBuilder\Syntax\Column + * @return Column * * @throws QueryException */ diff --git a/src/Manipulation/Union.php b/src/Manipulation/Union.php index 1f9af8b..529ca17 100644 --- a/src/Manipulation/Union.php +++ b/src/Manipulation/Union.php @@ -22,6 +22,6 @@ class Union extends AbstractSetQuery */ public function partName() { - return 'UNION'; + return self::UNION; } } diff --git a/src/Manipulation/UnionAll.php b/src/Manipulation/UnionAll.php index c5360b0..be80ff3 100644 --- a/src/Manipulation/UnionAll.php +++ b/src/Manipulation/UnionAll.php @@ -15,13 +15,13 @@ */ class UnionAll extends AbstractSetQuery { - const UNION_ALL = 'UNION ALL'; + const UNION_ALL='UNION ALL'; /** * @return string */ public function partName() { - return 'UNION ALL'; + return self::UNION_ALL; } } diff --git a/src/Syntax/OrderBy.php b/src/Syntax/OrderBy.php index 35214b3..e82c038 100644 --- a/src/Syntax/OrderBy.php +++ b/src/Syntax/OrderBy.php @@ -10,6 +10,7 @@ namespace NilPortugues\Sql\QueryBuilder\Syntax; +use InvalidArgumentException; /** * Class OrderBy. */ @@ -74,14 +75,14 @@ public function getDirection() /** * @param string $direction * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return $this */ public function setDirection($direction) { if (!in_array($direction, array(self::ASC, self::DESC))) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( "Specified direction '$direction' is not allowed. Only ASC or DESC are allowed." ); } diff --git a/src/Syntax/Where.php b/src/Syntax/Where.php index 94d6e4d..fc7ed3a 100644 --- a/src/Syntax/Where.php +++ b/src/Syntax/Where.php @@ -20,6 +20,8 @@ */ class Where { + private const SUBJECT = 'subject'; + const OPERATOR_GREATER_THAN_OR_EQUAL = '>='; const OPERATOR_GREATER_THAN = '>'; const OPERATOR_LESS_THAN_OR_EQUAL = '<='; @@ -32,8 +34,6 @@ class Where const CONJUNCTION_AND_NOT = 'AND NOT'; const CONJUNCTION_OR = 'OR'; const CONJUNCTION_OR_NOT = 'OR NOT'; - const CONJUNCTION_EXISTS = 'EXISTS'; - const CONJUNCTION_NOT_EXISTS = 'NOT EXISTS'; /** * @var array @@ -262,7 +262,7 @@ protected function compare($column, $value, $operator) $column = $this->prepareColumn($column); $this->comparisons[] = [ - 'subject' => $column, + self::SUBJECT => $column, 'conjunction' => $operator, 'target' => $value, ]; @@ -464,7 +464,7 @@ public function notIn($column, array $values) public function between($column, $a, $b) { $column = $this->prepareColumn($column); - $this->betweens[] = ['subject' => $column, 'a' => $a, 'b' => $b]; + $this->betweens[] = [self::SUBJECT => $column, 'a' => $a, 'b' => $b]; return $this; } @@ -479,7 +479,7 @@ public function between($column, $a, $b) public function notBetween($column, $a, $b) { $column = $this->prepareColumn($column); - $this->notBetweens[] = ['subject' => $column, 'a' => $a, 'b' => $b]; + $this->notBetweens[] = [self::SUBJECT => $column, 'a' => $a, 'b' => $b]; return $this; } @@ -492,7 +492,7 @@ public function notBetween($column, $a, $b) public function isNull($column) { $column = $this->prepareColumn($column); - $this->isNull[] = ['subject' => $column]; + $this->isNull[] = [self::SUBJECT => $column]; return $this; } @@ -505,7 +505,7 @@ public function isNull($column) public function isNotNull($column) { $column = $this->prepareColumn($column); - $this->isNotNull[] = ['subject' => $column]; + $this->isNotNull[] = [self::SUBJECT => $column]; return $this; } @@ -519,7 +519,7 @@ public function isNotNull($column) public function addBitClause($column, $value) { $column = $this->prepareColumn($column); - $this->booleans[] = ['subject' => $column, 'value' => $value]; + $this->booleans[] = [self::SUBJECT => $column, 'value' => $value]; return $this; } diff --git a/tests/Builder/GenericBuilderTest.php b/tests/Builder/GenericBuilderTest.php index 5b38fba..8baf868 100644 --- a/tests/Builder/GenericBuilderTest.php +++ b/tests/Builder/GenericBuilderTest.php @@ -21,9 +21,6 @@ class GenericBuilderTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/MySqlBuilderTest.php b/tests/Builder/MySqlBuilderTest.php index 7c8d8ac..0d9f130 100644 --- a/tests/Builder/MySqlBuilderTest.php +++ b/tests/Builder/MySqlBuilderTest.php @@ -24,17 +24,11 @@ class MySqlBuilderTest extends TestCase */ protected $writer; - /** - * - */ protected function setUp(): void { $this->writer = new MySqlBuilder(); } - /** - * - */ protected function tearDown(): void { $this->writer = null; diff --git a/tests/Builder/Syntax/ColumnWriterTest.php b/tests/Builder/Syntax/ColumnWriterTest.php index 77a1907..9bc0cca 100644 --- a/tests/Builder/Syntax/ColumnWriterTest.php +++ b/tests/Builder/Syntax/ColumnWriterTest.php @@ -37,9 +37,6 @@ class ColumnWriterTest extends TestCase */ private $query; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/DeleteWriterTest.php b/tests/Builder/Syntax/DeleteWriterTest.php index b96ef11..1baad5f 100644 --- a/tests/Builder/Syntax/DeleteWriterTest.php +++ b/tests/Builder/Syntax/DeleteWriterTest.php @@ -29,9 +29,6 @@ class DeleteWriterTest extends TestCase */ private $query; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/InsertWriterTest.php b/tests/Builder/Syntax/InsertWriterTest.php index d3c5756..3a601ad 100644 --- a/tests/Builder/Syntax/InsertWriterTest.php +++ b/tests/Builder/Syntax/InsertWriterTest.php @@ -34,9 +34,6 @@ class InsertWriterTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/IntersectWriterTest.php b/tests/Builder/Syntax/IntersectWriterTest.php index dc154a0..fe7bdbb 100644 --- a/tests/Builder/Syntax/IntersectWriterTest.php +++ b/tests/Builder/Syntax/IntersectWriterTest.php @@ -30,9 +30,6 @@ class IntersectWriterTest extends TestCase */ private $intersectWriter; - /** - * - */ protected function setUp(): void { $this->intersectWriter = new IntersectWriter(new GenericBuilder()); diff --git a/tests/Builder/Syntax/MinusWriterTest.php b/tests/Builder/Syntax/MinusWriterTest.php index b0e78c6..354a49e 100644 --- a/tests/Builder/Syntax/MinusWriterTest.php +++ b/tests/Builder/Syntax/MinusWriterTest.php @@ -31,9 +31,6 @@ class MinusWriterTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->minusWriter = new MinusWriter(new GenericBuilder()); diff --git a/tests/Builder/Syntax/PlaceholderWriterTest.php b/tests/Builder/Syntax/PlaceholderWriterTest.php index 4bcd873..c21320d 100644 --- a/tests/Builder/Syntax/PlaceholderWriterTest.php +++ b/tests/Builder/Syntax/PlaceholderWriterTest.php @@ -23,9 +23,6 @@ class PlaceholderWriterTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->writer = new PlaceholderWriter(); diff --git a/tests/Builder/Syntax/SelectWriterTest.php b/tests/Builder/Syntax/SelectWriterTest.php index b6bb83f..9f737a1 100644 --- a/tests/Builder/Syntax/SelectWriterTest.php +++ b/tests/Builder/Syntax/SelectWriterTest.php @@ -36,9 +36,6 @@ class SelectWriterTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/UnionAllWriterTest.php b/tests/Builder/Syntax/UnionAllWriterTest.php index 80c2e72..9e45d09 100644 --- a/tests/Builder/Syntax/UnionAllWriterTest.php +++ b/tests/Builder/Syntax/UnionAllWriterTest.php @@ -30,9 +30,6 @@ class UnionAllWriterTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->unionAllWriter = new UnionAllWriter(new GenericBuilder()); diff --git a/tests/Builder/Syntax/UnionWriterTest.php b/tests/Builder/Syntax/UnionWriterTest.php index c04f558..3e9c7a7 100644 --- a/tests/Builder/Syntax/UnionWriterTest.php +++ b/tests/Builder/Syntax/UnionWriterTest.php @@ -30,9 +30,6 @@ class UnionWriterTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->unionWriter = new UnionWriter(new GenericBuilder()); diff --git a/tests/Builder/Syntax/UpdateWriterTest.php b/tests/Builder/Syntax/UpdateWriterTest.php index 91c79fe..2541a2a 100644 --- a/tests/Builder/Syntax/UpdateWriterTest.php +++ b/tests/Builder/Syntax/UpdateWriterTest.php @@ -39,9 +39,6 @@ class UpdateWriterTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/WhereWriterTest.php b/tests/Builder/Syntax/WhereWriterTest.php index 1a0dd8e..17a499c 100644 --- a/tests/Builder/Syntax/WhereWriterTest.php +++ b/tests/Builder/Syntax/WhereWriterTest.php @@ -29,9 +29,6 @@ class WhereWriterTest extends TestCase */ private $query; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/WriterFactoryTest.php b/tests/Builder/Syntax/WriterFactoryTest.php index 792c9b6..ae941d3 100644 --- a/tests/Builder/Syntax/WriterFactoryTest.php +++ b/tests/Builder/Syntax/WriterFactoryTest.php @@ -30,9 +30,6 @@ class WriterFactoryTest extends TestCase */ private $writer; - /** - * - */ protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Manipulation/BaseQueryTest.php b/tests/Manipulation/BaseQueryTest.php index c59d319..ea31d2e 100644 --- a/tests/Manipulation/BaseQueryTest.php +++ b/tests/Manipulation/BaseQueryTest.php @@ -9,6 +9,7 @@ */ namespace NilPortugues\Tests\Sql\QueryBuilder\Manipulation; +use NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources\DummyQuery; use PHPUnit\Framework\TestCase; /** @@ -17,7 +18,7 @@ class BaseQueryTest extends TestCase { /** - * @var \NilPortugues\Tests\Sql\QueryBuilder\Manipulation\Resources\DummyQuery + * @var DummyQuery */ private $query; @@ -26,18 +27,12 @@ class BaseQueryTest extends TestCase */ private $whereClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Where'; - /** - * - */ protected function setUp(): void { - $this->query = new Resources\DummyQuery(); + $this->query = new DummyQuery(); $this->query->setTable('tablename'); } - /** - * - */ protected function tearDown(): void { $this->query = null; diff --git a/tests/Manipulation/DeleteTest.php b/tests/Manipulation/DeleteTest.php index 00c5960..3a9ce28 100644 --- a/tests/Manipulation/DeleteTest.php +++ b/tests/Manipulation/DeleteTest.php @@ -19,24 +19,14 @@ */ class DeleteTest extends TestCase { - /** - * @var GenericBuilder - */ - private $writer; - /** * @var Delete */ private $query; - - /** - * - */ protected function setUp(): void { $this->query = new Delete(); } - /** * @test */ @@ -44,7 +34,6 @@ public function itShouldGetPartName() { $this->assertSame('DELETE', $this->query->partName()); } - /** * @test */ diff --git a/tests/Manipulation/InsertTest.php b/tests/Manipulation/InsertTest.php index c7d3413..3433b27 100644 --- a/tests/Manipulation/InsertTest.php +++ b/tests/Manipulation/InsertTest.php @@ -22,9 +22,6 @@ class InsertTest extends TestCase * @var Insert */ private $query; - /** - * - */ protected function setUp(): void { $this->query = new Insert(); diff --git a/tests/Manipulation/IntersectTest.php b/tests/Manipulation/IntersectTest.php index 0575cfd..fa4b265 100644 --- a/tests/Manipulation/IntersectTest.php +++ b/tests/Manipulation/IntersectTest.php @@ -29,9 +29,6 @@ class IntersectTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->query = new Intersect(); diff --git a/tests/Manipulation/MinusTest.php b/tests/Manipulation/MinusTest.php index afaee63..1fd26eb 100644 --- a/tests/Manipulation/MinusTest.php +++ b/tests/Manipulation/MinusTest.php @@ -29,9 +29,6 @@ class MinusTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->query = new Minus(new Select('user'), new Select('user_email')); diff --git a/tests/Manipulation/SelectTest.php b/tests/Manipulation/SelectTest.php index 4a69e28..2bef93a 100644 --- a/tests/Manipulation/SelectTest.php +++ b/tests/Manipulation/SelectTest.php @@ -23,9 +23,6 @@ class SelectTest extends TestCase * @var Select */ private $query; - /** - * - */ protected function setUp(): void { $this->query = new Select(); diff --git a/tests/Manipulation/UnionAllTest.php b/tests/Manipulation/UnionAllTest.php index 293201a..e3dac49 100644 --- a/tests/Manipulation/UnionAllTest.php +++ b/tests/Manipulation/UnionAllTest.php @@ -29,9 +29,6 @@ class UnionAllTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->query = new UnionAll(); diff --git a/tests/Manipulation/UnionTest.php b/tests/Manipulation/UnionTest.php index 53b950b..d281e12 100644 --- a/tests/Manipulation/UnionTest.php +++ b/tests/Manipulation/UnionTest.php @@ -29,9 +29,6 @@ class UnionTest extends TestCase */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $this->query = new Union(); diff --git a/tests/Manipulation/UpdateTest.php b/tests/Manipulation/UpdateTest.php index 6be34b2..be96122 100644 --- a/tests/Manipulation/UpdateTest.php +++ b/tests/Manipulation/UpdateTest.php @@ -22,9 +22,6 @@ class UpdateTest extends TestCase * @var Update */ private $query; - /** - * - */ protected function setUp(): void { $this->query = new Update(); diff --git a/tests/Syntax/WhereTest.php b/tests/Syntax/WhereTest.php index 2a30e40..9da5d5f 100644 --- a/tests/Syntax/WhereTest.php +++ b/tests/Syntax/WhereTest.php @@ -40,9 +40,6 @@ class WhereTest extends TestCase */ protected $queryException = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - /** - * - */ protected function setUp(): void { $query = new DummyQuery(); From 9a4bb39f01ab4681b4e8a93374b95bef234d8d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Wed, 27 May 2020 11:05:41 +0200 Subject: [PATCH 3/5] rector:early returns --- composer.json | 2 +- rector.yaml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 57ea2cd..ff19133 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "scripts": { "test": "php vendor/pestphp/pest/bin/pest", - "rector": "php vendor/rector/rector/bin/rector" + "rector": "php vendor/rector/rector/bin/rector process" }, "autoload":{ "psr-4":{ diff --git a/rector.yaml b/rector.yaml index db3e63a..33be3b2 100644 --- a/rector.yaml +++ b/rector.yaml @@ -10,6 +10,14 @@ parameters: sets: # - solid - 'dead-code' + - 'early-return' + # - 'code-quality' + + # - 'performance' + # - 'psr4' + # - 'phpunit91' + # - 'php74' + # - 'order' paths: - src From 29f90772554ba5fb637670c036d1d6691f0d71e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Thu, 28 May 2020 13:39:27 +0200 Subject: [PATCH 4/5] composer php 7.4 or up --- composer.json | 2 +- tests/Builder/Syntax/SelectWriterTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ff19133..2fe3142 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ }, "require": { - "php": ">=7", + "php": ">=7.4", "nilportugues/sql-query-formatter": "~1.2" }, "require-dev": { diff --git a/tests/Builder/Syntax/SelectWriterTest.php b/tests/Builder/Syntax/SelectWriterTest.php index 9f737a1..f56e548 100644 --- a/tests/Builder/Syntax/SelectWriterTest.php +++ b/tests/Builder/Syntax/SelectWriterTest.php @@ -10,6 +10,7 @@ namespace NilPortugues\Tests\Sql\QueryBuilder\Builder\Syntax; +use NilPortugues\Sql\QueryBuilder\Manipulation\QueryException; use NilPortugues\Sql\QueryBuilder\Syntax\Column; use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy; use NilPortugues\Sql\QueryBuilder\Manipulation\Select; @@ -34,7 +35,7 @@ class SelectWriterTest extends TestCase /** * @var string */ - private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; + private $exceptionClass = QueryException::class; protected function setUp(): void { From 7742a0cd8ef418265c5fe8b7702801d4be6d7d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s=20Calder=C3=B3?= Date: Thu, 28 May 2020 13:43:45 +0200 Subject: [PATCH 5/5] rector order rule --- rector.yaml | 5 +- src/Builder/GenericBuilder.php | 68 ++++++----------------- src/Manipulation/AbstractBaseQuery.php | 27 ++++----- src/Manipulation/ColumnQuery.php | 9 ++- src/Manipulation/Intersect.php | 3 +- src/Manipulation/JoinQuery.php | 29 +--------- src/Manipulation/Minus.php | 3 +- src/Syntax/Column.php | 22 ++------ src/Syntax/OrderBy.php | 12 +--- src/Syntax/Where.php | 6 +- tests/Builder/Syntax/InsertWriterTest.php | 9 ++- tests/Builder/Syntax/SelectWriterTest.php | 9 ++- tests/Builder/Syntax/UpdateWriterTest.php | 9 ++- tests/Manipulation/BaseQueryTest.php | 14 ++--- tests/Manipulation/IntersectTest.php | 15 ++--- tests/Manipulation/MinusTest.php | 15 ++--- tests/Manipulation/UnionAllTest.php | 15 ++--- tests/Manipulation/UnionTest.php | 15 ++--- tests/Syntax/WhereTest.php | 41 ++------------ 19 files changed, 88 insertions(+), 238 deletions(-) diff --git a/rector.yaml b/rector.yaml index 33be3b2..02c7c51 100644 --- a/rector.yaml +++ b/rector.yaml @@ -11,13 +11,14 @@ parameters: # - solid - 'dead-code' - 'early-return' + - 'order' # - 'code-quality' # - 'performance' - # - 'psr4' + #>blows up - 'psr4' # - 'phpunit91' # - 'php74' - # - 'order' + # paths: - src diff --git a/src/Builder/GenericBuilder.php b/src/Builder/GenericBuilder.php index e7b741a..5a86482 100644 --- a/src/Builder/GenericBuilder.php +++ b/src/Builder/GenericBuilder.php @@ -33,27 +33,6 @@ */ class GenericBuilder implements BuilderInterface { - /** - * The placeholder parameter bag. - * - * @var PlaceholderWriter - */ - protected $placeholderWriter; - - /** - * The Where writer. - * - * @var WhereWriter - */ - protected $whereWriter; - - /** - * The SQL formatter. - * - * @var Formatter - */ - protected $sqlFormatter; - /** * Class namespace for the query pretty output formatter. * Required to create the instance only if required. @@ -61,7 +40,6 @@ class GenericBuilder implements BuilderInterface * @var string */ protected $sqlFormatterClass = 'NilPortugues\Sql\QueryFormatter\Formatter'; - /** * Array holding the writers for each query part. Methods are called upon request and stored in * the $queryWriterInstances array. @@ -78,7 +56,6 @@ class GenericBuilder implements BuilderInterface 'UNION' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createUnionWriter', 'UNION ALL' => '\NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory::createUnionAllWriter', ]; - /** * Array that stores instances of query writers. * @@ -94,7 +71,24 @@ class GenericBuilder implements BuilderInterface 'UNION' => null, 'UNION ALL' => null, ]; - + /** + * The placeholder parameter bag. + * + * @var PlaceholderWriter + */ + protected $placeholderWriter; + /** + * The Where writer. + * + * @var WhereWriter + */ + protected $whereWriter; + /** + * The SQL formatter. + * + * @var Formatter + */ + protected $sqlFormatter; /** * Creates writers. */ @@ -102,7 +96,6 @@ public function __construct() { $this->placeholderWriter = WriterFactory::createPlaceholderWriter(); } - /** * @param string $table * @param array $columns @@ -113,7 +106,6 @@ public function select($table = null, array $columns = null) { return $this->injectBuilder(QueryFactory::createSelect($table, $columns)); } - /** * @param \NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery * @@ -123,7 +115,6 @@ protected function injectBuilder(AbstractBaseQuery $query) { return $query->setBuilder($this); } - /** * @param string $table * @param array $values @@ -134,7 +125,6 @@ public function insert($table = null, array $values = null) { return $this->injectBuilder(QueryFactory::createInsert($table, $values)); } - /** * @param string $table * @param array $values @@ -145,7 +135,6 @@ public function update($table = null, array $values = null) { return $this->injectBuilder(QueryFactory::createUpdate($table, $values)); } - /** * @param string $table * @@ -155,7 +144,6 @@ public function delete($table = null) { return $this->injectBuilder(QueryFactory::createDelete($table)); } - /** * @return Intersect */ @@ -163,7 +151,6 @@ public function intersect() { return QueryFactory::createIntersect(); } - /** * @return Union */ @@ -171,7 +158,6 @@ public function union() { return QueryFactory::createUnion(); } - /** * @return UnionAll */ @@ -179,7 +165,6 @@ public function unionAll() { return QueryFactory::createUnionAll(); } - /** * @param \NilPortugues\Sql\QueryBuilder\Manipulation\Select $first * @param \NilPortugues\Sql\QueryBuilder\Manipulation\Select $second @@ -190,7 +175,6 @@ public function minus(Select $first, Select $second) { return QueryFactory::createMinus($first, $second); } - /** * @return array */ @@ -198,7 +182,6 @@ public function getValues() { return $this->placeholderWriter->get(); } - /** * Returns a SQL string in a readable human-friendly format. * @@ -214,7 +197,6 @@ public function writeFormatted(QueryInterface $query) return $this->sqlFormatter->format($this->write($query)); } - /** * @param QueryInterface $query * @param bool $resetPlaceholders @@ -239,7 +221,6 @@ public function write(QueryInterface $query, $resetPlaceholders = true) throw new RuntimeException('Query builder part not defined.'); } - /** * @param Select $select * @@ -259,7 +240,6 @@ public function writeJoin(Select $select) return $sql; } - /** * @param Table $table * @@ -272,7 +252,6 @@ public function writeTableWithAlias(Table $table) return $schema.$this->writeTableName($table).$alias; } - /** * @param $alias * @@ -282,7 +261,6 @@ public function writeTableAlias($alias) { return $alias; } - /** * Returns the table name. * @@ -294,7 +272,6 @@ public function writeTableName(Table $table) { return $table->getName(); } - /** * @param string $alias * @@ -304,7 +281,6 @@ public function writeColumnAlias($alias) { return sprintf('"%s"', $alias); } - /** * @param Table $table * @@ -316,7 +292,6 @@ public function writeTable(Table $table) return $schema.$this->writeTableName($table); } - /** * @param array $values * @@ -333,7 +308,6 @@ function (&$value) { return $values; } - /** * @param $value * @@ -343,7 +317,6 @@ public function writePlaceholderValue($value) { return $this->placeholderWriter->add($value); } - /** * @param $operator * @@ -353,7 +326,6 @@ public function writeConjunction($operator) { return ' '.$operator.' '; } - /** * @return string */ @@ -361,7 +333,6 @@ public function writeIsNull() { return ' IS NULL'; } - /** * @return string */ @@ -369,7 +340,6 @@ public function writeIsNotNull() { return ' IS NOT NULL'; } - /** * Returns the column name. * @@ -387,7 +357,6 @@ public function writeColumnName(Column $column) return $name; } - /** * @return string */ @@ -395,7 +364,6 @@ protected function writeColumnAll() { return '*'; } - /** * @param string $queryPart */ diff --git a/src/Manipulation/AbstractBaseQuery.php b/src/Manipulation/AbstractBaseQuery.php index 5bc3a78..67ee14f 100644 --- a/src/Manipulation/AbstractBaseQuery.php +++ b/src/Manipulation/AbstractBaseQuery.php @@ -30,11 +30,6 @@ abstract class AbstractBaseQuery implements QueryInterface, QueryPartInterface */ protected $comment = ''; - /** - * @var \NilPortugues\Sql\QueryBuilder\Builder\BuilderInterface - */ - protected $builder; - /** * @var string */ @@ -45,16 +40,6 @@ abstract class AbstractBaseQuery implements QueryInterface, QueryPartInterface */ protected $whereOperator = 'AND'; - /** - * @var Where - */ - protected $where; - - /** - * @var array - */ - protected $joins = []; - /** * @var int */ @@ -64,11 +49,23 @@ abstract class AbstractBaseQuery implements QueryInterface, QueryPartInterface * @var int */ protected $limitCount; + /** + * @var array + */ + protected $joins = []; /** * @var array */ protected $orderBy = []; + /** + * @var \NilPortugues\Sql\QueryBuilder\Builder\BuilderInterface + */ + protected $builder; + /** + * @var Where + */ + protected $where; /** * @return Where diff --git a/src/Manipulation/ColumnQuery.php b/src/Manipulation/ColumnQuery.php index 43ad96e..2cfb82e 100644 --- a/src/Manipulation/ColumnQuery.php +++ b/src/Manipulation/ColumnQuery.php @@ -20,6 +20,10 @@ */ class ColumnQuery { + /** + * @var bool + */ + protected $isCount = false; /** * @var array */ @@ -40,11 +44,6 @@ class ColumnQuery */ protected $columnFuncs = []; - /** - * @var bool - */ - protected $isCount = false; - /** * @var Select */ diff --git a/src/Manipulation/Intersect.php b/src/Manipulation/Intersect.php index 876d1e1..d56d81d 100644 --- a/src/Manipulation/Intersect.php +++ b/src/Manipulation/Intersect.php @@ -19,8 +19,7 @@ */ class Intersect implements QueryInterface, QueryPartInterface { - const INTERSECT='INTERSECT'; - + public const INTERSECT = 'INTERSECT'; /** * @var array */ diff --git a/src/Manipulation/JoinQuery.php b/src/Manipulation/JoinQuery.php index 8ddbbd2..c7bc8f5 100644 --- a/src/Manipulation/JoinQuery.php +++ b/src/Manipulation/JoinQuery.php @@ -19,36 +19,30 @@ */ class JoinQuery { - const JOIN_LEFT = 'LEFT'; - const JOIN_RIGHT = 'RIGHT'; const JOIN_INNER = 'INNER'; + const JOIN_RIGHT = 'RIGHT'; const JOIN_CROSS = 'CROSS'; - + const JOIN_LEFT = 'LEFT'; /** * @var Where */ protected $joinCondition; - /** * @var bool */ protected $isJoin = false; - /** * @var string */ protected $joinType; - /** * @var array */ protected $joins = []; - /** * @var Select */ protected $select; - /** * @param Select $select */ @@ -56,7 +50,6 @@ public function __construct(Select $select) { $this->select = $select; } - /** * @param string $table * @@ -68,7 +61,6 @@ public function setTable($table) return $this; } - /** * @param string $table * @param mixed $selfColumn @@ -81,7 +73,6 @@ public function leftJoin($table, $selfColumn = null, $refColumn = null, $columns { return $this->join($table, $selfColumn, $refColumn, $columns, self::JOIN_LEFT); } - /** * @param string $table * @param mixed $selfColumn @@ -108,7 +99,6 @@ public function join( return $this->joins[$table]; } - /** * @param Select $select * @param mixed $selfColumn @@ -136,7 +126,6 @@ public function addJoin(Select $select, $selfColumn, $refColumn) return $this->joins[$table]; } - /** * Transforms Select in a joint. * @@ -150,7 +139,6 @@ public function setJoin($isJoin = true) return $this; } - /** * @param string $table * @param mixed $selfColumn @@ -165,7 +153,6 @@ public function rightJoin($table, $selfColumn = null, $refColumn = null, $column { return $this->join($table, $selfColumn, $refColumn, $columns, self::JOIN_RIGHT); } - /** * @param string $table * @param mixed $selfColumn @@ -178,7 +165,6 @@ public function crossJoin($table, $selfColumn = null, $refColumn = null, $column { return $this->join($table, $selfColumn, $refColumn, $columns, self::JOIN_CROSS); } - /** * @param string $table * @param mixed $selfColumn @@ -191,7 +177,6 @@ public function innerJoin($table, $selfColumn = null, $refColumn = null, $column { return $this->join($table, $selfColumn, $refColumn, $columns, self::JOIN_INNER); } - /** * Alias to joinCondition. * @@ -201,7 +186,6 @@ public function on() { return $this->joinCondition(); } - /** * WHERE constrains used for the ON clause of a (LEFT/RIGHT/INNER/CROSS) JOIN. * @@ -215,7 +199,6 @@ public function joinCondition() return $this->joinCondition; } - /** * @return bool */ @@ -223,7 +206,6 @@ public function isJoinSelect() { return $this->isJoin; } - /** * @return bool */ @@ -231,7 +213,6 @@ public function isJoin() { return $this->isJoin; } - /** * @return \NilPortugues\Sql\QueryBuilder\Syntax\Where */ @@ -239,7 +220,6 @@ public function getJoinCondition() { return $this->joinCondition; } - /** * @param \NilPortugues\Sql\QueryBuilder\Syntax\Where $joinCondition * @@ -251,7 +231,6 @@ public function setJoinCondition($joinCondition) return $this; } - /** * @return string */ @@ -259,7 +238,6 @@ public function getJoinType() { return $this->joinType; } - /** * @param string $joinType * @@ -271,7 +249,6 @@ public function setJoinType($joinType) return $this; } - /** * @return array */ @@ -279,7 +256,6 @@ public function getJoins() { return $this->joins; } - /** * @param array $joins * @@ -291,7 +267,6 @@ public function setJoins($joins) return $this; } - /** * @return array */ diff --git a/src/Manipulation/Minus.php b/src/Manipulation/Minus.php index 361a5cc..f5bb138 100644 --- a/src/Manipulation/Minus.php +++ b/src/Manipulation/Minus.php @@ -19,8 +19,7 @@ */ class Minus implements QueryInterface, QueryPartInterface { - const MINUS='MINUS'; - + public const MINUS = 'MINUS'; /** * @var Select */ diff --git a/src/Syntax/Column.php b/src/Syntax/Column.php index aa244f9..568d4d6 100644 --- a/src/Syntax/Column.php +++ b/src/Syntax/Column.php @@ -17,23 +17,19 @@ */ class Column implements QueryPartInterface { - const ALL = '*'; - - /** - * @var Table - */ - protected $table; - /** * @var string */ protected $name; - + /** + * @var Table + */ + protected $table; + const ALL = '*'; /** * @var string */ protected $alias; - /** * @param string $name * @param string $table @@ -45,7 +41,6 @@ public function __construct($name, $table, $alias = '') $this->setTable($table); $this->setAlias($alias); } - /** * @return string */ @@ -53,7 +48,6 @@ public function partName() { return 'COLUMN'; } - /** * @return string */ @@ -61,7 +55,6 @@ public function getName() { return $this->name; } - /** * @param string $name * @@ -73,7 +66,6 @@ public function setName($name) return $this; } - /** * @return Table */ @@ -81,7 +73,6 @@ public function getTable() { return $this->table; } - /** * @param string $table * @@ -94,7 +85,6 @@ public function setTable($table) return $this; } - /** * @return string */ @@ -102,7 +92,6 @@ public function getAlias() { return $this->alias; } - /** * @param null|string $alias * @@ -126,7 +115,6 @@ public function setAlias($alias) return $this; } - /** * Check whether column name is '*' or not. * diff --git a/src/Syntax/OrderBy.php b/src/Syntax/OrderBy.php index e82c038..63c3c46 100644 --- a/src/Syntax/OrderBy.php +++ b/src/Syntax/OrderBy.php @@ -16,24 +16,20 @@ */ class OrderBy { - const ASC = 'ASC'; - const DESC = 'DESC'; - /** * @var Column */ protected $column; - + const DESC = 'DESC'; + const ASC = 'ASC'; /** * @var string */ protected $direction; - /** * @var bool */ protected $useAlias; - /** * @param Column $column * @param string $direction @@ -43,7 +39,6 @@ public function __construct(Column $column, $direction) $this->setColumn($column); $this->setDirection($direction); } - /** * @return Column */ @@ -51,7 +46,6 @@ public function getColumn() { return $this->column; } - /** * @param Column $column * @@ -63,7 +57,6 @@ public function setColumn($column) return $this; } - /** * @return string */ @@ -71,7 +64,6 @@ public function getDirection() { return $this->direction; } - /** * @param string $direction * diff --git a/src/Syntax/Where.php b/src/Syntax/Where.php index fc7ed3a..0d95766 100644 --- a/src/Syntax/Where.php +++ b/src/Syntax/Where.php @@ -20,6 +20,7 @@ */ class Where { + const CONJUNCTION_AND = 'AND'; private const SUBJECT = 'subject'; const OPERATOR_GREATER_THAN_OR_EQUAL = '>='; @@ -30,9 +31,6 @@ class Where const OPERATOR_NOT_LIKE = 'NOT LIKE'; const OPERATOR_EQUAL = '='; const OPERATOR_NOT_EQUAL = '<>'; - const CONJUNCTION_AND = 'AND'; - const CONJUNCTION_AND_NOT = 'AND NOT'; - const CONJUNCTION_OR = 'OR'; const CONJUNCTION_OR_NOT = 'OR NOT'; /** @@ -44,6 +42,8 @@ class Where * @var array */ protected $betweens = []; + const CONJUNCTION_AND_NOT = 'AND NOT'; + const CONJUNCTION_OR = 'OR'; /** * @var array diff --git a/tests/Builder/Syntax/InsertWriterTest.php b/tests/Builder/Syntax/InsertWriterTest.php index 3a601ad..d8f14f5 100644 --- a/tests/Builder/Syntax/InsertWriterTest.php +++ b/tests/Builder/Syntax/InsertWriterTest.php @@ -19,6 +19,10 @@ */ class InsertWriterTest extends TestCase { + /** + * @var string + */ + private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; /** * @var GenericBuilder */ @@ -29,11 +33,6 @@ class InsertWriterTest extends TestCase */ private $query; - /** - * @var string - */ - private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/SelectWriterTest.php b/tests/Builder/Syntax/SelectWriterTest.php index f56e548..e23a31e 100644 --- a/tests/Builder/Syntax/SelectWriterTest.php +++ b/tests/Builder/Syntax/SelectWriterTest.php @@ -22,6 +22,10 @@ */ class SelectWriterTest extends TestCase { + /** + * @var string + */ + private $exceptionClass = QueryException::class; /** * @var GenericBuilder */ @@ -32,11 +36,6 @@ class SelectWriterTest extends TestCase */ private $query; - /** - * @var string - */ - private $exceptionClass = QueryException::class; - protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Builder/Syntax/UpdateWriterTest.php b/tests/Builder/Syntax/UpdateWriterTest.php index 2541a2a..eb95fc9 100644 --- a/tests/Builder/Syntax/UpdateWriterTest.php +++ b/tests/Builder/Syntax/UpdateWriterTest.php @@ -19,6 +19,10 @@ */ class UpdateWriterTest extends TestCase { + /** + * @var string + */ + private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; /** * @var array */ @@ -34,11 +38,6 @@ class UpdateWriterTest extends TestCase */ private $query; - /** - * @var string - */ - private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - protected function setUp(): void { $this->writer = new GenericBuilder(); diff --git a/tests/Manipulation/BaseQueryTest.php b/tests/Manipulation/BaseQueryTest.php index ea31d2e..68e5723 100644 --- a/tests/Manipulation/BaseQueryTest.php +++ b/tests/Manipulation/BaseQueryTest.php @@ -17,27 +17,23 @@ */ class BaseQueryTest extends TestCase { - /** - * @var DummyQuery - */ - private $query; - /** * @var string */ private $whereClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Where'; - + /** + * @var DummyQuery + */ + private $query; protected function setUp(): void { $this->query = new DummyQuery(); $this->query->setTable('tablename'); } - protected function tearDown(): void { $this->query = null; } - /** * @test */ @@ -45,7 +41,6 @@ public function itShouldBeAbleToSetTableName() { $this->assertSame('tablename', $this->query->getTable()->getName()); } - /** * @test */ @@ -56,7 +51,6 @@ public function itShouldGetWhere() $this->query->where(); $this->assertInstanceOf($this->whereClass, $this->query->getWhere()); } - /** * @test */ diff --git a/tests/Manipulation/IntersectTest.php b/tests/Manipulation/IntersectTest.php index fa4b265..8252c0d 100644 --- a/tests/Manipulation/IntersectTest.php +++ b/tests/Manipulation/IntersectTest.php @@ -19,21 +19,18 @@ */ class IntersectTest extends TestCase { - /** - * @var Intersect - */ - private $query; - /** * @var string */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - + /** + * @var Intersect + */ + private $query; protected function setUp(): void { $this->query = new Intersect(); } - /** * @test */ @@ -41,7 +38,6 @@ public function itShouldGetPartName() { $this->assertSame('INTERSECT', $this->query->partName()); } - /** * @test */ @@ -50,7 +46,6 @@ public function itShouldThrowExceptionForUnsupportedGetTable() $this->expectException($this->exceptionClass); $this->query->getTable(); } - /** * @test */ @@ -59,7 +54,6 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() $this->expectException($this->exceptionClass); $this->query->getWhere(); } - /** * @test */ @@ -68,7 +62,6 @@ public function itShouldThrowExceptionForUnsupportedWhere() $this->expectException($this->exceptionClass); $this->query->where(); } - /** * @test */ diff --git a/tests/Manipulation/MinusTest.php b/tests/Manipulation/MinusTest.php index 1fd26eb..11ed675 100644 --- a/tests/Manipulation/MinusTest.php +++ b/tests/Manipulation/MinusTest.php @@ -19,21 +19,18 @@ */ class MinusTest extends TestCase { - /** - * @var Minus - */ - private $query; - /** * @var string */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - + /** + * @var Minus + */ + private $query; protected function setUp(): void { $this->query = new Minus(new Select('user'), new Select('user_email')); } - /** * @test */ @@ -41,7 +38,6 @@ public function itShouldGetPartName() { $this->assertSame('MINUS', $this->query->partName()); } - /** * @test */ @@ -50,7 +46,6 @@ public function itShouldThrowExceptionForUnsupportedGetTable() $this->expectException($this->exceptionClass); $this->query->getTable(); } - /** * @test */ @@ -59,7 +54,6 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() $this->expectException($this->exceptionClass); $this->query->getWhere(); } - /** * @test */ @@ -68,7 +62,6 @@ public function itShouldThrowExceptionForUnsupportedWhere() $this->expectException($this->exceptionClass); $this->query->where(); } - /** * @test */ diff --git a/tests/Manipulation/UnionAllTest.php b/tests/Manipulation/UnionAllTest.php index e3dac49..ef643e8 100644 --- a/tests/Manipulation/UnionAllTest.php +++ b/tests/Manipulation/UnionAllTest.php @@ -19,21 +19,18 @@ */ class UnionAllTest extends TestCase { - /** - * @var UnionAll - */ - private $query; - /** * @var string */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - + /** + * @var UnionAll + */ + private $query; protected function setUp(): void { $this->query = new UnionAll(); } - /** * @test */ @@ -41,7 +38,6 @@ public function itShouldGetPartName() { $this->assertSame('UNION ALL', $this->query->partName()); } - /** * @test */ @@ -50,7 +46,6 @@ public function itShouldThrowExceptionForUnsupportedGetTable() $this->expectException($this->exceptionClass); $this->query->getTable(); } - /** * @test */ @@ -59,7 +54,6 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() $this->expectException($this->exceptionClass); $this->query->getWhere(); } - /** * @test */ @@ -68,7 +62,6 @@ public function itShouldThrowExceptionForUnsupportedWhere() $this->expectException($this->exceptionClass); $this->query->where(); } - /** * @test */ diff --git a/tests/Manipulation/UnionTest.php b/tests/Manipulation/UnionTest.php index d281e12..406aa8d 100644 --- a/tests/Manipulation/UnionTest.php +++ b/tests/Manipulation/UnionTest.php @@ -19,21 +19,18 @@ */ class UnionTest extends TestCase { - /** - * @var Union - */ - private $query; - /** * @var string */ private $exceptionClass = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - + /** + * @var Union + */ + private $query; protected function setUp(): void { $this->query = new Union(); } - /** * @test */ @@ -41,7 +38,6 @@ public function itShouldGetPartName() { $this->assertSame('UNION', $this->query->partName()); } - /** * @test */ @@ -50,7 +46,6 @@ public function itShouldThrowExceptionForUnsupportedGetTable() $this->expectException($this->exceptionClass); $this->query->getTable(); } - /** * @test */ @@ -59,7 +54,6 @@ public function itShouldThrowExceptionForUnsupportedGetWhere() $this->expectException($this->exceptionClass); $this->query->getWhere(); } - /** * @test */ @@ -68,7 +62,6 @@ public function itShouldThrowExceptionForUnsupportedWhere() $this->expectException($this->exceptionClass); $this->query->where(); } - /** * @test */ diff --git a/tests/Syntax/WhereTest.php b/tests/Syntax/WhereTest.php index 9da5d5f..97ba6f0 100644 --- a/tests/Syntax/WhereTest.php +++ b/tests/Syntax/WhereTest.php @@ -21,25 +21,21 @@ class WhereTest extends TestCase { /** - * @var Where + * @var string */ - protected $where; - + protected $columnClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Column'; /** * @var string */ protected $whereClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Where'; - /** * @var string */ - protected $columnClass = '\NilPortugues\Sql\QueryBuilder\Syntax\Column'; - + protected $queryException = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; /** - * @var string + * @var Where */ - protected $queryException = '\NilPortugues\Sql\QueryBuilder\Manipulation\QueryException'; - + protected $where; protected function setUp(): void { $query = new DummyQuery(); @@ -47,7 +43,6 @@ protected function setUp(): void $this->where = new Where($query); } - /** * @test */ @@ -55,7 +50,6 @@ public function itShouldBeCloneable() { $this->assertEquals($this->where, clone $this->where); } - /** * @test */ @@ -63,7 +57,6 @@ public function itShouldBeEmptyOnConstruct() { $this->assertTrue($this->where->isEmpty()); } - /** * @test */ @@ -71,7 +64,6 @@ public function itShouldReturnDefaultConjuctionAnd() { $this->assertSame('AND', $this->where->getConjunction()); } - /** * @test */ @@ -79,7 +71,6 @@ public function itShouldReturnDefaultSubWhere() { $this->assertSame(array(), $this->where->getSubWheres()); } - /** * @test */ @@ -90,7 +81,6 @@ public function itShouldReturnSubFilter() $this->assertSame(array(), $filter->getSubWheres()); $this->assertInstanceOf($this->whereClass, $filter); } - /** * @test */ @@ -104,7 +94,6 @@ public function itShouldReturnTheSameEqAndEqual() $this->where->eq($column, $value) ); } - /** * @test */ @@ -119,7 +108,6 @@ public function itShouldNotBeEqualTo() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -134,7 +122,6 @@ public function itShouldBeGreaterThan() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -149,7 +136,6 @@ public function itShouldBeGreaterThanOrEqual() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -164,7 +150,6 @@ public function itShouldBeLessThan() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -179,7 +164,6 @@ public function itShouldBeLessThanOrEqual() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -194,7 +178,6 @@ public function itShouldBeLike() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -209,7 +192,6 @@ public function itShouldBeNotLike() $this->assertSame($column, $result[0]['subject']->getName()); $this->assertSame($value, $result[0]['target']); } - /** * @test */ @@ -230,7 +212,6 @@ public function itShouldAccumulateMatchConditions() ); $this->assertEquals($expected, $result); } - /** * @test */ @@ -251,7 +232,6 @@ public function itShouldAccumulateMatchBooleanConditions() ); $this->assertEquals($expected, $result); } - /** * @test */ @@ -272,7 +252,6 @@ public function itShouldAccumulateMatchQueryExpansionConditions() ); $this->assertEquals($expected, $result); } - /** * @test */ @@ -287,7 +266,6 @@ public function itShouldAccumulateInConditions() $expected = array($column => array(1, 2, 3)); $this->assertEquals($expected, $result); } - /** * @test */ @@ -302,7 +280,6 @@ public function itShouldAccumulateNotInConditions() $expected = array($column => array(1, 2, 3)); $this->assertEquals($expected, $result); } - /** * @test */ @@ -318,7 +295,6 @@ public function itShouldWriteBetweenConditions() $this->assertEquals(1, $result[0]['a']); $this->assertEquals(2, $result[0]['b']); } - /** * @test */ @@ -332,7 +308,6 @@ public function itShouldSetNullValueCondition() $this->assertInstanceOf($this->columnClass, $result[0]['subject']); } - /** * @test */ @@ -346,7 +321,6 @@ public function itShouldSetIsNotNullValueCondition() $this->assertInstanceOf($this->columnClass, $result[0]['subject']); } - /** * @test */ @@ -361,7 +335,6 @@ public function itShouldSetBitClauseValueCondition() $this->assertEquals(1, $result[0]['value']); $this->assertInstanceOf($this->columnClass, $result[0]['subject']); } - /** * @test */ @@ -370,7 +343,6 @@ public function ItShouldChangeAndToOrOperator() $result = $this->where->conjunction('OR'); $this->assertEquals('OR', $result->getConjunction()); } - /** * @test */ @@ -379,7 +351,6 @@ public function itShouldThrowExceptionOnUnknownConjunction() $this->expectException($this->queryException); $this->where->conjunction('NOT_VALID_CONJUNCTION'); } - /** * @test */ @@ -392,7 +363,6 @@ public function itShouldSetExistsCondition() $this->assertEquals(array($select1), $result); } - /** * @test */ @@ -405,7 +375,6 @@ public function itShouldSetNotExistsCondition() $this->assertEquals(array($select1), $result); } - /** * @test */