diff --git a/src/Builder/InsertUpdateStatement.php b/src/Builder/InsertUpdateStatement.php index ac4634d..f62db76 100644 --- a/src/Builder/InsertUpdateStatement.php +++ b/src/Builder/InsertUpdateStatement.php @@ -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}"; @@ -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); diff --git a/src/Builder/QueryStatement.php b/src/Builder/QueryStatement.php index c5b75d2..930b264 100644 --- a/src/Builder/QueryStatement.php +++ b/src/Builder/QueryStatement.php @@ -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; }); } @@ -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); }); } @@ -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); }); } @@ -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); }); } @@ -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(); }); } @@ -96,7 +96,7 @@ public function closeCursor() { * @return int */ public function columnCount() { - return $this->exceptionHandler(function () { + return $this->exceptionHandler(function() { return $this->statement->columnCount(); }); } @@ -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); }); } diff --git a/src/Builder/RunnableInsert.php b/src/Builder/RunnableInsert.php index 4f5874a..7f12c16 100644 --- a/src/Builder/RunnableInsert.php +++ b/src/Builder/RunnableInsert.php @@ -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(); } @@ -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(); }); } diff --git a/src/Builder/Select.php b/src/Builder/Select.php index a3984f7..ccd3b74 100644 --- a/src/Builder/Select.php +++ b/src/Builder/Select.php @@ -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; @@ -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; @@ -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; @@ -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); @@ -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}`"; @@ -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; diff --git a/src/Builder/Statement.php b/src/Builder/Statement.php index 6bbcaa1..a4038ea 100644 --- a/src/Builder/Statement.php +++ b/src/Builder/Statement.php @@ -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 "
{$this->__toString()}
"; } - if($stop) { + if ($stop) { exit; } return $this; diff --git a/src/Builder/Update.php b/src/Builder/Update.php index 356edbc..c51e471 100644 --- a/src/Builder/Update.php +++ b/src/Builder/Update.php @@ -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); } } @@ -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; @@ -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; } } diff --git a/src/QueryLogger/QueryLoggers.php b/src/QueryLogger/QueryLoggers.php index 020d113..1125411 100644 --- a/src/QueryLogger/QueryLoggers.php +++ b/src/QueryLogger/QueryLoggers.php @@ -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; diff --git a/src/Tools/AliasRegistry.php b/src/Tools/AliasRegistry.php index 9b5d60c..ab84447 100644 --- a/src/Tools/AliasRegistry.php +++ b/src/Tools/AliasRegistry.php @@ -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]; diff --git a/src/Tools/AliasReplacer.php b/src/Tools/AliasReplacer.php index 1bfa513..27ae772 100644 --- a/src/Tools/AliasReplacer.php +++ b/src/Tools/AliasReplacer.php @@ -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); }