Skip to content

Commit

Permalink
fix: rector rules
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Dec 9, 2021
1 parent d1dac19 commit 04e3dbf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function valueDefault($value)
*/
public function getValueDefault()
{
if (isset($this->valueDefault)) {
if ($this->valueDefault !== null) {
return $this->valueDefault;
}
if ($this->isNullable) {
Expand Down Expand Up @@ -202,7 +202,7 @@ public function toArray(): array
if ($this->comment !== null) {
$data[ '_comment' ] = $this->comment;
}
if (isset($this->valueDefault)) {
if ($this->valueDefault !== null) {
$data[ 'default' ] = $this->valueDefault;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Field/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function filterValue($value)
*/
public function getValueDefault()
{
if (isset($this->valueDefault)) {
if ($this->valueDefault !== null) {
if ($this->valueDefault === static::CURRENT_DEFAULT) {
return date(static::FORMAT, time());
}
Expand Down
18 changes: 9 additions & 9 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __toString(): string
} else {
$output .= sprintf('SELECT %s ', $this->columnNames ? addslashes(implode(', ', $this->columnNames)) : '*');
}
if ($this->from) {
if ($this->from !== '') {
$output .= sprintf('FROM %s ', addslashes($this->from));
}
foreach ($this->joins as $value) {
Expand All @@ -92,7 +92,7 @@ public function __toString(): string
(string) $value[ 'where' ]
);
}
if ($this->where) {
if ($this->where !== null) {
$output .= sprintf('WHERE %s ', (string) $this->where);
}
foreach ($this->unions as $union) {
Expand All @@ -111,10 +111,10 @@ public function __toString(): string
}
$output = trim($output, ', ') . ' ';
}
if ($this->limit) {
if ($this->limit !== 0) {
$output .= sprintf('LIMIT %d ', (string) $this->limit);
}
if ($this->offset) {
if ($this->offset !== 0) {
$output .= sprintf('OFFSET %d ', (string) $this->offset);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ public function fetch(): array
{
$fetch = $this->limit(1)->fetchAll();

return $fetch
return $fetch !== []
? $fetch[ 0 ]
: [];
}
Expand Down Expand Up @@ -384,7 +384,7 @@ protected function executeJoins(string $type, string $tableName, Where $where):
* Si aucun resultat n'est trouvé alors la ligne est remplie
* avec les colonnes de la table jointe avec des valeurs null.
*/
if ($addRow === false) {
if (!$addRow) {
$result[] = array_merge($rowTableNull, $row);
}
}
Expand Down Expand Up @@ -600,11 +600,11 @@ private function filterWhere(): void
}

/* Merge les colonnes des conditions de la requête courante. */
if ($this->where) {
if ($this->where !== null) {
$columnNames = array_merge($columnNames, $this->where->getColumnNames());
}

if ($columnNames) {
if ($columnNames !== []) {
$this->diffColumnNames($columnNames);
}
}
Expand Down Expand Up @@ -670,7 +670,7 @@ private function diffColumnNames(array $columnNames): void
$this->allFieldsSchema
);

if ($diff) {
if ($diff !== []) {
$columnsDiff = array_flip($diff);

throw new ColumnsNotFoundException(
Expand Down
3 changes: 1 addition & 2 deletions src/Where.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ protected static function predicate($column, string $operator, $value): bool
case '!==':
return $column !== $value;
case '!=':
return $column != $value;
case '<>':
return $column <> $value;
return $column != $value;
case '<':
return $column < $value;
case '<=':
Expand Down
12 changes: 6 additions & 6 deletions src/WhereHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function where(

$type = __FUNCTION__;

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];

return $this;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public function between(
$type = __FUNCTION__;
$value = [ 'min' => $min, 'max' => $max ];

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];

return $this;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ public function in(
$condition = 'in';
$type = __FUNCTION__;

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];

return $this;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public function isNull(
$type = __FUNCTION__;
$value = null;

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];

return $this;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ public function regex(
$condition = 'regex';
$type = __FUNCTION__;

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];

return $this;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ protected function like(
$type = __FUNCTION__;
$condition = 'regex';

$this->where[] = compact('bool', 'columnName', 'condition', 'not', 'type', 'value');
$this->where[] = ['bool' => $bool, 'columnName' => $columnName, 'condition' => $condition, 'not' => $not, 'type' => $type, 'value' => $value];
}

/**
Expand Down
21 changes: 5 additions & 16 deletions tests/unit/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,7 @@ public function testUnion(): void
->union($union);

self::assertEquals(
'SELECT name FROM user '
. 'UNION '
. 'SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
'SELECT name FROM user UNION SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
(string) $data
);
self::assertEquals(
Expand Down Expand Up @@ -1505,9 +1503,7 @@ public function testUnionMultiple(): void
->union($union);

self::assertEquals(
'SELECT name, firstname FROM user '
. 'UNION '
. 'SELECT name, firstname FROM user WHERE id BETWEEN 1 AND 5;',
'SELECT name, firstname FROM user UNION SELECT name, firstname FROM user WHERE id BETWEEN 1 AND 5;',
(string) $data
);
self::assertEquals(
Expand Down Expand Up @@ -1555,9 +1551,7 @@ public function testUnionAll(): void
->unionAll($union);

self::assertEquals(
'SELECT name FROM user '
. 'UNION ALL '
. 'SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
'SELECT name FROM user UNION ALL SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
(string) $data
);
self::assertEquals(
Expand Down Expand Up @@ -1647,9 +1641,7 @@ public function testUnionList(): void
->union($union);

self::assertEquals(
'SELECT name FROM user '
. 'UNION '
. 'SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
'SELECT name FROM user UNION SELECT name FROM user WHERE id BETWEEN 1 AND 5;',
(string) $data
);
self::assertEquals(
Expand Down Expand Up @@ -1679,10 +1671,7 @@ public function testUnionListOrder(): void
->orderBy('name');

self::assertEquals(
'SELECT name FROM user '
. 'UNION '
. 'SELECT name FROM user WHERE id BETWEEN 1 AND 5 '
. 'ORDER BY name ASC;',
'SELECT name FROM user UNION SELECT name FROM user WHERE id BETWEEN 1 AND 5 ORDER BY name ASC;',
(string) $data
);
self::assertEquals(
Expand Down

0 comments on commit 04e3dbf

Please sign in to comment.