Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Builder/InsertUpdateStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function setMask(array $mask) {
*/
protected function buildFieldList(array $fields, array $query = array()) {
foreach ($fields as $fieldName => $fieldValue) {
if($fieldValue instanceof DefaultValue) {
if ($fieldValue instanceof DefaultValue) {
$fieldValue = 'DEFAULT';
}
if(is_array($this->mask) && !in_array($fieldName, $this->mask)) {
if (is_array($this->mask) && !in_array($fieldName, $this->mask)) {
continue;
}
if (is_int($fieldName)) {
if(is_array($fieldValue)) {
if (is_array($fieldValue)) {
$fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1));
}
$query[] = "\t{$fieldValue}";
Expand All @@ -55,10 +55,10 @@ protected function buildFieldList(array $fields, array $query = array()) {
* @return bool
*/
protected function isFieldAccessible($fieldName, array $tableFields) {
if(!in_array($fieldName, $tableFields)) {
if (!in_array($fieldName, $tableFields)) {
return false;
}
if(!is_array($this->mask)) {
if (!is_array($this->mask)) {
return true;
}
return in_array($fieldName, $this->mask);
Expand Down
16 changes: 8 additions & 8 deletions src/Builder/QueryStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function getStatement() {
* @return bool
*/
public function execute(array $params = []) {
return $this->exceptionHandler(function () use ($params) {
return $this->exceptionHandler(function() use ($params) {
$timer = microtime(true);
$response = $this->statement->execute($params);
$this->queryLoggers->log($this->query, microtime(true) - $timer);
$this->queryLoggers->log($this->query, microtime(true)-$timer);
return $response;
});
}
Expand All @@ -56,7 +56,7 @@ public function execute(array $params = []) {
*/
public function fetchAll() {
$args = func_get_args();
return $this->exceptionHandler(function () use ($args) {
return $this->exceptionHandler(function() use ($args) {
return call_user_func_array([$this->statement, 'fetchAll'], $args);
});
}
Expand All @@ -68,7 +68,7 @@ public function fetchAll() {
* @return mixed
*/
public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) {
return $this->exceptionHandler(function () use ($fetchStyle, $cursorOrientation, $cursorOffset) {
return $this->exceptionHandler(function() use ($fetchStyle, $cursorOrientation, $cursorOffset) {
return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset);
});
}
Expand All @@ -78,7 +78,7 @@ public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::
* @return mixed
*/
public function fetchColumn($columnNo = 0) {
return $this->exceptionHandler(function () use ($columnNo) {
return $this->exceptionHandler(function() use ($columnNo) {
return $this->statement->fetchColumn($columnNo);
});
}
Expand All @@ -87,7 +87,7 @@ public function fetchColumn($columnNo = 0) {
* @return bool
*/
public function closeCursor() {
return $this->exceptionHandler(function () {
return $this->exceptionHandler(function() {
return $this->statement->closeCursor();
});
}
Expand All @@ -96,7 +96,7 @@ public function closeCursor() {
* @return int
*/
public function columnCount() {
return $this->exceptionHandler(function () {
return $this->exceptionHandler(function() {
return $this->statement->columnCount();
});
}
Expand All @@ -106,7 +106,7 @@ public function columnCount() {
* @return array
*/
public function getColumnMeta($columnNo) {
return $this->exceptionHandler(function () use ($columnNo) {
return $this->exceptionHandler(function() use ($columnNo) {
return $this->statement->getColumnMeta($columnNo);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/RunnableInsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class RunnableInsert extends Insert implements DDLPreparable {
* @return int[] Insert IDs
*/
public function insertRows($rows) {
if(!(is_array($rows) || $rows instanceof Traversable)) {
if (!(is_array($rows) || $rows instanceof Traversable)) {
throw new BadMethodCallException('Expected $rows to by an array or an instance of \\Traversable');
}
$result = [];
$query = $this->__toString();
$stmt = $this->db()->prepare($query);
foreach($rows as $row) {
foreach ($rows as $row) {
$stmt->execute($row);
$result[] = (int) $this->db()->getLastInsertId();
}
Expand All @@ -33,7 +33,7 @@ public function insertRows($rows) {
* @return DDLRunnable
*/
public function prepare() {
return $this->createPreparable($this->db()->prepare($this), function () {
return $this->createPreparable($this->db()->prepare($this), function() {
return (int) $this->db()->getLastInsertId();
});
}
Expand Down
22 changes: 11 additions & 11 deletions src/Builder/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ class Select extends Statement {
* @return $this
*/
public function field($expression, $alias = null) {
if(is_object($expression)) {
if (is_object($expression)) {
$expression = (string) $expression;
$expression = trim($expression);
$expression = rtrim($expression, ';');
$expression = trim($expression);
$lines = explode("\n", $expression);
$lines = array_map(function ($line) { return "\t\t{$line}"; }, $lines);
$lines = array_map(function($line) { return "\t\t{$line}"; }, $lines);
$expression = join("\n", $lines);
$expression = sprintf("(\n%s\n\t)", $expression);
}
if($alias === null) {
if ($alias === null) {
$this->fields[] = $expression;
} else {
$this->fields[$alias] = $expression;
Expand All @@ -60,7 +60,7 @@ public function field($expression, $alias = null) {
* @return $this
*/
public function fields(array $fields) {
foreach($fields as $alias => $expression) {
foreach ($fields as $alias => $expression) {
$this->field($expression, $alias);
}
return $this;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function getCalcFoundRows() {
* @return $this
*/
public function setCalcFoundRows($calcFoundRows = true) {
if(ini_get("mysql.trace_mode")) {
if (ini_get("mysql.trace_mode")) {
throw new \Exception('This function cant operate with mysql.trace_mode is set.');
}
$this->calcFoundRows = $calcFoundRows;
Expand All @@ -117,12 +117,12 @@ public function from($alias, $tableName = null) {
*/
public function __toString() {
$query = "SELECT";
if($this->calcFoundRows) {
if ($this->calcFoundRows) {
$query .= " SQL_CALC_FOUND_ROWS";
}
$query .= "\n";
$query = $this->buildFields($query);
if(count($this->getTables())) {
if (count($this->getTables())) {
$query .= "FROM\n";
}
$query = $this->buildTables($query);
Expand All @@ -144,9 +144,9 @@ public function __toString() {
*/
private function buildFields($query) {
$fields = array();
if(count($this->fields)) {
foreach($this->fields as $alias => $expression) {
if(is_numeric($alias)) {
if (count($this->fields)) {
foreach ($this->fields as $alias => $expression) {
if (is_numeric($alias)) {
$fields[] = "\t{$expression}";
} else {
$fields[] = "\t{$expression} AS `{$alias}`";
Expand All @@ -163,7 +163,7 @@ private function buildFields($query) {
* @return string
*/
private function buildForUpdate($query) {
if($this->forUpdate) {
if ($this->forUpdate) {
$query .= "FOR UPDATE\n";
}
return $query;
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function __construct(MySQL $db) {
* @return $this
*/
public function debug($stop = true) {
if(php_sapi_name() == 'cli') {
if (php_sapi_name() == 'cli') {
echo "\n{$this->__toString()}\n";
} else {
echo "<pre>{$this->__toString()}</pre>";
}
if($stop) {
if ($stop) {
exit;
}
return $this;
Expand Down
16 changes: 8 additions & 8 deletions src/Builder/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public function setExpr($expr) {
* @throws Exception
*/
public function setAll(array $data, array $allowedFields = null) {
if($allowedFields !== null) {
foreach($data as $fieldName => $value) {
if(in_array($fieldName, $allowedFields)) {
if ($allowedFields !== null) {
foreach ($data as $fieldName => $value) {
if (in_array($fieldName, $allowedFields)) {
$this->set($fieldName, $value);
}
}
} else {
$values = $this->clearValues($data);
foreach($values as $fieldName => $value) {
foreach ($values as $fieldName => $value) {
$this->set($fieldName, $value);
}
}
Expand Down Expand Up @@ -125,14 +125,14 @@ private function buildAssignments($query) {
* @throws Exception
*/
private function clearValues(array $values) {
if(!count($values)) {
if (!count($values)) {
return [];
}
$tables = $this->getTables();
if(!count($tables)) {
if (!count($tables)) {
throw new Exception('Table name is missing');
}
if(count($tables) > 1) {
if (count($tables) > 1) {
throw new Exception('Batch values only work with max. one table');
}
list($table) = $tables;
Expand All @@ -142,7 +142,7 @@ private function clearValues(array $values) {
$result = array();

foreach ($values as $fieldName => $fieldValue) {
if(in_array($fieldName, $fields)) {
if (in_array($fieldName, $fields)) {
$result[$fieldName] = $fieldValue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/QueryLogger/QueryLoggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function add(QueryLogger $queryLogger) {
* @return $this
*/
public function log($query, $duration) {
foreach($this->queryLoggers as $queryLogger) {
foreach ($this->queryLoggers as $queryLogger) {
$queryLogger->log($query, $duration);
}
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/AliasRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function add($alias, $string) {
* @return string
*/
public function get($alias) {
if(!array_key_exists($alias, $this->aliases)) {
if (!array_key_exists($alias, $this->aliases)) {
throw new \Exception("Alias not found: {$alias}");
}
return $this->aliases[$alias];
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/AliasReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function __construct(AliasRegistry $aliasRegistry) {
* @return string
*/
public function replace($name) {
$fn = function ($values) {
$fn = function($values) {
$alias = $values[1];
$part = $values[2];
$string = $this->aliasRegistry->get($alias);
return $string . $part;
return $string.$part;
};
return preg_replace_callback('/^(\\w+)#(\\w+)$/', $fn, $name);
}
Expand Down