@@ -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); |
@@ -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 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | if (empty($this->bindings)) { |
38 | 38 | unset($dbg['bindings']); |
39 | 39 | } |
40 | - else{ |
|
40 | + else { |
|
41 | 41 | $dbg['bindings'] = json_encode($dbg['bindings']); |
42 | 42 | } |
43 | 43 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | |
99 | 99 | public function bindings(): array |
100 | 100 | { |
101 | - if(empty($this->clauses)){ |
|
101 | + if (empty($this->clauses)) { |
|
102 | 102 | return $this->bindings; |
103 | 103 | } |
104 | 104 | |
105 | - return array_merge($this->bindings, array_reduce($this->clauses, function ($carry, $clause) { |
|
105 | + return array_merge($this->bindings, array_reduce($this->clauses, function($carry, $clause) { |
|
106 | 106 | return array_merge($carry, $clause->bindings()); |
107 | 107 | }, [])); |
108 | 108 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | public function bindLabel($field, $table_name = null): string |
120 | 120 | { |
121 | - return ':' . $this->tableLabel($table_name) . '_' . $field; |
|
121 | + return ':'.$this->tableLabel($table_name).'_'.$field; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function addBindings($assoc_data, $binding_label = null): array |
@@ -8,7 +8,6 @@ |
||
8 | 8 | * LEFT JOIN, two ways |
9 | 9 | * (new Join('cbx_order', 'Orders'))->on('user_id', 'User', 'id')->type('LEFT'); |
10 | 10 | * (new Join('cbx_order', 'Orders'))->on('user_id', 'User', 'id')->left(); |
11 | - |
|
12 | 11 | * INNER JOIN, with helper, before on |
13 | 12 | * (new Join('cbx_order', 'Orders'))->inner()->on('user_id', 'User', 'id'); |
14 | 13 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | public function __toString(): string |
54 | 54 | { |
55 | - if(isset($this->column, $this->referenced_table, $this->referenced_column)) { |
|
55 | + if (isset($this->column, $this->referenced_table, $this->referenced_column)) { |
|
56 | 56 | $on = (string)(new Predicate([$this->alias, $this->column], '=', [$this->referenced_table, $this->referenced_column])); |
57 | 57 | } |
58 | 58 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function referenced(): ?array |
94 | 94 | { |
95 | - if(isset($this->referenced_table, $this->referenced_column)) { |
|
95 | + if (isset($this->referenced_table, $this->referenced_column)) { |
|
96 | 96 | return [$this->referenced_table, $this->referenced_column]; |
97 | 97 | } |
98 | 98 |
@@ -119,13 +119,13 @@ |
||
119 | 119 | continue; // dont load the log information |
120 | 120 | } else { |
121 | 121 | $m = []; |
122 | - if (preg_match('/(.+)_(' . $fk_column->foreignColumnName() . ')$/', $fk_column->name(), $m)) { |
|
122 | + if (preg_match('/(.+)_('.$fk_column->foreignColumnName().')$/', $fk_column->name(), $m)) { |
|
123 | 123 | $foreign_table_alias = $m[1]; |
124 | 124 | } else { |
125 | 125 | $foreign_table_alias = $foreign_table_name; |
126 | 126 | } |
127 | 127 | |
128 | - $foreign_table_alias = $single_fk ? $foreign_table_alias : $foreign_table_alias . '_' . $fk_column->name(); |
|
128 | + $foreign_table_alias = $single_fk ? $foreign_table_alias : $foreign_table_alias.'_'.$fk_column->name(); |
|
129 | 129 | |
130 | 130 | // auto select non nullable columns |
131 | 131 | } |
@@ -113,7 +113,7 @@ |
||
113 | 113 | private static function options(array $provided = []): array |
114 | 114 | { |
115 | 115 | if (isset($provided[\PDO::ATTR_ERRMODE])) { |
116 | - unset($provided[\PDO::ATTR_ERRMODE]); // the one option you cannot change |
|
116 | + unset($provided[\PDO::ATTR_ERRMODE]); // the one option you cannot change |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return array_merge( |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected $secondary_table; |
18 | 18 | protected $secondary_col; |
19 | 19 | |
20 | - public const NAME='ABSTRACT_RELATION'; |
|
20 | + public const NAME = 'ABSTRACT_RELATION'; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | public function __debugInfo() |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | $this->connection = $c; |
47 | 47 | } |
48 | 48 | |
49 | - public function source(){ |
|
49 | + public function source() { |
|
50 | 50 | return $this->primary_table; |
51 | 51 | } |
52 | 52 | |
53 | - public function target(){ |
|
53 | + public function target() { |
|
54 | 54 | return $this->secondary_table; |
55 | 55 | } |
56 | 56 |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | |
8 | 8 | class OneToManyQualified extends OneToMany |
9 | 9 | { |
10 | - private $pivot_qualified; // FK to the table storing the qualifiers |
|
10 | + private $pivot_qualified; // FK to the table storing the qualifiers |
|
11 | 11 | |
12 | - private $qualified_table; // table storing the qualifiers (tags) |
|
13 | - private $qualified_col; // PK of the table storing the qualifiers |
|
12 | + private $qualified_table; // table storing the qualifiers (tags) |
|
13 | + private $qualified_col; // PK of the table storing the qualifiers |
|
14 | 14 | |
15 | 15 | public const NAME = 'hasAndBelongsToManyQualified'; |
16 | 16 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __toString() |
27 | 27 | { |
28 | - return $this->primary_table . '-hasAndBelongsToManyQualified-' . $this->secondary_table; |
|
28 | + return $this->primary_table.'-hasAndBelongsToManyQualified-'.$this->secondary_table; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | // what a mess... |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function getTargets(int $source): array |
57 | 57 | { |
58 | - $table =$this->connection->schema()->table($this->secondary_table); |
|
58 | + $table = $this->connection->schema()->table($this->secondary_table); |
|
59 | 59 | $select = $table->select() |
60 | 60 | ->join([$this->pivot_table], [[$this->secondary_table, $this->secondary_col, $this->pivot_table, $this->pivot_secondary]], 'INNER') |
61 | 61 | ->whereEQ($this->pivot_primary, $source, $this->pivot_table); |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | private function query(int $source, array $targetWithQualifier, string $method): array |
81 | 81 | { |
82 | 82 | |
83 | - if($source < 1) { |
|
83 | + if ($source < 1) { |
|
84 | 84 | throw new \InvalidArgumentException('MISSING_PARENT_ID'); |
85 | 85 | } |
86 | 86 | |
87 | - if($method !== 'insert' && $method !== 'delete') { |
|
87 | + if ($method !== 'insert' && $method !== 'delete') { |
|
88 | 88 | throw new \InvalidArgumentException('INVALID_METHOD'); |
89 | 89 | } |
90 | 90 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | try { |
94 | 94 | vd($targetWithQualifier, $this->pivot_table); |
95 | - $pivot_table =$this->connection->schema()->table($this->pivot_table); |
|
95 | + $pivot_table = $this->connection->schema()->table($this->pivot_table); |
|
96 | 96 | |
97 | 97 | foreach ($targetWithQualifier as [$qualified_id, $qualifier_id]) { |
98 | 98 |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | |
55 | 55 | public function getIds(int $source) |
56 | 56 | { |
57 | - $pivot_table =$this->connection->schema()->table($this->pivot_table); |
|
57 | + $pivot_table = $this->connection->schema()->table($this->pivot_table); |
|
58 | 58 | $res = $pivot_table->select([$this->pivot_secondary])->whereEQ($this->pivot_primary, $source); |
59 | 59 | return $res->retCol(); |
60 | 60 | } |
61 | 61 | |
62 | 62 | public function getTargets(int $source): array |
63 | 63 | { |
64 | - $table =$this->connection->schema()->table($this->secondary_table); |
|
64 | + $table = $this->connection->schema()->table($this->secondary_table); |
|
65 | 65 | $select = $table->select() |
66 | 66 | ->join([$this->pivot_table], [[$this->secondary_table, $this->secondary_col, $this->pivot_table, $this->pivot_secondary]], 'INNER') |
67 | 67 | ->whereEQ($this->pivot_primary, $source, $this->pivot_table); |
@@ -71,22 +71,22 @@ discard block |
||
71 | 71 | |
72 | 72 | private function query(int $source, array $target_ids, string $method): array |
73 | 73 | { |
74 | - if($source < 1) { |
|
74 | + if ($source < 1) { |
|
75 | 75 | throw new \InvalidArgumentException('MISSING_PARENT_ID'); |
76 | 76 | } |
77 | 77 | |
78 | - if($method !== self::ACTION_LINK && $method !== self::ACTION_UNLINK) { |
|
78 | + if ($method !== self::ACTION_LINK && $method !== self::ACTION_UNLINK) { |
|
79 | 79 | throw new \InvalidArgumentException('INVALID_METHOD'); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $target_ids = array_unique($target_ids); |
83 | 83 | |
84 | - if(empty($target_ids)){ |
|
84 | + if (empty($target_ids)) { |
|
85 | 85 | throw new \InvalidArgumentException('NO_UNIQUE_CHILDREN'); |
86 | 86 | } |
87 | 87 | |
88 | 88 | $errors = []; |
89 | - $pivot_table =$this->connection->schema()->table($this->pivot_table); |
|
89 | + $pivot_table = $this->connection->schema()->table($this->pivot_table); |
|
90 | 90 | |
91 | 91 | foreach ($target_ids as $target) { |
92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if (!$query->isSuccess()) { |
104 | 104 | $errors[] = $query->error(); |
105 | 105 | |
106 | - if($query->error()->getCode() !== 1062){ |
|
106 | + if ($query->error()->getCode() !== 1062) { |
|
107 | 107 | throw CruditesExceptionFactory::make($query); |
108 | 108 | } |
109 | 109 | } |