@@ -11,12 +11,12 @@ |
||
11 | 11 | * @return string : the string surrounded by the tick character |
12 | 12 | * |
13 | 13 | */ |
14 | - public static function identifier($reference, $tick='`'): string |
|
14 | + public static function identifier($reference, $tick = '`'): string |
|
15 | 15 | { |
16 | 16 | if (is_array($reference)) { |
17 | 17 | $identifier = $reference[0]; |
18 | 18 | if (isset($reference[1])) { |
19 | - $identifier = $identifier.$tick . '.' . $tick.$reference[1]; |
|
19 | + $identifier = $identifier.$tick.'.'.$tick.$reference[1]; |
|
20 | 20 | } |
21 | 21 | $reference = $identifier; |
22 | 22 | } |
@@ -74,7 +74,7 @@ |
||
74 | 74 | $expected_bind_label = 'andValue_expression_bind_label'; |
75 | 75 | |
76 | 76 | $where->andValue($expression, '>', 3, $expected_bind_label); |
77 | - $this->assertEquals('WHERE ' . $expression . ' > :' . $expected_bind_label, (string)$where); |
|
77 | + $this->assertEquals('WHERE '.$expression.' > :'.$expected_bind_label, (string)$where); |
|
78 | 78 | $this->assertEquals([$expected_bind_label => 3], $where->bindings()); |
79 | 79 | |
80 | 80 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | return ''; |
27 | 27 | } |
28 | 28 | |
29 | - return 'WHERE ' . implode(' AND ', $this->and); |
|
29 | + return 'WHERE '.implode(' AND ', $this->and); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function name(): string |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | foreach ($assoc_data as $field => $value) { |
62 | 62 | $column = $table_name === null ? [$field] : [$table_name, $field]; |
63 | - $predicate = (new Predicate($column, $operator))->withValue($value, __FUNCTION__ .'_'.implode('_', $column)); |
|
63 | + $predicate = (new Predicate($column, $operator))->withValue($value, __FUNCTION__.'_'.implode('_', $column)); |
|
64 | 64 | |
65 | 65 | $this->and($predicate, $predicate->bindings()); |
66 | 66 | } |
@@ -12,10 +12,11 @@ |
||
12 | 12 | { |
13 | 13 | if ($predicates !== null) { |
14 | 14 | foreach ($predicates as $predicate) { |
15 | - if (is_string($predicate)) |
|
16 | - $this->and($predicate); |
|
17 | - else |
|
18 | - $this->and($predicate, $predicate->bindings()); |
|
15 | + if (is_string($predicate)) { |
|
16 | + $this->and($predicate); |
|
17 | + } else { |
|
18 | + $this->and($predicate, $predicate->bindings()); |
|
19 | + } |
|
19 | 20 | } |
20 | 21 | } |
21 | 22 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function withValue($value, string $bind_label = null): self |
64 | 64 | { |
65 | 65 | $this->bindings[$this->bindLabel($bind_label)] = $value; |
66 | - $this->right = ':' . $this->bindLabel($bind_label); |
|
66 | + $this->right = ':'.$this->bindLabel($bind_label); |
|
67 | 67 | return $this; |
68 | 68 | } |
69 | 69 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | $this->operator = 'IN'; |
82 | - $this->right = '(:' . implode(',:', array_keys($this->bindings)) . ')'; |
|
82 | + $this->right = '(:'.implode(',:', array_keys($this->bindings)).')'; |
|
83 | 83 | |
84 | 84 | return $this; |
85 | 85 | } |
@@ -118,8 +118,9 @@ |
||
118 | 118 | return $this->bind_label; |
119 | 119 | } |
120 | 120 | // getter |
121 | - else if ($this->bind_label !== null) |
|
122 | - return $this->bind_label; |
|
121 | + else if ($this->bind_label !== null) { |
|
122 | + return $this->bind_label; |
|
123 | + } |
|
123 | 124 | |
124 | 125 | // generator |
125 | 126 | else if (is_array($this->left)) { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $res = new Result(self::$connection->pdo(), (string)$select, $select->bindings()); |
63 | 63 | $res = $res->retCol(); |
64 | 64 | if (is_array($res)) { |
65 | - return (int) current($res); |
|
65 | + return (int)current($res); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return null; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $ret = []; |
80 | 80 | |
81 | 81 | $res = new Result(self::$connection->pdo(), (string)$select, $select->bindings()); |
82 | - if($res->ran()) { |
|
82 | + if ($res->ran()) { |
|
83 | 83 | |
84 | 84 | $primary_keys = self::$connection->schema()->primaryKeys($select->table()); |
85 | 85 | $pk_name = implode('_', $primary_keys); |
@@ -42,8 +42,7 @@ |
||
42 | 42 | // no props, assumes connection made, verify and return |
43 | 43 | if (isset($dsn, $user, $pass)) { |
44 | 44 | self::$connection = new Connection($dsn, $user, $pass); |
45 | - } |
|
46 | - elseif (self::$connection === null) { |
|
45 | + } elseif (self::$connection === null) { |
|
47 | 46 | throw new CruditesException('NO_DATABASE'); |
48 | 47 | } |
49 | 48 |
@@ -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 |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | |
45 | 45 | public function __toString() |
46 | 46 | { |
47 | - return PHP_EOL . 'load: ' |
|
47 | + return PHP_EOL.'load: ' |
|
48 | 48 | . json_encode($this->load) |
49 | - . PHP_EOL . 'alterations: ' |
|
49 | + . PHP_EOL.'alterations: ' |
|
50 | 50 | . json_encode(array_keys($this->alterations)); |
51 | 51 | } |
52 | 52 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | } |
146 | 146 | |
147 | 147 | // replaces empty strings with null or default value |
148 | - if (trim('' . $datass[$field_name]) === '' && $attributes->nullable()) { |
|
148 | + if (trim(''.$datass[$field_name]) === '' && $attributes->nullable()) { |
|
149 | 149 | $datass[$field_name] = null; |
150 | 150 | } |
151 | 151 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | $unique_match = $this->connection->schema()->matchUniqueness($this->table, $this->load); |
203 | 203 | |
204 | - if(empty($unique_match)){ |
|
204 | + if (empty($unique_match)) { |
|
205 | 205 | throw new CruditesException('UNIQUE_MATCH_NOT_FOUND'); |
206 | 206 | } |
207 | 207 |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $pdo_statement = $this->executed ?? $this->prepared; |
89 | 89 | |
90 | 90 | if ($pdo_statement === null) |
91 | - throw new CruditesException('both executed and prepared instances are null, cannot call PDOStatement method ' . $method); |
|
91 | + throw new CruditesException('both executed and prepared instances are null, cannot call PDOStatement method '.$method); |
|
92 | 92 | |
93 | 93 | if (!method_exists($pdo_statement, $method)) |
94 | 94 | throw new \BadMethodCallException("method $method not found in PDOStatement instance"); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | throw new CruditesException('PDO_PREPARE_STRING'); |
144 | 144 | } catch (\PDOException $e) { |
145 | - throw new CruditesException('PDO_EXCEPTION: ' . $e->getMessage(), $e->getCode(), $e); |
|
145 | + throw new CruditesException('PDO_EXCEPTION: '.$e->getMessage(), $e->getCode(), $e); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | return $this; |
@@ -70,8 +70,9 @@ discard block |
||
70 | 70 | $this->statement = $statement; |
71 | 71 | } |
72 | 72 | |
73 | - if ($this->statement instanceof \PDOStatement) |
|
74 | - $this->prepared = $this->statement; |
|
73 | + if ($this->statement instanceof \PDOStatement) { |
|
74 | + $this->prepared = $this->statement; |
|
75 | + } |
|
75 | 76 | |
76 | 77 | $this->run($bindings); |
77 | 78 | } |
@@ -87,11 +88,13 @@ discard block |
||
87 | 88 | // make senses for chronology and error handling |
88 | 89 | $pdo_statement = $this->executed ?? $this->prepared; |
89 | 90 | |
90 | - if ($pdo_statement === null) |
|
91 | - throw new CruditesException('both executed and prepared instances are null, cannot call PDOStatement method ' . $method); |
|
91 | + if ($pdo_statement === null) { |
|
92 | + throw new CruditesException('both executed and prepared instances are null, cannot call PDOStatement method ' . $method); |
|
93 | + } |
|
92 | 94 | |
93 | - if (!method_exists($pdo_statement, $method)) |
|
94 | - throw new \BadMethodCallException("method $method not found in PDOStatement instance"); |
|
95 | + if (!method_exists($pdo_statement, $method)) { |
|
96 | + throw new \BadMethodCallException("method $method not found in PDOStatement instance"); |
|
97 | + } |
|
95 | 98 | |
96 | 99 | return call_user_func_array([$pdo_statement, $method], $args); |
97 | 100 | } |
@@ -164,8 +167,9 @@ discard block |
||
164 | 167 | */ |
165 | 168 | public function ret($mode = \PDO::FETCH_ASSOC, $fetch_argument = null, $ctor_args = null) |
166 | 169 | { |
167 | - if ($mode === \PDO::FETCH_CLASS) |
|
168 | - return $this->executed->fetchAll($mode, $fetch_argument, $ctor_args); |
|
170 | + if ($mode === \PDO::FETCH_CLASS) { |
|
171 | + return $this->executed->fetchAll($mode, $fetch_argument, $ctor_args); |
|
172 | + } |
|
169 | 173 | |
170 | 174 | return $this->executed->fetchAll($mode); |
171 | 175 | } |