@@ -60,19 +60,19 @@ discard block |
||
| 60 | 60 | * @return array[] |
| 61 | 61 | */ |
| 62 | 62 | public function fetchRows(Closure $callback = null) { |
| 63 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback) { |
|
| 63 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback) { |
|
| 64 | 64 | $data = $statement->fetchAll(\PDO::FETCH_ASSOC); |
| 65 | - if($this->preserveTypes) { |
|
| 65 | + if ($this->preserveTypes) { |
|
| 66 | 66 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 67 | - foreach($data as &$row) { |
|
| 67 | + foreach ($data as &$row) { |
|
| 68 | 68 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | - if($callback !== null) { |
|
| 71 | + if ($callback !== null) { |
|
| 72 | 72 | $resultData = []; |
| 73 | - foreach($data as $row) { |
|
| 73 | + foreach ($data as $row) { |
|
| 74 | 74 | $result = $callback($row); |
| 75 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 75 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 76 | 76 | $resultData[] = $result; |
| 77 | 77 | } else { |
| 78 | 78 | $resultData[] = $row; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return array[]|\Generator |
| 90 | 90 | */ |
| 91 | 91 | public function fetchRowsLazy(Closure $callback = null) { |
| 92 | - if(version_compare(PHP_VERSION, '5.5', '<')) { |
|
| 92 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
| 93 | 93 | return $this->fetchRows($callback); |
| 94 | 94 | } |
| 95 | 95 | $statement = $this->createStatement(); |
@@ -103,18 +103,18 @@ discard block |
||
| 103 | 103 | * @throws \Exception |
| 104 | 104 | */ |
| 105 | 105 | public function fetchRow(Closure $callback = null) { |
| 106 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback) { |
|
| 106 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback) { |
|
| 107 | 107 | $row = $statement->fetch(\PDO::FETCH_ASSOC); |
| 108 | - if(!is_array($row)) { |
|
| 108 | + if (!is_array($row)) { |
|
| 109 | 109 | return []; |
| 110 | 110 | } |
| 111 | - if($this->preserveTypes) { |
|
| 111 | + if ($this->preserveTypes) { |
|
| 112 | 112 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 113 | 113 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 114 | 114 | } |
| 115 | - if($callback !== null) { |
|
| 115 | + if ($callback !== null) { |
|
| 116 | 116 | $result = $callback($row); |
| 117 | - if($result !== null) { |
|
| 117 | + if ($result !== null) { |
|
| 118 | 118 | $row = $result; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | * @return mixed[] |
| 128 | 128 | */ |
| 129 | 129 | public function fetchKeyValue($treatValueAsArray = false) { |
| 130 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
| 131 | - if($treatValueAsArray) { |
|
| 130 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
| 131 | + if ($treatValueAsArray) { |
|
| 132 | 132 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
| 133 | 133 | $result = array(); |
| 134 | - foreach($rows as $row) { |
|
| 134 | + foreach ($rows as $row) { |
|
| 135 | 135 | list($key) = array_values($row); |
| 136 | 136 | $result[$key] = $row; |
| 137 | 137 | } |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | public function fetchGroups(array $fields) { |
| 149 | 149 | $rows = $this->fetchRows(); |
| 150 | 150 | $result = array(); |
| 151 | - foreach($rows as $row) { |
|
| 151 | + foreach ($rows as $row) { |
|
| 152 | 152 | $tmp = &$result; |
| 153 | - foreach($fields as $field) { |
|
| 153 | + foreach ($fields as $field) { |
|
| 154 | 154 | $value = $row[$field]; |
| 155 | - if(!array_key_exists($value, $tmp)) { |
|
| 155 | + if (!array_key_exists($value, $tmp)) { |
|
| 156 | 156 | $tmp[$value] = []; |
| 157 | 157 | } |
| 158 | 158 | $tmp = &$tmp[$value]; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @return string[] |
| 167 | 167 | */ |
| 168 | 168 | public function fetchArray() { |
| 169 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
| 169 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
| 170 | 170 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
| 171 | 171 | }); |
| 172 | 172 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * @return null|bool|string|int|float |
| 177 | 177 | */ |
| 178 | 178 | public function fetchValue($default = null) { |
| 179 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
| 179 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
| 180 | 180 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
| 181 | - if($result !== false) { |
|
| 181 | + if ($result !== false) { |
|
| 182 | 182 | return $result[0]; |
| 183 | 183 | } |
| 184 | 184 | return $default; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $query = $this->__toString(); |
| 219 | 219 | $statement = $db->prepare($query); |
| 220 | 220 | $statement->execute($this->values); |
| 221 | - if($this->getCalcFoundRows()) { |
|
| 221 | + if ($this->getCalcFoundRows()) { |
|
| 222 | 222 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
| 223 | 223 | } |
| 224 | 224 | return $statement; |
@@ -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(\PDO::FETCH_ASSOC)) { |
|
| 25 | - if($this->preserveTypes) { |
|
| 24 | + while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { |
|
| 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; |