From 230d90ebda53fe04d46a69ee57592714556fb125 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 11:36:54 -0400 Subject: [PATCH 1/6] Passing `null` to trim() is deprecated since PHP 8.1 --- src/DB/QueryBuilder/Clauses/Join.php | 2 +- src/DB/QueryBuilder/Clauses/Select.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DB/QueryBuilder/Clauses/Join.php b/src/DB/QueryBuilder/Clauses/Join.php index 6a79fa0..67f0f5e 100644 --- a/src/DB/QueryBuilder/Clauses/Join.php +++ b/src/DB/QueryBuilder/Clauses/Join.php @@ -33,7 +33,7 @@ class Join { public function __construct( $joinType, $table, $alias = null ) { $this->table = QueryBuilder::prefixTable( $table ); $this->joinType = $this->getJoinType( $joinType ); - $this->alias = trim( $alias ); + $this->alias = is_null( $alias ) ? null : trim( $alias ); } /** diff --git a/src/DB/QueryBuilder/Clauses/Select.php b/src/DB/QueryBuilder/Clauses/Select.php index 56eaaf9..88e76e0 100644 --- a/src/DB/QueryBuilder/Clauses/Select.php +++ b/src/DB/QueryBuilder/Clauses/Select.php @@ -22,6 +22,6 @@ class Select { */ public function __construct( $column, $alias = null ) { $this->column = trim( $column ); - $this->alias = trim( $alias ); + $this->alias = is_null( $alias ) ? null : trim( $alias ); } } From 2c8b0788419f8261b1e185aca68c065d3e617c50 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 11:45:51 -0400 Subject: [PATCH 2/6] missed one! --- src/DB/QueryBuilder/Clauses/From.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DB/QueryBuilder/Clauses/From.php b/src/DB/QueryBuilder/Clauses/From.php index 8c0dcb7..bed2df9 100644 --- a/src/DB/QueryBuilder/Clauses/From.php +++ b/src/DB/QueryBuilder/Clauses/From.php @@ -24,6 +24,6 @@ class From { */ public function __construct( $table, $alias = null ) { $this->table = QueryBuilder::prefixTable( $table ); - $this->alias = trim( $alias ); + $this->alias = is_null( $alias ) ? null : trim( $alias ); } } From e44274bf2e15dfa47d9649741752a41f0cc1888b Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 13:50:26 -0400 Subject: [PATCH 3/6] Update with some suggestions and some extrapolation from those. --- CHANGELOG.md | 6 ++++++ src/DB/DB.php | 4 ++-- src/DB/QueryBuilder/Clauses/From.php | 6 +++--- src/DB/QueryBuilder/Clauses/Join.php | 6 +++--- src/DB/QueryBuilder/Clauses/Select.php | 6 +++--- src/DB/QueryBuilder/Concerns/FromClause.php | 4 ++-- src/DB/QueryBuilder/Concerns/JoinClause.php | 12 ++++++------ src/DB/QueryBuilder/JoinQueryBuilder.php | 12 ++++++------ 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f1f1ed..5cef213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard. +## [1.0.4] 2023-10-23 + +* Tweak - Updates around `trim()` for php 8.1 compatibility. +* Tweak - Force From() and Select() to convert passed non-strings to an empty string. +* Tweak - Convert all function signatures that take `$alias` as a param to use only `string` instead of `string|null`. + ## [1.0.3] 2022-11-22 * Tweak - Set composer.json `config.platform.php` to `7.0`. diff --git a/src/DB/DB.php b/src/DB/DB.php index 1a4605e..a3d2758 100644 --- a/src/DB/DB.php +++ b/src/DB/DB.php @@ -173,11 +173,11 @@ public static function prefix( $tableName ) { * Create QueryBuilder instance * * @param string|RawSQL $table - * @param null|string $alias + * @param string $alias * * @return QueryBuilder */ - public static function table( $table, $alias = null ) { + public static function table( $table, $alias = '' ) { $builder = new QueryBuilder(); $builder->from( $table, $alias ); diff --git a/src/DB/QueryBuilder/Clauses/From.php b/src/DB/QueryBuilder/Clauses/From.php index bed2df9..34ee338 100644 --- a/src/DB/QueryBuilder/Clauses/From.php +++ b/src/DB/QueryBuilder/Clauses/From.php @@ -20,10 +20,10 @@ class From { /** * @param string|RawSQL $table - * @param string|null $alias + * @param string $alias */ - public function __construct( $table, $alias = null ) { + public function __construct( $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); - $this->alias = is_null( $alias ) ? null : trim( $alias ); + $this->alias = is_scalar( $alias ) ? trim( (string) $alias ) : ''; } } diff --git a/src/DB/QueryBuilder/Clauses/Join.php b/src/DB/QueryBuilder/Clauses/Join.php index 67f0f5e..c2511d2 100644 --- a/src/DB/QueryBuilder/Clauses/Join.php +++ b/src/DB/QueryBuilder/Clauses/Join.php @@ -28,12 +28,12 @@ class Join { /** * @param string $table * @param string $joinType \StellarWP\DB\QueryBuilder\Types\JoinType - * @param string|null $alias + * @param string $alias */ - public function __construct( $joinType, $table, $alias = null ) { + public function __construct( $joinType, $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); $this->joinType = $this->getJoinType( $joinType ); - $this->alias = is_null( $alias ) ? null : trim( $alias ); + $this->alias = is_scalar( $alias ) ? trim( (string) $alias ) : ''; } /** diff --git a/src/DB/QueryBuilder/Clauses/Select.php b/src/DB/QueryBuilder/Clauses/Select.php index 88e76e0..468bfc4 100644 --- a/src/DB/QueryBuilder/Clauses/Select.php +++ b/src/DB/QueryBuilder/Clauses/Select.php @@ -18,10 +18,10 @@ class Select { /** * @param string $column - * @param string|null $alias + * @param string $alias */ - public function __construct( $column, $alias = null ) { + public function __construct( $column, $alias = '' ) { $this->column = trim( $column ); - $this->alias = is_null( $alias ) ? null : trim( $alias ); + $this->alias = is_scalar( $alias ) ? trim( (string) $alias ) : ''; } } diff --git a/src/DB/QueryBuilder/Concerns/FromClause.php b/src/DB/QueryBuilder/Concerns/FromClause.php index c0e4daf..78a6644 100644 --- a/src/DB/QueryBuilder/Concerns/FromClause.php +++ b/src/DB/QueryBuilder/Concerns/FromClause.php @@ -17,11 +17,11 @@ trait FromClause { /** * @param string|RawSQL $table - * @param string|null $alias + * @param string $alias * * @return $this */ - public function from( $table, $alias = null ) { + public function from( $table, $alias = '' ) { $this->froms[] = new From( $table, $alias ); return $this; diff --git a/src/DB/QueryBuilder/Concerns/JoinClause.php b/src/DB/QueryBuilder/Concerns/JoinClause.php index 0ba2fe7..b2032b3 100644 --- a/src/DB/QueryBuilder/Concerns/JoinClause.php +++ b/src/DB/QueryBuilder/Concerns/JoinClause.php @@ -36,11 +36,11 @@ public function join( $callback ) { * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string|null $alias + * @param string $alias * * @return static */ - public function leftJoin( $table, $column1, $column2, $alias = null ) { + public function leftJoin( $table, $column1, $column2, $alias = '' ) { $this->join( function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias ) { $builder @@ -56,11 +56,11 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string|null $alias + * @param string $alias * * @return static */ - public function innerJoin( $table, $column1, $column2, $alias = null ) { + public function innerJoin( $table, $column1, $column2, $alias = '' ) { $this->join( function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias ) { $builder @@ -76,11 +76,11 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string|null $alias + * @param string $alias * * @return static */ - public function rightJoin( $table, $column1, $column2, $alias = null ) { + public function rightJoin( $table, $column1, $column2, $alias = '' ) { $this->join( function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias ) { $builder diff --git a/src/DB/QueryBuilder/JoinQueryBuilder.php b/src/DB/QueryBuilder/JoinQueryBuilder.php index 27d2731..630e336 100644 --- a/src/DB/QueryBuilder/JoinQueryBuilder.php +++ b/src/DB/QueryBuilder/JoinQueryBuilder.php @@ -19,11 +19,11 @@ class JoinQueryBuilder { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string $alias * * @return $this */ - public function leftJoin( $table, $alias = null ) { + public function leftJoin( $table, $alias = '' ) { return $this->join( JoinType::LEFT, $table, @@ -33,11 +33,11 @@ public function leftJoin( $table, $alias = null ) { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string $alias * * @return $this */ - public function rightJoin( $table, $alias = null ) { + public function rightJoin( $table, $alias = '' ) { return $this->join( JoinType::RIGHT, $table, @@ -47,11 +47,11 @@ public function rightJoin( $table, $alias = null ) { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string $alias * * @return $this */ - public function innerJoin( $table, $alias = null ) { + public function innerJoin( $table, $alias = '' ) { return $this->join( JoinType::INNER, $table, From 2f50c7cb974f04799741b581547c070f0276a210 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 16:19:07 -0400 Subject: [PATCH 4/6] Allow null for phpstan --- src/DB/DB.php | 2 +- src/DB/QueryBuilder/Clauses/From.php | 2 +- src/DB/QueryBuilder/Clauses/Join.php | 2 +- src/DB/QueryBuilder/Clauses/Select.php | 2 +- src/DB/QueryBuilder/Concerns/FromClause.php | 2 +- src/DB/QueryBuilder/Concerns/JoinClause.php | 6 +++--- src/DB/QueryBuilder/JoinQueryBuilder.php | 10 +++++----- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/DB/DB.php b/src/DB/DB.php index a3d2758..491421a 100644 --- a/src/DB/DB.php +++ b/src/DB/DB.php @@ -173,7 +173,7 @@ public static function prefix( $tableName ) { * Create QueryBuilder instance * * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return QueryBuilder */ diff --git a/src/DB/QueryBuilder/Clauses/From.php b/src/DB/QueryBuilder/Clauses/From.php index 34ee338..ac45454 100644 --- a/src/DB/QueryBuilder/Clauses/From.php +++ b/src/DB/QueryBuilder/Clauses/From.php @@ -20,7 +20,7 @@ class From { /** * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias */ public function __construct( $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); diff --git a/src/DB/QueryBuilder/Clauses/Join.php b/src/DB/QueryBuilder/Clauses/Join.php index c2511d2..71e76d3 100644 --- a/src/DB/QueryBuilder/Clauses/Join.php +++ b/src/DB/QueryBuilder/Clauses/Join.php @@ -28,7 +28,7 @@ class Join { /** * @param string $table * @param string $joinType \StellarWP\DB\QueryBuilder\Types\JoinType - * @param string $alias + * @param null|string $alias */ public function __construct( $joinType, $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); diff --git a/src/DB/QueryBuilder/Clauses/Select.php b/src/DB/QueryBuilder/Clauses/Select.php index 468bfc4..74bee4a 100644 --- a/src/DB/QueryBuilder/Clauses/Select.php +++ b/src/DB/QueryBuilder/Clauses/Select.php @@ -18,7 +18,7 @@ class Select { /** * @param string $column - * @param string $alias + * @param null|string $alias */ public function __construct( $column, $alias = '' ) { $this->column = trim( $column ); diff --git a/src/DB/QueryBuilder/Concerns/FromClause.php b/src/DB/QueryBuilder/Concerns/FromClause.php index 78a6644..bb19e84 100644 --- a/src/DB/QueryBuilder/Concerns/FromClause.php +++ b/src/DB/QueryBuilder/Concerns/FromClause.php @@ -17,7 +17,7 @@ trait FromClause { /** * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return $this */ diff --git a/src/DB/QueryBuilder/Concerns/JoinClause.php b/src/DB/QueryBuilder/Concerns/JoinClause.php index b2032b3..06fe4d2 100644 --- a/src/DB/QueryBuilder/Concerns/JoinClause.php +++ b/src/DB/QueryBuilder/Concerns/JoinClause.php @@ -36,7 +36,7 @@ public function join( $callback ) { * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string $alias + * @param null|string $alias * * @return static */ @@ -56,7 +56,7 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string $alias + * @param null|string $alias * * @return static */ @@ -76,7 +76,7 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param string $alias + * @param null|string $alias * * @return static */ diff --git a/src/DB/QueryBuilder/JoinQueryBuilder.php b/src/DB/QueryBuilder/JoinQueryBuilder.php index 630e336..9270aa0 100644 --- a/src/DB/QueryBuilder/JoinQueryBuilder.php +++ b/src/DB/QueryBuilder/JoinQueryBuilder.php @@ -19,7 +19,7 @@ class JoinQueryBuilder { /** * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return $this */ @@ -33,7 +33,7 @@ public function leftJoin( $table, $alias = '' ) { /** * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return $this */ @@ -47,7 +47,7 @@ public function rightJoin( $table, $alias = '' ) { /** * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return $this */ @@ -122,11 +122,11 @@ public function joinRaw( $sql, ...$args ) { * * @param string $joinType * @param string|RawSQL $table - * @param string $alias + * @param null|string $alias * * @return $this */ - private function join( $joinType, $table, $alias ) { + private function join( $joinType, $table, $alias = '' ) { $this->joins[] = new Join( $joinType, $table, From 6c9cf63ab8eb75b19b1d19a5f1fc8fc98a94f5a2 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 16:24:01 -0400 Subject: [PATCH 5/6] string then null --- src/DB/DB.php | 2 +- src/DB/QueryBuilder/Clauses/From.php | 2 +- src/DB/QueryBuilder/Clauses/Join.php | 2 +- src/DB/QueryBuilder/Clauses/Select.php | 2 +- src/DB/QueryBuilder/Concerns/FromClause.php | 2 +- src/DB/QueryBuilder/Concerns/JoinClause.php | 6 +++--- src/DB/QueryBuilder/JoinQueryBuilder.php | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/DB/DB.php b/src/DB/DB.php index 491421a..f0cf42b 100644 --- a/src/DB/DB.php +++ b/src/DB/DB.php @@ -173,7 +173,7 @@ public static function prefix( $tableName ) { * Create QueryBuilder instance * * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return QueryBuilder */ diff --git a/src/DB/QueryBuilder/Clauses/From.php b/src/DB/QueryBuilder/Clauses/From.php index ac45454..4ac4674 100644 --- a/src/DB/QueryBuilder/Clauses/From.php +++ b/src/DB/QueryBuilder/Clauses/From.php @@ -20,7 +20,7 @@ class From { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias */ public function __construct( $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); diff --git a/src/DB/QueryBuilder/Clauses/Join.php b/src/DB/QueryBuilder/Clauses/Join.php index 71e76d3..63c640d 100644 --- a/src/DB/QueryBuilder/Clauses/Join.php +++ b/src/DB/QueryBuilder/Clauses/Join.php @@ -28,7 +28,7 @@ class Join { /** * @param string $table * @param string $joinType \StellarWP\DB\QueryBuilder\Types\JoinType - * @param null|string $alias + * @param string|null $alias */ public function __construct( $joinType, $table, $alias = '' ) { $this->table = QueryBuilder::prefixTable( $table ); diff --git a/src/DB/QueryBuilder/Clauses/Select.php b/src/DB/QueryBuilder/Clauses/Select.php index 74bee4a..74831cd 100644 --- a/src/DB/QueryBuilder/Clauses/Select.php +++ b/src/DB/QueryBuilder/Clauses/Select.php @@ -18,7 +18,7 @@ class Select { /** * @param string $column - * @param null|string $alias + * @param string|null $alias */ public function __construct( $column, $alias = '' ) { $this->column = trim( $column ); diff --git a/src/DB/QueryBuilder/Concerns/FromClause.php b/src/DB/QueryBuilder/Concerns/FromClause.php index bb19e84..21f079a 100644 --- a/src/DB/QueryBuilder/Concerns/FromClause.php +++ b/src/DB/QueryBuilder/Concerns/FromClause.php @@ -17,7 +17,7 @@ trait FromClause { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return $this */ diff --git a/src/DB/QueryBuilder/Concerns/JoinClause.php b/src/DB/QueryBuilder/Concerns/JoinClause.php index 06fe4d2..43c5978 100644 --- a/src/DB/QueryBuilder/Concerns/JoinClause.php +++ b/src/DB/QueryBuilder/Concerns/JoinClause.php @@ -36,7 +36,7 @@ public function join( $callback ) { * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param null|string $alias + * @param string|null $alias * * @return static */ @@ -56,7 +56,7 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param null|string $alias + * @param string|null $alias * * @return static */ @@ -76,7 +76,7 @@ function ( JoinQueryBuilder $builder ) use ( $table, $column1, $column2, $alias * @param string|RawSQL $table * @param string $column1 * @param string $column2 - * @param null|string $alias + * @param string|null $alias * * @return static */ diff --git a/src/DB/QueryBuilder/JoinQueryBuilder.php b/src/DB/QueryBuilder/JoinQueryBuilder.php index 9270aa0..a5a4499 100644 --- a/src/DB/QueryBuilder/JoinQueryBuilder.php +++ b/src/DB/QueryBuilder/JoinQueryBuilder.php @@ -19,7 +19,7 @@ class JoinQueryBuilder { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return $this */ @@ -33,7 +33,7 @@ public function leftJoin( $table, $alias = '' ) { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return $this */ @@ -47,7 +47,7 @@ public function rightJoin( $table, $alias = '' ) { /** * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return $this */ @@ -122,7 +122,7 @@ public function joinRaw( $sql, ...$args ) { * * @param string $joinType * @param string|RawSQL $table - * @param null|string $alias + * @param string|null $alias * * @return $this */ From 19f0fce05c3d0d184d9c8ab6cead4a44d2692352 Mon Sep 17 00:00:00 2001 From: Stephen Page Date: Mon, 23 Oct 2023 16:29:31 -0400 Subject: [PATCH 6/6] update changelog --- CHANGELOG.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cef213..ab5a35b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,23 @@ All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard. -## [1.0.4] 2023-10-23 +## [1.0.7] 2023-10-23 * Tweak - Updates around `trim()` for php 8.1 compatibility. -* Tweak - Force From() and Select() to convert passed non-strings to an empty string. -* Tweak - Convert all function signatures that take `$alias` as a param to use only `string` instead of `string|null`. +* Tweak - Force `From()` and `Select()` to convert passed non-strings to an empty string. + +## [1.0.6] 2023-09-05 + +* Tweak - Fix array shape for errors in `DatabaseQueryException` + +## [1.0.5] 2023-09-05 + +* Tweak - Updating docblock for `whereExists()` and `whereNotExists()` in response to a PHPStan flag. + +## [1.0.4] 2023-06-06 + +* Tweak - Added more documentation for methods provided by DB. +* Tweak - Adjusted docblocks to better declare types. ## [1.0.3] 2022-11-22