Skip to content

Commit

Permalink
Merge branch 'bugfix/psalm' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
StulE-ru committed Aug 29, 2023
2 parents 61a1a2b + d5ac822 commit f84949b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Actions/AlterTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function addColumns(array $fields): self
/**
* Adds fields to rename.
*
* @param string[] $names array of names
* @param array<string, string> $names array of names
*/
public function renameColumns(array $names): self
{
Expand Down
7 changes: 4 additions & 3 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public function columnCount(): int
public function fetchColumn(int $column = 0): mixed
{
try {
$column = $this->statement?->fetchColumn($column) ?? false;
/** @var mixed */
$result = $this->statement?->fetchColumn($column) ?? false;
} catch (\Throwable $th) {
$column = false;
$result = false;
}

return $column;
return $result;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ColumnsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
trait ColumnsTrait
{
/**
* @var (string|BaseFunction)[] column names
* @var array<int|string, string|BaseFunction> column names
*/
protected array $columns = [];

Expand Down Expand Up @@ -56,7 +56,7 @@ protected function columnsPlaceholders(): array
/**
* Set columns.
*
* @param (string|BaseFunction)[] $columns array of column names
* @param array<int|string, string|BaseFunction> $columns array of column names
*
* @return $this
*/
Expand Down
25 changes: 19 additions & 6 deletions src/Traits/OnTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
trait OnTrait
{
/**
* @var array<int, array{type: string, name: string, sign: string, value: mixed}> on conditions
* @var list<array{type: string, name: string, sign: string, value: scalar|null|ScalarFunction|Condition}> on conditions
*/
protected array $on = [];

Expand All @@ -41,7 +41,7 @@ protected function onQuery(Escaper $escaper): string
$value = '?';
}*/

$query .= $type . ' ' . $escaper->column($name) . $sign . $value . ' ';
$query .= $type . ' ' . $escaper->column($name) . $sign . $escaper->column(strval($value)) . ' ';
}

return trim($query);
Expand Down Expand Up @@ -73,8 +73,13 @@ protected function onPlaceholders(): array

/**
* Adds condition to list.
*
* @param string $type
* @param string $name
* @param string $sign
* @param scalar|null|ScalarFunction|Condition $value
*/
protected function addOnCondition(string $type, string $name, string $sign, mixed $value): void
protected function addOnCondition(string $type, string $name, string $sign, string|int|float|bool|null|ScalarFunction|Condition $value): void
{
$this->on[] = [
'type' => $type,
Expand All @@ -87,6 +92,10 @@ protected function addOnCondition(string $type, string $name, string $sign, mixe
/**
* Set first condition.
*
* @param string $name
* @param scalar|null|ScalarFunction|Condition $value
* @param string $sign
*
* !!! ATTENTION !!!
* Method think that $value is name of table like 'join_table.id'
* and do not prepare it. So be careful with sql-injections.
Expand All @@ -96,7 +105,7 @@ protected function addOnCondition(string $type, string $name, string $sign, mixe
*
* @return $this
*/
public function on(string $name, mixed $value, string $sign = '='): object
public function on(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand All @@ -110,6 +119,10 @@ public function on(string $name, mixed $value, string $sign = '='): object
/**
* Adds 'and' condition.
*
* @param string $name
* @param scalar|null|ScalarFunction|Condition $value
* @param string $sign
*
* !!! ATTENTION !!!
* Method think that $value is name of table like 'join_table.id'
* and do not prepare it. So be careful with sql-injections.
Expand All @@ -119,7 +132,7 @@ public function on(string $name, mixed $value, string $sign = '='): object
*
* @return $this
*/
public function onAnd(string $name, mixed $value, string $sign = '='): object
public function onAnd(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand All @@ -146,7 +159,7 @@ public function onAnd(string $name, mixed $value, string $sign = '='): object
*
* @return $this
*/
public function onOr(string $name, mixed $value, string $sign = '='): object
public function onOr(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/SetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
trait SetTrait
{
/**
* @var array<string, mixed> values for SET
* @var array<string, scalar|null|ScalarFunction> values for SET
*/
protected array $set = [];

Expand Down Expand Up @@ -58,7 +58,7 @@ protected function setPlaceholders(): array
/**
* Set values for SET.
*
* @param array<string, mixed> $values array of values for SET
* @param array<string, scalar|null|ScalarFunction> $values array of values for SET
*
* @return $this
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ValuesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
trait ValuesTrait
{
/**
* @var list<list<mixed>> values for VALUES
* @var list<list<scalar|null|ScalarFunction>> values for VALUES
*/
protected array $values = [];

Expand Down Expand Up @@ -63,7 +63,7 @@ protected function valuesPlaceholders(): array
/**
* Set values for VALUES.
*
* @param list<list<mixed>> $values values for VALUES
* @param list<list<scalar|null|ScalarFunction>> $values values for VALUES
*
* @return $this
*/
Expand Down
27 changes: 22 additions & 5 deletions src/Traits/WhereTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait WhereTrait
{
/**
* @var array<int, array{type: string, name: string, sign: string, value: mixed}> where conditions
* @var list<array{type: string, name: string, sign: string, value: scalar|null|ScalarFunction|Condition}> where conditions
*/
protected array $where = [];

Expand Down Expand Up @@ -70,8 +70,13 @@ protected function wherePlaceholders(): array

/**
* Adds condition to list.
*
* @param string $type
* @param string $name
* @param string $sign
* @param scalar|null|ScalarFunction|Condition $value
*/
protected function addCondition(string $type, string $name, string $sign, mixed $value): void
protected function addCondition(string $type, string $name, string $sign, string|int|float|bool|null|ScalarFunction|Condition $value): void
{
$this->where[] = [
'type' => $type,
Expand All @@ -84,12 +89,16 @@ protected function addCondition(string $type, string $name, string $sign, mixed
/**
* Set first condition.
*
* @param string $name
* @param scalar|null|ScalarFunction|Condition $value
* @param string $sign
*
* $value can be subclass of Condition (In, Beetween, etc.)
* If $value is subclass of Condition $sign will be ignored.
*
* @return $this
*/
public function where(string $name, mixed $value, string $sign = '='): object
public function where(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand All @@ -103,12 +112,16 @@ public function where(string $name, mixed $value, string $sign = '='): object
/**
* Adds 'and' condition.
*
* @param string $name
* @param scalar|null|ScalarFunction|Condition $value
* @param string $sign
*
* $value can be subclass of Condition (In, Beetween, etc.)
* If $value is subclass of Condition $sign will be ignored.
*
* @return $this
*/
public function and(string $name, mixed $value, string $sign = '='): object
public function and(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand All @@ -126,12 +139,16 @@ public function and(string $name, mixed $value, string $sign = '='): object
/**
* Adds 'or' condition.
*
* @param string $name
* @param scalar|null|ScalarFunction|Condition $value
* @param string $sign
*
* $value can be subclass of Condition (In, Beetween, etc.)
* If $value is subclass of Condition $sign will be ignored.
*
* @return $this
*/
public function or(string $name, mixed $value, string $sign = '='): object
public function or(string $name, string|int|float|bool|null|ScalarFunction|Condition $value, string $sign = '='): object
{
if (empty($name)) {
return $this;
Expand Down

0 comments on commit f84949b

Please sign in to comment.