diff --git a/src/Query/Traits/HavingTrait.php b/src/Query/Traits/HavingTrait.php index fea63800..fa987a83 100644 --- a/src/Query/Traits/HavingTrait.php +++ b/src/Query/Traits/HavingTrait.php @@ -86,18 +86,18 @@ public function orHaving(...$args): self /** * Convert various amount of where function arguments into valid where token. * - * @param string $boolean Boolean joiner (AND | OR). + * @param string $boolean Boolean joiner (AND | OR). * @param array $params Set of parameters collected from where functions. - * @param array $tokens Array to aggregate compiled tokens. Reference. + * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential * parameter. * * @throws BuilderException */ abstract protected function registerToken( - $boolean, + string $boolean, array $params, - &$tokens, + array &$tokens, callable $wrapper ); diff --git a/src/Query/Traits/JoinTrait.php b/src/Query/Traits/JoinTrait.php index c8bb712a..fb11e48b 100644 --- a/src/Query/Traits/JoinTrait.php +++ b/src/Query/Traits/JoinTrait.php @@ -91,7 +91,7 @@ public function join($type, $outer, string $alias = null, $on = null): self 'on' => [] ]; - return call_user_func_array([$this, 'on'], array_slice(func_get_args(), 2)); + return $on === null ? $this : $this->on(...$on); } /** @@ -333,18 +333,18 @@ public function orOnWhere(...$args): self /** * Convert various amount of where function arguments into valid where token. * - * @param string $boolean Boolean joiner (AND | OR). + * @param string $boolean Boolean joiner (AND | OR). * @param array $params Set of parameters collected from where functions. - * @param array $tokens Array to aggregate compiled tokens. Reference. + * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential * parameter. * * @throws BuilderException */ abstract protected function registerToken( - $boolean, + string $boolean, array $params, - &$tokens, + array &$tokens, callable $wrapper ); diff --git a/src/Query/Traits/TokenTrait.php b/src/Query/Traits/TokenTrait.php index 991614af..eee86019 100644 --- a/src/Query/Traits/TokenTrait.php +++ b/src/Query/Traits/TokenTrait.php @@ -21,15 +21,15 @@ trait TokenTrait /** * Convert various amount of where function arguments into valid where token. * - * @param string $boolean Boolean joiner (AND | OR). + * @param string $boolean Boolean joiner (AND | OR). * @param array $params Set of parameters collected from where functions. - * @param array $tokens Array to aggregate compiled tokens. Reference. + * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential * parameter. * * @throws BuilderException */ - protected function registerToken($boolean, array $params, &$tokens, callable $wrapper): void + protected function registerToken(string $boolean, array $params, array &$tokens, callable $wrapper): void { $count = count($params); if ($count === 0) { diff --git a/src/Query/Traits/WhereTrait.php b/src/Query/Traits/WhereTrait.php index 1745af8f..2f0b3386 100644 --- a/src/Query/Traits/WhereTrait.php +++ b/src/Query/Traits/WhereTrait.php @@ -85,17 +85,18 @@ public function orWhere(...$args): self /** * Convert various amount of where function arguments into valid where token. * - * @param string $boolean Boolean joiner (AND | OR). + * @param string $boolean Boolean joiner (AND | OR). * @param array $params Set of parameters collected from where functions. - * @param array $tokens Array to aggregate compiled tokens. Reference. + * @param array $tokens Array to aggregate compiled tokens. Reference. * @param callable $wrapper Callback or closure used to wrap/collect every potential * parameter. + * * @throws BuilderException */ abstract protected function registerToken( - $boolean, + string $boolean, array $params, - &$tokens, + array &$tokens, callable $wrapper ); diff --git a/tests/Database/SelectQueryTest.php b/tests/Database/SelectQueryTest.php index 501a159a..84badb86 100644 --- a/tests/Database/SelectQueryTest.php +++ b/tests/Database/SelectQueryTest.php @@ -2042,6 +2042,43 @@ public function testLeftJoin3(): void ); } + public function testLeftJoin4(): void + { + $select = $this->database->select() + ->from(['users']) + ->join('LEFT', 'photos', 'pht', ['pht.user_id', 'users.id']); + + $this->assertSameQuery( + 'SELECT * FROM {users} LEFT JOIN {photos} AS {pht} ON {pht}.{user_id} = {users}.{id}', + $select + ); + } + + // Todo: make this case valid + // public function testLeftJoin5(): void + // { + // $select = $this->database->select() + // ->from(['users']) + // ->join('LEFT', 'photos', 'pht', ['@AND' => ['pht.user_id' => 'users.id']]); + // + // $this->assertSameQuery( + // 'SELECT * FROM {users} LEFT JOIN {photos} AS {pht} ON {pht}.{user_id} = {users}.{id}', + // $select + // ); + // } + + public function testLeftJoin6(): void + { + $select = $this->database->select() + ->from(['users']) + ->join('LEFT', 'photos', 'pht', [['pht.user_id' => 'users.id']]); + + $this->assertSameQuery( + 'SELECT * FROM {users} LEFT JOIN {photos} AS {pht} ON {pht}.{user_id} = {users}.{id}', + $select + ); + } + public function testRightJoin0(): void { $select = $this->database->select()