Skip to content

Commit

Permalink
Fix 3: Better naming var, fix phpdoc, code style. (#386)
Browse files Browse the repository at this point in the history
* Fix 3: Better naming var, fix phpdoc, code style.
  • Loading branch information
terabytesoftw committed Nov 19, 2022
1 parent 9d2b63c commit 3836fa9
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Constraint/DefaultValueConstraint.php
Expand Up @@ -9,7 +9,7 @@
*/
final class DefaultValueConstraint extends Constraint
{
private mixed $value;
private mixed $value = null;

public function getValue(): mixed
{
Expand Down
5 changes: 3 additions & 2 deletions src/Driver/PDO/ConnectionPDO.php
Expand Up @@ -143,8 +143,9 @@ public function getActivePDO(string|null $sql = '', bool|null $forRead = null):
public function getLastInsertID(string $sequenceName = null): string
{
if ($this->isActive() && $this->pdo) {
return $this->pdo->lastInsertID($sequenceName === null
? null : $this->getQuoter()->quoteTableName($sequenceName));
return $this->pdo->lastInsertID(
$sequenceName === null ? null : $this->getQuoter()->quoteTableName($sequenceName)
);
}

throw new InvalidCallException('DB Connection is not active.');
Expand Down
38 changes: 21 additions & 17 deletions src/QueryBuilder/Conditions/BetweenColumnsCondition.php
Expand Up @@ -83,48 +83,52 @@ public static function fromArrayDefinition(string $operator, array $operands): s

private static function validateValue(
string $operator,
mixed $operand
mixed $value
): array|int|string|Iterator|ExpressionInterface {
if (
!is_array($operand) &&
!is_int($operand) &&
!is_string($operand) &&
!($operand instanceof Iterator) &&
!($operand instanceof ExpressionInterface)
!is_array($value) &&
!is_int($value) &&
!is_string($value) &&
!($value instanceof Iterator) &&
!($value instanceof ExpressionInterface)
) {
throw new InvalidArgumentException(
"Operator '$operator' requires value to be array, int, string, Iterator or ExpressionInterface."
);
}

return $operand;
return $value;
}

private static function validateIntervalStartColumn(string $operator, mixed $operand): string|ExpressionInterface
{
private static function validateIntervalStartColumn(
string $operator,
mixed $intervalStartColumn
): string|ExpressionInterface {
if (
!is_string($operand) &&
!($operand instanceof ExpressionInterface)
!is_string($intervalStartColumn) &&
!($intervalStartColumn instanceof ExpressionInterface)
) {
throw new InvalidArgumentException(
"Operator '$operator' requires interval start column to be string or ExpressionInterface."
);
}

return $operand;
return $intervalStartColumn;
}

private static function validateIntervalEndColumn(string $operator, mixed $operand): string|ExpressionInterface
{
private static function validateIntervalEndColumn(
string $operator,
mixed $intervalEndColumn
): string|ExpressionInterface {
if (
!is_string($operand) &&
!($operand instanceof ExpressionInterface)
!is_string($intervalEndColumn) &&
!($intervalEndColumn instanceof ExpressionInterface)
) {
throw new InvalidArgumentException(
"Operator '$operator' requires interval end column to be string or ExpressionInterface."
);
}

return $operand;
return $intervalEndColumn;
}
}
6 changes: 3 additions & 3 deletions src/QueryBuilder/Conditions/BetweenCondition.php
Expand Up @@ -53,14 +53,14 @@ public static function fromArrayDefinition(string $operator, array $operands): s
return new self(self::validateColumn($operator, $operands[0]), $operator, $operands[1], $operands[2]);
}

private static function validateColumn(string $operator, mixed $operand): string|Expression
private static function validateColumn(string $operator, mixed $column): string|Expression
{
if (!is_string($operand) && !($operand instanceof Expression)) {
if (!is_string($column) && !($column instanceof Expression)) {
throw new InvalidArgumentException(
"Operator '$operator' requires column to be string or ExpressionInterface."
);
}

return $operand;
return $column;
}
}
12 changes: 6 additions & 6 deletions src/QueryBuilder/Conditions/InCondition.php
Expand Up @@ -52,23 +52,23 @@ public static function fromArrayDefinition(string $operator, array $operands): s
);
}

private static function validateColumn(string $operator, mixed $operand): array|string|Iterator
private static function validateColumn(string $operator, mixed $column): array|string|Iterator
{
if (!is_string($operand) && !is_array($operand) && !$operand instanceof Iterator) {
if (!is_string($column) && !is_array($column) && !$column instanceof Iterator) {
throw new InvalidArgumentException("Operator '$operator' requires column to be string, array or Iterator.");
}

return $operand;
return $column;
}

private static function validateValues(string $operator, mixed $operand): int|iterable|Iterator|QueryInterface
private static function validateValues(string $operator, mixed $values): int|iterable|Iterator|QueryInterface
{
if (!is_array($operand) && !$operand instanceof Iterator && !is_int($operand) && !$operand instanceof QueryInterface) {
if (!is_array($values) && !$values instanceof Iterator && !is_int($values) && !$values instanceof QueryInterface) {
throw new InvalidArgumentException(
"Operator '$operator' requires values to be array, Iterator, int or QueryInterface."
);
}

return $operand;
return $values;
}
}
22 changes: 11 additions & 11 deletions src/QueryBuilder/Conditions/LikeCondition.php
Expand Up @@ -71,32 +71,32 @@ public static function fromArrayDefinition(string $operator, array $operands): s
return $condition;
}

private static function validateColumn(string $operator, mixed $operand): string|Expression
private static function validateColumn(string $operator, mixed $column): string|Expression
{
if (!is_string($operand) && !$operand instanceof Expression) {
if (!is_string($column) && !$column instanceof Expression) {
throw new InvalidArgumentException("Operator '$operator' requires column to be string or Expression.");
}

return $operand;
return $column;
}

private static function validateValue(
string $operator,
mixed $operand
mixed $value
): array|int|string|Iterator|ExpressionInterface|null {
if (
!is_string($operand) &&
!is_array($operand) &&
!is_int($operand) &&
!$operand instanceof Iterator &&
!$operand instanceof ExpressionInterface &&
$operand !== null
!is_string($value) &&
!is_array($value) &&
!is_int($value) &&
!$value instanceof Iterator &&
!$value instanceof ExpressionInterface &&
$value !== null
) {
throw new InvalidArgumentException(
"Operator '$operator' requires value to be string, array, Iterator or ExpressionInterface."
);
}

return $operand;
return $value;
}
}
18 changes: 9 additions & 9 deletions src/QueryBuilder/Conditions/NotCondition.php
Expand Up @@ -33,26 +33,26 @@ public static function fromArrayDefinition(string $operator, array $operands): s
return new self(self::validateCondition($operator, $operands));
}

private static function validateCondition(string $operator, array $operands): ExpressionInterface|array|null|string
private static function validateCondition(string $operator, array $condition): ExpressionInterface|array|null|string
{
if (count($operands) !== 1) {
if (count($condition) !== 1) {
throw new InvalidArgumentException("Operator '$operator' requires exactly one operand.");
}

/** @var mixed $operands */
$operands = array_shift($operands);
/** @var mixed $condition */
$condition = array_shift($condition);

if (
!is_array($operands) &&
!($operands instanceof ExpressionInterface) &&
!is_string($operands) &&
$operands !== null
!is_array($condition) &&
!($condition instanceof ExpressionInterface) &&
!is_string($condition) &&
$condition !== null
) {
throw new InvalidArgumentException(
"Operator '$operator' requires condition to be array, string, null or ExpressionInterface."
);
}

return $operands;
return $condition;
}
}
6 changes: 3 additions & 3 deletions src/QueryBuilder/DDLQueryBuilderInterface.php
Expand Up @@ -146,9 +146,9 @@ public function addUnique(string $name, string $table, array|string $columns): s
* @param string $table the table whose column is to be changed. The table name will be properly quoted by the
* method.
* @param string $column the name of the column to be changed. The name will be properly quoted by the method.
* @param ColumnSchemaBuilder|string $type the new column type. The {@see getColumnType()} method will be invoked to convert abstract
* column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept
* in the generated SQL.
* @param ColumnSchemaBuilder|string $type the new column type. The {@see getColumnType()} method will be invoked
* to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type
* will be kept in the generated SQL.
*
* For example, 'string' will be turned into 'varchar(255)', while 'string not null'
* will become 'varchar(255) not null'.
Expand Down

0 comments on commit 3836fa9

Please sign in to comment.