Skip to content

Commit

Permalink
Update with some suggestions and some extrapolation from those.
Browse files Browse the repository at this point in the history
  • Loading branch information
Camwyn committed Oct 23, 2023
1 parent 2c8b078 commit e44274b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions src/DB/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
6 changes: 3 additions & 3 deletions src/DB/QueryBuilder/Clauses/From.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) : '';

Check failure on line 27 in src/DB/QueryBuilder/Clauses/From.php

View workflow job for this annotation

GitHub Actions / phpstan

Else branch is unreachable because ternary operator condition is always true.
}
}
6 changes: 3 additions & 3 deletions src/DB/QueryBuilder/Clauses/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) : '';

Check failure on line 36 in src/DB/QueryBuilder/Clauses/Join.php

View workflow job for this annotation

GitHub Actions / phpstan

Else branch is unreachable because ternary operator condition is always true.
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/DB/QueryBuilder/Clauses/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) : '';

Check failure on line 25 in src/DB/QueryBuilder/Clauses/Select.php

View workflow job for this annotation

GitHub Actions / phpstan

Else branch is unreachable because ternary operator condition is always true.
}
}
4 changes: 2 additions & 2 deletions src/DB/QueryBuilder/Concerns/FromClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/DB/QueryBuilder/Concerns/JoinClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/DB/QueryBuilder/JoinQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit e44274b

Please sign in to comment.