@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | throw new CruditesException('RUN_OR_PREPARE_QUERY_BEFORE_CALLING_METHOD'); |
51 | 51 | |
52 | 52 | if (!method_exists($pdo_statement, $method)) |
53 | - throw new \BadMethodCallException(__FUNCTION__ . " method $method() does not exist in PDOStatement class"); |
|
53 | + throw new \BadMethodCallException(__FUNCTION__." method $method() does not exist in PDOStatement class"); |
|
54 | 54 | |
55 | 55 | |
56 | 56 | return call_user_func_array([$pdo_statement, $method], $args); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | throw new CruditesException('PDO_PREPARE_STRING'); |
103 | 103 | |
104 | 104 | } catch (\PDOException $e) { |
105 | - throw new CruditesException('PDO_EXCEPTION: ' . $e->getMessage(), $e->getCode(), $e); |
|
105 | + throw new CruditesException('PDO_EXCEPTION: '.$e->getMessage(), $e->getCode(), $e); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $this; |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | $this->statement = $statement; |
32 | 32 | $this->bindings = $bindings; |
33 | 33 | |
34 | - if ($statement instanceof \PDOStatement) |
|
35 | - $this->prepared = $statement; |
|
34 | + if ($statement instanceof \PDOStatement) { |
|
35 | + $this->prepared = $statement; |
|
36 | + } |
|
36 | 37 | |
37 | 38 | $this->run($bindings); |
38 | 39 | } |
@@ -46,11 +47,13 @@ discard block |
||
46 | 47 | { |
47 | 48 | $pdo_statement = $this->executed ?? $this->prepared; |
48 | 49 | |
49 | - if ($pdo_statement === null) |
|
50 | - throw new CruditesException('RUN_OR_PREPARE_QUERY_BEFORE_CALLING_METHOD'); |
|
50 | + if ($pdo_statement === null) { |
|
51 | + throw new CruditesException('RUN_OR_PREPARE_QUERY_BEFORE_CALLING_METHOD'); |
|
52 | + } |
|
51 | 53 | |
52 | - if (!method_exists($pdo_statement, $method)) |
|
53 | - throw new \BadMethodCallException(__FUNCTION__ . " method $method() does not exist in PDOStatement class"); |
|
54 | + if (!method_exists($pdo_statement, $method)) { |
|
55 | + throw new \BadMethodCallException(__FUNCTION__ . " method $method() does not exist in PDOStatement class"); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | |
56 | 59 | return call_user_func_array([$pdo_statement, $method], $args); |
@@ -173,11 +176,13 @@ discard block |
||
173 | 176 | */ |
174 | 177 | public function errorInfo(): array |
175 | 178 | { |
176 | - if ($this->executed !== null) |
|
177 | - return $this->executed->errorInfo(); |
|
179 | + if ($this->executed !== null) { |
|
180 | + return $this->executed->errorInfo(); |
|
181 | + } |
|
178 | 182 | |
179 | - if ($this->prepared !== null) |
|
180 | - return $this->prepared->errorInfo(); |
|
183 | + if ($this->prepared !== null) { |
|
184 | + return $this->prepared->errorInfo(); |
|
185 | + } |
|
181 | 186 | |
182 | 187 | return $this->pdo->errorInfo(); |
183 | 188 | } |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | public function listRelations(): array |
28 | 28 | { |
29 | 29 | $relations = []; |
30 | - foreach($this->connection->schema()->foreignKeysFor() as $table => $join){ |
|
30 | + foreach ($this->connection->schema()->foreignKeysFor() as $table => $join) { |
|
31 | 31 | |
32 | - if(count($join) == 1){ |
|
33 | - $res = new HasOne($table, $join,$this->connection); |
|
32 | + if (count($join) == 1) { |
|
33 | + $res = new HasOne($table, $join, $this->connection); |
|
34 | 34 | $relations["$res"] = $res; |
35 | 35 | } |
36 | - else if(count($join) == 2){ |
|
37 | - $res = new OneToMany($table, $join,$this->connection); |
|
36 | + else if (count($join) == 2) { |
|
37 | + $res = new OneToMany($table, $join, $this->connection); |
|
38 | 38 | $relations["$res"] = $res; |
39 | 39 | |
40 | - $res = new OneToMany($table, array_reverse($join),$this->connection); |
|
40 | + $res = new OneToMany($table, array_reverse($join), $this->connection); |
|
41 | 41 | $relations["$res"] = $res; |
42 | 42 | } |
43 | - else if(count($join) == 3){ |
|
44 | - $res = new OneToManyQualified($table, $join,$this->connection); |
|
43 | + else if (count($join) == 3) { |
|
44 | + $res = new OneToManyQualified($table, $join, $this->connection); |
|
45 | 45 | $relations["$res"] = $res; |
46 | 46 | |
47 | - $res = new OneToManyQualified($table, array_reverse($join),$this->connection); |
|
47 | + $res = new OneToManyQualified($table, array_reverse($join), $this->connection); |
|
48 | 48 | $relations["$res"] = $res; |
49 | 49 | } |
50 | 50 | else |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | { |
67 | 67 | $ret = []; |
68 | 68 | |
69 | - foreach($this->relations as $urn => $relation){ |
|
70 | - if($relation->source() === $source){ |
|
69 | + foreach ($this->relations as $urn => $relation) { |
|
70 | + if ($relation->source() === $source) { |
|
71 | 71 | $ret[$urn] = $relation; |
72 | 72 | } |
73 | 73 | } |
@@ -32,22 +32,19 @@ |
||
32 | 32 | if(count($join) == 1){ |
33 | 33 | $res = new HasOne($table, $join,$this->connection); |
34 | 34 | $relations["$res"] = $res; |
35 | - } |
|
36 | - else if(count($join) == 2){ |
|
35 | + } else if(count($join) == 2){ |
|
37 | 36 | $res = new OneToMany($table, $join,$this->connection); |
38 | 37 | $relations["$res"] = $res; |
39 | 38 | |
40 | 39 | $res = new OneToMany($table, array_reverse($join),$this->connection); |
41 | 40 | $relations["$res"] = $res; |
42 | - } |
|
43 | - else if(count($join) == 3){ |
|
41 | + } else if(count($join) == 3){ |
|
44 | 42 | $res = new OneToManyQualified($table, $join,$this->connection); |
45 | 43 | $relations["$res"] = $res; |
46 | 44 | |
47 | 45 | $res = new OneToManyQualified($table, array_reverse($join),$this->connection); |
48 | 46 | $relations["$res"] = $res; |
49 | - } |
|
50 | - else |
|
47 | + } else |
|
51 | 48 | { |
52 | 49 | vd($join, 'skipping '.$table); |
53 | 50 | } |
@@ -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 | } |
@@ -17,19 +17,19 @@ |
||
17 | 17 | $this->propertiesFromJoin($join); |
18 | 18 | } |
19 | 19 | |
20 | - protected function propertiesFromJoin($join){ |
|
20 | + protected function propertiesFromJoin($join) { |
|
21 | 21 | $this->primary_col = array_keys($join); |
22 | 22 | $this->primary_col = array_pop($this->primary_col); |
23 | 23 | [$this->secondary_table, $this->secondary_col] = $join[$this->primary_col]; |
24 | 24 | } |
25 | 25 | |
26 | - public function link(int $primary_id, $secondary_id){ |
|
27 | - $table =$this->connection->schema()->table($this->primary_table); |
|
26 | + public function link(int $primary_id, $secondary_id) { |
|
27 | + $table = $this->connection->schema()->table($this->primary_table); |
|
28 | 28 | $table->insert($this->primary_table, [$this->primary_col => $primary_id, $this->secondary_col => $secondary_id]); |
29 | 29 | } |
30 | 30 | |
31 | - public function unlink(int $primary_id, $secondary_id){ |
|
32 | - $table =$this->connection->schema()->table($this->primary_table); |
|
31 | + public function unlink(int $primary_id, $secondary_id) { |
|
32 | + $table = $this->connection->schema()->table($this->primary_table); |
|
33 | 33 | $table->delete($this->primary_table, [$this->primary_col => $primary_id, $this->secondary_col => $secondary_id]); |
34 | 34 | |
35 | 35 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | if (is_array($reference)) { |
22 | 22 | $tick = $reference[0]; |
23 | 23 | if (isset($reference[1])) { |
24 | - $tick = $tick . '`.`' . $reference[1]; |
|
24 | + $tick = $tick.'`.`'.$reference[1]; |
|
25 | 25 | } |
26 | 26 | $reference = $tick; |
27 | 27 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | public function addRaw(string $raw): self |
30 | 30 | { |
31 | - $this->aggregates .= ',' . $raw; |
|
31 | + $this->aggregates .= ','.$raw; |
|
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $ret = is_string($aggregate) ? $aggregate : self::identifier($aggregate); |
44 | 44 | |
45 | 45 | if ($alias !== null) { |
46 | - $ret .= ' AS ' . self::identifier($alias); |
|
46 | + $ret .= ' AS '.self::identifier($alias); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | return $ret; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | public function __toString(): string |
23 | 23 | { |
24 | - return 'GROUP BY ' . $this->deck; |
|
24 | + return 'GROUP BY '.$this->deck; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function name(): string |