@@ -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; |
@@ -21,16 +21,16 @@ |
||
| 21 | 21 | * @return array[]|\Generator |
| 22 | 22 | */ |
| 23 | 23 | public function generate(QueryStatement $statement, Closure $callback = null) { |
| 24 | - while($row = $statement->fetch()) { |
|
| 25 | - if($this->preserveTypes) { |
|
| 24 | + while ($row = $statement->fetch()) { |
|
| 25 | + if ($this->preserveTypes) { |
|
| 26 | 26 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 27 | 27 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 28 | 28 | } |
| 29 | - if($callback !== null) { |
|
| 29 | + if ($callback !== null) { |
|
| 30 | 30 | $result = $callback($row); |
| 31 | - if($result instanceof DBIgnoreRow) { |
|
| 31 | + if ($result instanceof DBIgnoreRow) { |
|
| 32 | 32 | // Do nothing in this case |
| 33 | - } elseif($result !== null) { |
|
| 33 | + } elseif ($result !== null) { |
|
| 34 | 34 | yield $result; |
| 35 | 35 | } else { |
| 36 | 36 | yield $row; |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * @return $this |
| 47 | 47 | */ |
| 48 | 48 | public function setFetchMode($mode, $arg0 = null, array $arg1 = null) { |
| 49 | - if($arg1 !== null) { |
|
| 49 | + if ($arg1 !== null) { |
|
| 50 | 50 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
| 51 | 51 | $this->statement->setFetchMode($mode, $arg0, $arg1); |
| 52 | 52 | return $this; |
| 53 | 53 | } |
| 54 | - if($arg0 !== null) { |
|
| 54 | + if ($arg0 !== null) { |
|
| 55 | 55 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
| 56 | 56 | $this->statement->setFetchMode($mode, $arg0); |
| 57 | 57 | return $this; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $timer = microtime(true); |
| 71 | 71 | $response = $this->statement->execute($params); |
| 72 | 72 | $this->queryLoggers->log($this->query, microtime(true)-$timer); |
| 73 | - if(!$response) { |
|
| 73 | + if (!$response) { |
|
| 74 | 74 | throw new SqlException('Execution returned with "false".'); |
| 75 | 75 | } |
| 76 | 76 | }); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function fetchAll($fetchStyle = null, $fetchArgument = null, array $ctorArgs = []) { |
| 87 | 87 | return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
| 88 | - if($fetchArgument !== null) { |
|
| 88 | + if ($fetchArgument !== null) { |
|
| 89 | 89 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); |
| 90 | 90 | } |
| 91 | 91 | return $this->statement->fetchAll($fetchStyle); |