@@ -21,7 +21,7 @@ |
||
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | 23 | protected function buildOffset($query) { |
| 24 | - if($this->offset !== null) { |
|
| 24 | + if ($this->offset !== null) { |
|
| 25 | 25 | $query .= "OFFSET\n\t{$this->offset}\n"; |
| 26 | 26 | } |
| 27 | 27 | return $query; |
@@ -30,21 +30,21 @@ |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | protected function buildUnions($query) { |
| 33 | - $wrap = function ($query) { |
|
| 33 | + $wrap = function($query) { |
|
| 34 | 34 | $query = trim($query); |
| 35 | 35 | $query = join("\n\t", explode("\n", $query)); |
| 36 | 36 | return sprintf("(\n\t%s\n)", $query); |
| 37 | 37 | }; |
| 38 | 38 | $queries = [$wrap($query)]; |
| 39 | - foreach($this->unions as $unionQuery) { |
|
| 40 | - if($unionQuery[0] === 'ALL') { |
|
| 39 | + foreach ($this->unions as $unionQuery) { |
|
| 40 | + if ($unionQuery[0] === 'ALL') { |
|
| 41 | 41 | $queries[] = 'UNION ALL'; |
| 42 | 42 | } else { |
| 43 | 43 | $queries[] = 'UNION'; |
| 44 | 44 | } |
| 45 | 45 | $queries[] = $wrap($unionQuery[1]); |
| 46 | 46 | } |
| 47 | - if(count($queries) > 1) { |
|
| 47 | + if (count($queries) > 1) { |
|
| 48 | 48 | return join(" ", $queries); |
| 49 | 49 | } |
| 50 | 50 | return $query; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function from($alias, $table = null) { |
| 32 | - if($table !== null) { |
|
| 32 | + if ($table !== null) { |
|
| 33 | 33 | $this->aliases[] = $alias; |
| 34 | 34 | } |
| 35 | 35 | $this->addTable($alias, $table); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function __toString() { |
| 44 | 44 | $query = "DELETE "; |
| 45 | 45 | $query .= join(', ', $this->aliases); |
| 46 | - $query = trim($query) . " FROM\n"; |
|
| 46 | + $query = trim($query)." FROM\n"; |
|
| 47 | 47 | $query = $this->buildTables($query); |
| 48 | 48 | $query = $this->buildJoins($query); |
| 49 | 49 | $query = $this->buildWhereConditions($query); |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | * @return array |
| 9 | 9 | */ |
| 10 | 10 | public static function convertValues(array $row, array $columnDefinitions) { |
| 11 | - foreach($row as $key => &$value) { |
|
| 12 | - if($value !== null) { |
|
| 11 | + foreach ($row as $key => &$value) { |
|
| 12 | + if ($value !== null) { |
|
| 13 | 13 | $value = self::convertValue($value, $columnDefinitions[$key]); |
| 14 | 14 | } |
| 15 | 15 | } |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | * @return string |
| 13 | 13 | */ |
| 14 | 14 | public static function build(Database $db, $query, array $conditions, $token) { |
| 15 | - if(!count($conditions)) { |
|
| 15 | + if (!count($conditions)) { |
|
| 16 | 16 | return $query; |
| 17 | 17 | } |
| 18 | 18 | $query .= "{$token}\n"; |
| 19 | 19 | $arr = []; |
| 20 | - foreach($conditions as $condition) { |
|
| 20 | + foreach ($conditions as $condition) { |
|
| 21 | 21 | list($expression, $arguments) = $condition; |
| 22 | - if(is_array($expression)) { |
|
| 23 | - foreach($expression as $key => $value) { |
|
| 22 | + if (is_array($expression)) { |
|
| 23 | + foreach ($expression as $key => $value) { |
|
| 24 | 24 | $arr = self::buildCondition($arr, "`{$key}`=?", [$value], $db); |
| 25 | 25 | } |
| 26 | 26 | } else { |
@@ -27,8 +27,8 @@ |
||
| 27 | 27 | * @return DBExprFilter |
| 28 | 28 | */ |
| 29 | 29 | public function __invoke($expression, $keyPath, $validator = null) { |
| 30 | - return new DBExprFilter($expression, $this->map, $keyPath, $validator, function ($result, array $data) { |
|
| 31 | - if(!$result) { |
|
| 30 | + return new DBExprFilter($expression, $this->map, $keyPath, $validator, function($result, array $data) { |
|
| 31 | + if (!$result) { |
|
| 32 | 32 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key'])); |
| 33 | 33 | } |
| 34 | 34 | }); |
@@ -28,10 +28,10 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | protected function buildLimit($query, $offset = null) { |
| 30 | 30 | $limit = $this->limit; |
| 31 | - if($limit === null && $offset !== null) { |
|
| 31 | + if ($limit === null && $offset !== null) { |
|
| 32 | 32 | $limit = '18446744073709551615'; |
| 33 | 33 | } |
| 34 | - if($limit !== null) { |
|
| 34 | + if ($limit !== null) { |
|
| 35 | 35 | $query .= "LIMIT\n\t{$limit}\n"; |
| 36 | 36 | } |
| 37 | 37 | return $query; |
@@ -11,16 +11,16 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | public function __construct($spec, $sortFieldsSpec) { |
| 13 | 13 | $expressions = []; |
| 14 | - foreach($spec as $specReference => $dbExpr) { |
|
| 15 | - if(is_int($specReference)) { |
|
| 14 | + foreach ($spec as $specReference => $dbExpr) { |
|
| 15 | + if (is_int($specReference)) { |
|
| 16 | 16 | $specReference = $dbExpr; |
| 17 | 17 | } |
| 18 | 18 | $expressions[$specReference] = $dbExpr; |
| 19 | 19 | } |
| 20 | - foreach($sortFieldsSpec as $sortFieldSpec) { |
|
| 21 | - if(array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
| 20 | + foreach ($sortFieldsSpec as $sortFieldSpec) { |
|
| 21 | + if (array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
| 22 | 22 | $direction = 'ASC'; |
| 23 | - if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
| 23 | + if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
| 24 | 24 | $direction = 'DESC'; |
| 25 | 25 | } |
| 26 | 26 | $this->fields[] = [ |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | * @return $this |
| 17 | 17 | */ |
| 18 | 18 | public function having($expression, $_ = null) { |
| 19 | - if($expression instanceof OptionalExpression) { |
|
| 20 | - if($expression->isValid()) { |
|
| 19 | + if ($expression instanceof OptionalExpression) { |
|
| 20 | + if ($expression->isValid()) { |
|
| 21 | 21 | $this->having[] = [$expression->getExpression(), $expression->getValue()]; |
| 22 | 22 | } |
| 23 | 23 | } else { |