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,