@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | list($state, $code, $message) = $errorInfo; |
| 56 | 56 | $functs = [ |
| 57 | 57 | // violation: column cannot be null |
| 58 | - 1048 => function ($message) { |
|
| 58 | + 1048 => function($message) { |
|
| 59 | 59 | preg_match("#Column '(.+)' cannot be null#", $message, $m); |
| 60 | 60 | return ['FIELD_REQUIRED', $m[1]]; |
| 61 | 61 | }, |
| 62 | 62 | |
| 63 | - 1054 => function ($message) { |
|
| 63 | + 1054 => function($message) { |
|
| 64 | 64 | return ['COLUMN_DOES_NOT_EXIST', $message]; |
| 65 | 65 | }, |
| 66 | 66 | |
| 67 | 67 | // violation: duplicate key |
| 68 | - 1062 => function ($message) { |
|
| 68 | + 1062 => function($message) { |
|
| 69 | 69 | if (preg_match("#'([^']+)' for key '([^']+)'#", $message, $m)) { |
| 70 | 70 | $entry = $m[1]; |
| 71 | 71 | $key = $m[2]; |
@@ -79,25 +79,25 @@ discard block |
||
| 79 | 79 | return ["DUPLICATE_KEY:".$m[1]]; |
| 80 | 80 | }, |
| 81 | 81 | |
| 82 | - 1064 => function ($message) { |
|
| 82 | + 1064 => function($message) { |
|
| 83 | 83 | preg_match("#right syntax to use near '(.+)'#", $message, $m); |
| 84 | 84 | return ['SYNTAX_ERROR', $m[1]]; |
| 85 | 85 | }, |
| 86 | 86 | |
| 87 | - 1146 => function ($message) { |
|
| 87 | + 1146 => function($message) { |
|
| 88 | 88 | return ['TABLE_DOES_NOT_EXIST', $message]; |
| 89 | 89 | }, |
| 90 | 90 | |
| 91 | - 1264 => function ($message) { |
|
| 91 | + 1264 => function($message) { |
|
| 92 | 92 | preg_match("#for column '(.+)'#", $message, $m); |
| 93 | 93 | return ['VALUE_OUT_OF_RANGE', $m[1]]; |
| 94 | 94 | }, |
| 95 | 95 | |
| 96 | - 1364 => function ($message) { |
|
| 96 | + 1364 => function($message) { |
|
| 97 | 97 | return ['FIELD_REQUIRED', $message]; |
| 98 | 98 | }, |
| 99 | 99 | |
| 100 | - 1451 => function ($message) { |
|
| 100 | + 1451 => function($message) { |
|
| 101 | 101 | preg_match("#CONSTRAINT `(.+)` FOREIGN#", $message, $m); |
| 102 | 102 | return ['RELATIONAL_INTEGRITY', $m[1]]; |
| 103 | 103 | }, |
@@ -106,6 +106,6 @@ discard block |
||
| 106 | 106 | if (isset($functs[$code])) |
| 107 | 107 | return [call_user_func($functs[$code], $message), $code]; |
| 108 | 108 | |
| 109 | - return ['FUBAR #' . $state . '-' . $code . '-' . $message, $code]; |
|
| 109 | + return ['FUBAR #'.$state.'-'.$code.'-'.$message, $code]; |
|
| 110 | 110 | } |
| 111 | 111 | } |
@@ -20,19 +20,22 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | $errorInfo = null; |
| 22 | 22 | |
| 23 | - if (!$query->isSuccess()) |
|
| 24 | - $errorInfo = $query->errorInfo(); |
|
| 25 | - elseif ($exception !== null) |
|
| 26 | - $errorInfo = $exception->errorInfo; |
|
| 23 | + if (!$query->isSuccess()) { |
|
| 24 | + $errorInfo = $query->errorInfo(); |
|
| 25 | + } elseif ($exception !== null) { |
|
| 26 | + $errorInfo = $exception->errorInfo; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | - if (!is_array($errorInfo)) |
|
| 29 | - return new CruditesException('ERROR_INFO_UNAVAILABLE', 0, $exception); |
|
| 29 | + if (!is_array($errorInfo)) { |
|
| 30 | + return new CruditesException('ERROR_INFO_UNAVAILABLE', 0, $exception); |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | list($message, $code) = self::transcript($errorInfo); |
| 32 | 34 | |
| 33 | 35 | // TODO: losing the parsing work from transcript. IMPROVE |
| 34 | - if (is_array($message)) |
|
| 35 | - $message = array_shift($message); |
|
| 36 | + if (is_array($message)) { |
|
| 37 | + $message = array_shift($message); |
|
| 38 | + } |
|
| 36 | 39 | |
| 37 | 40 | return new CruditesException($message, $code, null); // exception could reveal database credentials |
| 38 | 41 | } |
@@ -103,8 +106,9 @@ discard block |
||
| 103 | 106 | }, |
| 104 | 107 | |
| 105 | 108 | ]; |
| 106 | - if (isset($functs[$code])) |
|
| 107 | - return [call_user_func($functs[$code], $message), $code]; |
|
| 109 | + if (isset($functs[$code])) { |
|
| 110 | + return [call_user_func($functs[$code], $message), $code]; |
|
| 111 | + } |
|
| 108 | 112 | |
| 109 | 113 | return ['FUBAR #' . $state . '-' . $code . '-' . $message, $code]; |
| 110 | 114 | } |
@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | $this->message = $message; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function __toString(){ |
|
| 19 | + public function __toString() { |
|
| 20 | 20 | $ret = $this->message; |
| 21 | 21 | |
| 22 | - if(!empty($this->table)) |
|
| 22 | + if (!empty($this->table)) |
|
| 23 | 23 | $ret .= sprintf(' on table "%s"', $this->table); |
| 24 | - if(!empty($this->columns)) |
|
| 24 | + if (!empty($this->columns)) |
|
| 25 | 25 | $ret .= sprintf(' on column(s) "%s"', implode('", "', $this->columns)); |
| 26 | 26 | |
| 27 | 27 | return $ret; |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | $errorInfo = null; |
| 33 | 33 | |
| 34 | - if(method_exists($something_PDO, 'errorInfo')) |
|
| 34 | + if (method_exists($something_PDO, 'errorInfo')) |
|
| 35 | 35 | $errorInfo = $something_PDO->errorInfo(); |
| 36 | - elseif(property_exists($something_PDO, 'errorInfo')) |
|
| 36 | + elseif (property_exists($something_PDO, 'errorInfo')) |
|
| 37 | 37 | $errorInfo = $something_PDO->errorInfo; |
| 38 | 38 | else |
| 39 | 39 | throw new \InvalidArgumentException('INVALID_PDO_CLASS'); |
@@ -19,10 +19,12 @@ discard block |
||
| 19 | 19 | public function __toString(){ |
| 20 | 20 | $ret = $this->message; |
| 21 | 21 | |
| 22 | - if(!empty($this->table)) |
|
| 23 | - $ret .= sprintf(' on table "%s"', $this->table); |
|
| 24 | - if(!empty($this->columns)) |
|
| 25 | - $ret .= sprintf(' on column(s) "%s"', implode('", "', $this->columns)); |
|
| 22 | + if(!empty($this->table)) { |
|
| 23 | + $ret .= sprintf(' on table "%s"', $this->table); |
|
| 24 | + } |
|
| 25 | + if(!empty($this->columns)) { |
|
| 26 | + $ret .= sprintf(' on column(s) "%s"', implode('", "', $this->columns)); |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | return $ret; |
| 28 | 30 | } |
@@ -31,12 +33,13 @@ discard block |
||
| 31 | 33 | { |
| 32 | 34 | $errorInfo = null; |
| 33 | 35 | |
| 34 | - if(method_exists($something_PDO, 'errorInfo')) |
|
| 35 | - $errorInfo = $something_PDO->errorInfo(); |
|
| 36 | - elseif(property_exists($something_PDO, 'errorInfo')) |
|
| 37 | - $errorInfo = $something_PDO->errorInfo; |
|
| 38 | - else |
|
| 39 | - throw new \InvalidArgumentException('INVALID_PDO_CLASS'); |
|
| 36 | + if(method_exists($something_PDO, 'errorInfo')) { |
|
| 37 | + $errorInfo = $something_PDO->errorInfo(); |
|
| 38 | + } elseif(property_exists($something_PDO, 'errorInfo')) { |
|
| 39 | + $errorInfo = $something_PDO->errorInfo; |
|
| 40 | + } else { |
|
| 41 | + throw new \InvalidArgumentException('INVALID_PDO_CLASS'); |
|
| 42 | + } |
|
| 40 | 43 | |
| 41 | 44 | // 0: the SQLSTATE associated with the last operation on the database handle |
| 42 | 45 | $this->setState($errorInfo[0] ?? null); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $select->selectAlso(['count' => ['COUNT(*)']]); |
| 56 | 56 | $res = $select->retCol(); |
| 57 | 57 | if (is_array($res)) { |
| 58 | - return (int) current($res); |
|
| 58 | + return (int)current($res); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return null; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $res->execute($dat_ass); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - return $res instanceof \PDOStatement? $res : null; |
|
| 99 | + return $res instanceof \PDOStatement ? $res : null; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public static function distinctFor(string $table, string $column_name, string $filter_by_value = null) |
@@ -153,8 +153,8 @@ |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | - * @return array<string,string> an array of errors, column name => message |
|
| 157 | - */ |
|
| 156 | + * @return array<string,string> an array of errors, column name => message |
|
| 157 | + */ |
|
| 158 | 158 | public function persist(): array |
| 159 | 159 | { |
| 160 | 160 | if (!$this->isNew() && !$this->isAltered()) { // existing record with no alterations |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | public function __toString() |
| 53 | 53 | { |
| 54 | - return PHP_EOL . 'load: ' |
|
| 54 | + return PHP_EOL.'load: ' |
|
| 55 | 55 | . json_encode($this->load) |
| 56 | - . PHP_EOL . 'alterations: ' |
|
| 56 | + . PHP_EOL.'alterations: ' |
|
| 57 | 57 | . json_encode(array_keys($this->alterations)); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // replaces empty strings with null or default value |
| 152 | - if (trim('' . $datass[$field_name]) === '' && $attributes->nullable()) { |
|
| 152 | + if (trim(''.$datass[$field_name]) === '' && $attributes->nullable()) { |
|
| 153 | 153 | $datass[$field_name] = $attributes->nullable() ? null : $attributes->default(); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $unique_match = $this->schema->matchUniqueness($this->table, $this->load); |
| 209 | 209 | |
| 210 | - if(empty($unique_match)){ |
|
| 210 | + if (empty($unique_match)) { |
|
| 211 | 211 | throw new CruditesException('UNIQUE_MATCH_NOT_FOUND'); |
| 212 | 212 | } |
| 213 | 213 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $this->where ??= []; |
| 29 | 29 | $this->where[] = sprintf('(%s)', $where_condition); |
| 30 | 30 | |
| 31 | - if(!empty($bindings)){ |
|
| 31 | + if (!empty($bindings)) { |
|
| 32 | 32 | $this->bindings = array_merge($this->bindings, $bindings); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | return $this->wherePredicate($p); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - private function predicateColumn($column, $table=null): array |
|
| 120 | + private function predicateColumn($column, $table = null): array |
|
| 121 | 121 | { |
| 122 | 122 | return [$this->tableLabel($table), $column]; |
| 123 | 123 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | protected function generateWhere() |
| 222 | 222 | { |
| 223 | 223 | if (!empty($this->where)) { |
| 224 | - return PHP_EOL . ' WHERE ' . implode(PHP_EOL . ' AND ', $this->where); |
|
| 224 | + return PHP_EOL.' WHERE '.implode(PHP_EOL.' AND ', $this->where); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function addJoinedTable($join_table_name, $join_table_alias) |
| 26 | 26 | { |
| 27 | - if(!isset($this->joined_tables[$join_table_alias])){ |
|
| 27 | + if (!isset($this->joined_tables[$join_table_alias])) { |
|
| 28 | 28 | $this->joined_tables[$join_table_alias] = $join_table_name; |
| 29 | 29 | } |
| 30 | - elseif ($this->joined_tables[$join_table_alias] !== $join_table_name){ |
|
| 30 | + elseif ($this->joined_tables[$join_table_alias] !== $join_table_name) { |
|
| 31 | 31 | throw new \InvalidArgumentException(sprintf(__FUNCTION__.'(): ALIAS `%s` ALREADY ALLOCATED FOR TABLE `%s`', $join_table_alias, $join_table_name)); |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function join($table_names, $joins, $join_type = '') |
| 37 | 37 | { |
| 38 | - list($join_table_name,$join_table_alias) = self::processParamTableNames($table_names); |
|
| 38 | + list($join_table_name, $join_table_alias) = self::processParamTableNames($table_names); |
|
| 39 | 39 | |
| 40 | 40 | if (preg_match('#^(INNER|LEFT|RIGHT|FULL)(\sOUTER)?#i', $join_type) !== 1) { |
| 41 | 41 | $join_type = ''; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | // 3 join params -> t.f = v |
| 76 | - else{ |
|
| 76 | + else { |
|
| 77 | 77 | $value = $join_field[0]; |
| 78 | 78 | // join bind label |
| 79 | 79 | |
@@ -26,8 +26,7 @@ |
||
| 26 | 26 | { |
| 27 | 27 | if(!isset($this->joined_tables[$join_table_alias])){ |
| 28 | 28 | $this->joined_tables[$join_table_alias] = $join_table_name; |
| 29 | - } |
|
| 30 | - elseif ($this->joined_tables[$join_table_alias] !== $join_table_name){ |
|
| 29 | + } elseif ($this->joined_tables[$join_table_alias] !== $join_table_name){ |
|
| 31 | 30 | throw new \InvalidArgumentException(sprintf(__FUNCTION__.'(): ALIAS `%s` ALREADY ALLOCATED FOR TABLE `%s`', $join_table_alias, $join_table_name)); |
| 32 | 31 | } |
| 33 | 32 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | if (empty($this->bindings)) { |
| 31 | 31 | unset($dbg['bindings']); |
| 32 | 32 | } |
| 33 | - else{ |
|
| 33 | + else { |
|
| 34 | 34 | $dbg['bindings'] = json_encode($dbg['bindings']); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | public function bindLabel($field, $table_name = null): string |
| 128 | 128 | { |
| 129 | - return ':' . $this->tableLabel($table_name) . '_' . $field; |
|
| 129 | + return ':'.$this->tableLabel($table_name).'_'.$field; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | public function addBindings($assoc_data): array |
@@ -33,8 +33,7 @@ |
||
| 33 | 33 | |
| 34 | 34 | if (empty($this->bindings)) { |
| 35 | 35 | unset($dbg['bindings']); |
| 36 | - } |
|
| 37 | - else{ |
|
| 36 | + } else{ |
|
| 38 | 37 | $dbg['bindings'] = json_encode($dbg['bindings']); |
| 39 | 38 | } |
| 40 | 39 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | $fields = $this->getBindingNames(); |
| 27 | 27 | $fields = array_keys($fields[$this->table]); |
| 28 | 28 | |
| 29 | - $fields = '`' . implode('`, `', $fields) . '`'; |
|
| 29 | + $fields = '`'.implode('`, `', $fields).'`'; |
|
| 30 | 30 | $bindings = implode(', ', array_keys($this->bindings())); |
| 31 | 31 | |
| 32 | 32 | return sprintf('INSERT INTO `%s` (%s) VALUES (%s)', $this->table, $fields, $bindings); |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | return ''; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - return PHP_EOL . ' WHERE ' . implode(PHP_EOL . ' AND ', $this->and); |
|
| 32 | + return PHP_EOL.' WHERE '.implode(PHP_EOL.' AND ', $this->and); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function name(): string |