@@ -12,28 +12,28 @@ |
||
12 | 12 | * @return string |
13 | 13 | */ |
14 | 14 | protected function buildTableName($alias, $name) { |
15 | - if(is_object($name)) { |
|
15 | + if (is_object($name)) { |
|
16 | 16 | $name = (string) $name; |
17 | 17 | $lines = explode("\n", $name); |
18 | - foreach($lines as &$line) { |
|
18 | + foreach ($lines as &$line) { |
|
19 | 19 | $line = "\t{$line}"; |
20 | 20 | } |
21 | 21 | $name = join("\n", $lines); |
22 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
22 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
23 | 23 | } |
24 | - if(is_array($name)) { |
|
24 | + if (is_array($name)) { |
|
25 | 25 | $parts = []; |
26 | - foreach($name as $bucket) { |
|
26 | + foreach ($name as $bucket) { |
|
27 | 27 | $values = []; |
28 | - foreach($bucket as $field => $value) { |
|
28 | + foreach ($bucket as $field => $value) { |
|
29 | 29 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
30 | 30 | } |
31 | 31 | $parts[] = sprintf("SELECT %s", join(', ', $values)); |
32 | 32 | } |
33 | - $name = '(' . join("\n\tUNION\n\t", $parts) . ')'; |
|
33 | + $name = '('.join("\n\tUNION\n\t", $parts).')'; |
|
34 | 34 | } |
35 | 35 | $name = $this->aliasReplacer()->replace($name); |
36 | - if($alias !== null) { |
|
36 | + if ($alias !== null) { |
|
37 | 37 | return sprintf("%s %s", $name, $alias); |
38 | 38 | } |
39 | 39 | return $name; |
@@ -16,8 +16,8 @@ |
||
16 | 16 | * @return $this |
17 | 17 | */ |
18 | 18 | public function having($expression) { |
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 { |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @return $this |
16 | 16 | */ |
17 | 17 | public function orderBy($expression, $direction = 'asc') { |
18 | - if($expression instanceof OrderBySpecification) { |
|
19 | - foreach($expression->getFields() as $field) { |
|
18 | + if ($expression instanceof OrderBySpecification) { |
|
19 | + foreach ($expression->getFields() as $field) { |
|
20 | 20 | $this->addOrder($field[0], $field[1]); |
21 | 21 | } |
22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function orderByValues($fieldName, array $values) { |
34 | 34 | $expr = []; |
35 | - foreach(array_values($values) as $idx => $value) { |
|
35 | + foreach (array_values($values) as $idx => $value) { |
|
36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", array($value, $idx)); |
37 | 37 | } |
38 | 38 | $this->orderBy[] = array(sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC'); |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return string |
45 | 45 | */ |
46 | 46 | protected function buildOrder($query) { |
47 | - if(!count($this->orderBy)) { |
|
47 | + if (!count($this->orderBy)) { |
|
48 | 48 | return $query; |
49 | 49 | } |
50 | 50 | $query .= "ORDER BY\n"; |
51 | 51 | $arr = array(); |
52 | - foreach($this->orderBy as $order) { |
|
52 | + foreach ($this->orderBy as $order) { |
|
53 | 53 | list($expression, $direction) = $order; |
54 | 54 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
55 | 55 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function addOrder($expression, $direction) { |
64 | 64 | $direction = $this->fixDirection($direction); |
65 | - if(is_array($expression)) { |
|
66 | - if(!count($expression)) { |
|
65 | + if (is_array($expression)) { |
|
66 | + if (!count($expression)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | $arguments = array( |
@@ -16,8 +16,8 @@ |
||
16 | 16 | * @return $this |
17 | 17 | */ |
18 | 18 | public function where($expression) { |
19 | - if($expression instanceof OptionalExpression) { |
|
20 | - if($expression->isValid()) { |
|
19 | + if ($expression instanceof OptionalExpression) { |
|
20 | + if ($expression->isValid()) { |
|
21 | 21 | $this->where[] = [$expression->getExpression(), $expression->getValue()]; |
22 | 22 | } |
23 | 23 | } else { |
@@ -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,14 +16,14 @@ |
||
16 | 16 | public function throwMoreConcreteException(PDOException $exception) { |
17 | 17 | $code = $exception->getCode(); |
18 | 18 | $message = (string) $exception->getMessage(); |
19 | - switch($code) { |
|
19 | + switch ($code) { |
|
20 | 20 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
21 | 21 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
22 | 22 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
23 | 23 | case 1062: throw new DuplicateUniqueKeyException($message, $code, $exception); |
24 | 24 | } |
25 | 25 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
26 | - if(!is_string($message) || !is_int($code)) { |
|
26 | + if (!is_string($message) || !is_int($code)) { |
|
27 | 27 | throw new SqlException((string) $message, (int) $code, $exception); |
28 | 28 | } |
29 | 29 | throw $exception; |