Completed
Push — master ( 5fdfe9...8a6726 )
by Ondřej
03:21
created
src/Ivory/Connection/Connection.php 1 patch
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -8,103 +8,103 @@  discard block
 block discarded – undo
8 8
 // TODO: consider introducing factory methods for abbreviating relation creating; e.g., new QueryRelation($conn, $query)
9 9
 class Connection implements IConnection
10 10
 {
11
-	use NotSerializable; // TODO: implement connection serialization instead of giving up
12
-
13
-	private $name;
14
-	private $connCtl;
15
-	private $typeCtl;
16
-	private $stmtExec;
17
-	private $copyCtl;
18
-	private $txCtl;
19
-	private $ipcCtl;
20
-
21
-	private $config;
22
-
23
-
24
-	/**
25
-	 * @param string $name name for the connection
26
-	 * @param ConnectionParameters|array|string $params either a connection parameters object, or an associative array
27
-	 *                                                    of parameters for {@link ConnectionParameters::__construct()},
28
-	 *                                                    or a URL for {@link ConnectionParameters::fromUrl()},
29
-	 *                                                    or a PostgreSQL connection string (see {@link pg_connect()})
30
-	 */
31
-	public function __construct($name, $params)
32
-	{
33
-		$this->name = $name;
34
-		$this->connCtl = new ConnectionControl($params); // TODO: extract all usages of ConnectionControl::requireConnection() - consider introducing an interface specifying the method, named like PGSQLDriver or ConnectionManager or ConnectionPool
35
-		$this->typeCtl = new TypeControl($this, $this->connCtl);
36
-		$this->stmtExec = new StatementExecution($this->connCtl, $this->typeCtl);
37
-		$this->copyCtl = new CopyControl();
38
-		$this->txCtl = new TransactionControl($this->connCtl, $this->stmtExec);
39
-		$this->ipcCtl = new IPCControl($this->connCtl);
40
-		$this->config = new ConnConfig($this->connCtl, $this->stmtExec, $this->txCtl);
41
-	}
42
-
43
-	final public function getName()
44
-	{
45
-		return $this->name;
46
-	}
47
-
48
-	final public function getConfig()
49
-	{
50
-		return $this->config;
51
-	}
52
-
53
-
54
-	//region Connection Control
55
-
56
-	public function getParameters()
57
-	{
58
-		return $this->connCtl->getParameters();
59
-	}
60
-
61
-	public function isConnected()
62
-	{
63
-		return $this->connCtl->isConnected();
64
-	}
65
-
66
-	public function isConnectedWait()
67
-	{
68
-		return $this->connCtl->isConnectedWait();
69
-	}
70
-
71
-	public function connect()
72
-	{
73
-		return $this->connCtl->connect();
74
-	}
75
-
76
-	public function connectWait()
77
-	{
78
-		return $this->connCtl->connectWait();
79
-	}
80
-
81
-	public function disconnect()
82
-	{
83
-		return $this->connCtl->disconnect();
84
-	}
85
-
86
-	//endregion
87
-
88
-	//region Type Control
89
-
90
-	public function getTypeRegister()
91
-	{
92
-		return $this->typeCtl->getTypeRegister();
93
-	}
94
-
95
-	public function getTypeDictionary()
96
-	{
97
-		return $this->typeCtl->getTypeDictionary();
98
-	}
99
-
100
-	public function flushTypeDictionary()
101
-	{
102
-		$this->typeCtl->flushTypeDictionary();
103
-	}
104
-
105
-	//endregion
106
-
107
-	//region Statement Execution
11
+    use NotSerializable; // TODO: implement connection serialization instead of giving up
12
+
13
+    private $name;
14
+    private $connCtl;
15
+    private $typeCtl;
16
+    private $stmtExec;
17
+    private $copyCtl;
18
+    private $txCtl;
19
+    private $ipcCtl;
20
+
21
+    private $config;
22
+
23
+
24
+    /**
25
+     * @param string $name name for the connection
26
+     * @param ConnectionParameters|array|string $params either a connection parameters object, or an associative array
27
+     *                                                    of parameters for {@link ConnectionParameters::__construct()},
28
+     *                                                    or a URL for {@link ConnectionParameters::fromUrl()},
29
+     *                                                    or a PostgreSQL connection string (see {@link pg_connect()})
30
+     */
31
+    public function __construct($name, $params)
32
+    {
33
+        $this->name = $name;
34
+        $this->connCtl = new ConnectionControl($params); // TODO: extract all usages of ConnectionControl::requireConnection() - consider introducing an interface specifying the method, named like PGSQLDriver or ConnectionManager or ConnectionPool
35
+        $this->typeCtl = new TypeControl($this, $this->connCtl);
36
+        $this->stmtExec = new StatementExecution($this->connCtl, $this->typeCtl);
37
+        $this->copyCtl = new CopyControl();
38
+        $this->txCtl = new TransactionControl($this->connCtl, $this->stmtExec);
39
+        $this->ipcCtl = new IPCControl($this->connCtl);
40
+        $this->config = new ConnConfig($this->connCtl, $this->stmtExec, $this->txCtl);
41
+    }
42
+
43
+    final public function getName()
44
+    {
45
+        return $this->name;
46
+    }
47
+
48
+    final public function getConfig()
49
+    {
50
+        return $this->config;
51
+    }
52
+
53
+
54
+    //region Connection Control
55
+
56
+    public function getParameters()
57
+    {
58
+        return $this->connCtl->getParameters();
59
+    }
60
+
61
+    public function isConnected()
62
+    {
63
+        return $this->connCtl->isConnected();
64
+    }
65
+
66
+    public function isConnectedWait()
67
+    {
68
+        return $this->connCtl->isConnectedWait();
69
+    }
70
+
71
+    public function connect()
72
+    {
73
+        return $this->connCtl->connect();
74
+    }
75
+
76
+    public function connectWait()
77
+    {
78
+        return $this->connCtl->connectWait();
79
+    }
80
+
81
+    public function disconnect()
82
+    {
83
+        return $this->connCtl->disconnect();
84
+    }
85
+
86
+    //endregion
87
+
88
+    //region Type Control
89
+
90
+    public function getTypeRegister()
91
+    {
92
+        return $this->typeCtl->getTypeRegister();
93
+    }
94
+
95
+    public function getTypeDictionary()
96
+    {
97
+        return $this->typeCtl->getTypeDictionary();
98
+    }
99
+
100
+    public function flushTypeDictionary()
101
+    {
102
+        $this->typeCtl->flushTypeDictionary();
103
+    }
104
+
105
+    //endregion
106
+
107
+    //region Statement Execution
108 108
 
109 109
     public function query($sqlFragmentPatternOrRecipe, ...$fragmentsAndPositionalParamsAndNamedParamsMap)
110 110
     {
@@ -116,172 +116,172 @@  discard block
 block discarded – undo
116 116
         return $this->stmtExec->command($sqlFragmentPatternOrRecipe, ...$fragmentsAndPositionalParamsAndNamedParamsMap);
117 117
     }
118 118
 
119
-	public function rawQuery(string $sqlStatement)
120
-	{
121
-		return $this->stmtExec->rawQuery($sqlStatement);
122
-	}
119
+    public function rawQuery(string $sqlStatement)
120
+    {
121
+        return $this->stmtExec->rawQuery($sqlStatement);
122
+    }
123 123
 
124
-	public function rawMultiQuery($sqlStatements)
125
-	{
126
-		return $this->stmtExec->rawMultiQuery($sqlStatements);
127
-	}
124
+    public function rawMultiQuery($sqlStatements)
125
+    {
126
+        return $this->stmtExec->rawMultiQuery($sqlStatements);
127
+    }
128 128
 
129
-	public function runScript($sqlScript)
130
-	{
131
-		return $this->stmtExec->runScript($sqlScript);
132
-	}
129
+    public function runScript($sqlScript)
130
+    {
131
+        return $this->stmtExec->runScript($sqlScript);
132
+    }
133 133
 
134 134
     public function getStatementExceptionFactory()
135
-   	{
136
-   		return $this->stmtExec->getStatementExceptionFactory();
137
-   	}
138
-
139
-	//endregion
140
-
141
-	//region Copy Control
142
-
143
-	public function copyFromFile($file, $table, $columns = null, $options = [])
144
-	{
145
-		return $this->copyCtl->copyFromFile($file, $table, $columns, $options);
146
-	}
147
-
148
-	public function copyFromProgram($program, $table, $columns = null, $options = [])
149
-	{
150
-		return $this->copyCtl->copyFromProgram($program, $table, $columns, $options);
151
-	}
152
-
153
-	public function copyFromInput($table, $columns = null, $options = [])
154
-	{
155
-		return $this->copyCtl->copyFromInput($table, $columns, $options);
156
-	}
157
-
158
-	public function copyToFile($file, $tableOrQuery, $columns = null, $options = [])
159
-	{
160
-		return $this->copyCtl->copyToFile($file, $tableOrQuery, $columns, $options);
161
-	}
162
-
163
-	public function copyToProgram($program, $tableOrQuery, $columns = null, $options = [])
164
-	{
165
-		return $this->copyCtl->copyToProgram($program, $tableOrQuery, $columns, $options);
166
-	}
167
-
168
-	public function copyToArray($table, $options = [])
169
-	{
170
-		return $this->copyCtl->copyToArray($table, $options);
171
-	}
172
-
173
-	//endregion
174
-
175
-	//region Transaction Control
176
-
177
-	public function inTransaction()
178
-	{
179
-		return $this->txCtl->inTransaction();
180
-	}
181
-
182
-	public function startTransaction($transactionOptions = 0)
183
-	{
184
-		return $this->txCtl->startTransaction($transactionOptions);
185
-	}
186
-
187
-	public function setupTransaction($transactionOptions)
188
-	{
189
-		$this->txCtl->setupTransaction($transactionOptions);
190
-	}
191
-
192
-	public function setupSubsequentTransactions($transactionOptions)
193
-	{
194
-		$this->txCtl->setupSubsequentTransactions($transactionOptions);
195
-	}
196
-
197
-	public function commit()
198
-	{
199
-		return $this->txCtl->commit();
200
-	}
201
-
202
-	public function rollback()
203
-	{
204
-		return $this->txCtl->rollback();
205
-	}
206
-
207
-	public function savepoint($name)
208
-	{
209
-		$this->txCtl->savepoint($name);
210
-	}
211
-
212
-	public function rollbackToSavepoint($name)
213
-	{
214
-		$this->txCtl->rollbackToSavepoint($name);
215
-	}
216
-
217
-	public function releaseSavepoint($name)
218
-	{
219
-		$this->txCtl->releaseSavepoint($name);
220
-	}
221
-
222
-	public function setTransactionSnapshot($snapshotId)
223
-	{
224
-		return $this->txCtl->setTransactionSnapshot($snapshotId);
225
-	}
226
-
227
-	public function exportTransactionSnapshot()
228
-	{
229
-		return $this->txCtl->exportTransactionSnapshot();
230
-	}
231
-
232
-	public function prepareTransaction($name)
233
-	{
234
-		return $this->txCtl->prepareTransaction($name);
235
-	}
236
-
237
-	public function commitPreparedTransaction($name)
238
-	{
239
-		$this->txCtl->commitPreparedTransaction($name);
240
-	}
241
-
242
-	public function rollbackPreparedTransaction($name)
243
-	{
244
-		$this->txCtl->rollbackPreparedTransaction($name);
245
-	}
246
-
247
-	public function listPreparedTransactions()
248
-	{
249
-		return $this->txCtl->listPreparedTransactions();
250
-	}
251
-
252
-	//endregion
253
-
254
-	//region IPC Control
255
-
256
-	public function getBackendPID()
257
-	{
258
-		return $this->ipcCtl->getBackendPID();
259
-	}
260
-
261
-	public function notify($channel, $payload = null)
262
-	{
263
-		$this->ipcCtl->notify($channel, $payload);
264
-	}
265
-
266
-	public function listen($channel)
267
-	{
268
-		$this->ipcCtl->listen($channel);
269
-	}
270
-
271
-	public function unlisten($channel)
272
-	{
273
-		$this->ipcCtl->unlisten($channel);
274
-	}
275
-
276
-	public function unlistenAll()
277
-	{
278
-		$this->ipcCtl->unlistenAll();
279
-	}
280
-
281
-	public function pollNotification()
282
-	{
283
-		return $this->ipcCtl->pollNotification();
284
-	}
285
-
286
-	//endregion
135
+        {
136
+            return $this->stmtExec->getStatementExceptionFactory();
137
+        }
138
+
139
+    //endregion
140
+
141
+    //region Copy Control
142
+
143
+    public function copyFromFile($file, $table, $columns = null, $options = [])
144
+    {
145
+        return $this->copyCtl->copyFromFile($file, $table, $columns, $options);
146
+    }
147
+
148
+    public function copyFromProgram($program, $table, $columns = null, $options = [])
149
+    {
150
+        return $this->copyCtl->copyFromProgram($program, $table, $columns, $options);
151
+    }
152
+
153
+    public function copyFromInput($table, $columns = null, $options = [])
154
+    {
155
+        return $this->copyCtl->copyFromInput($table, $columns, $options);
156
+    }
157
+
158
+    public function copyToFile($file, $tableOrQuery, $columns = null, $options = [])
159
+    {
160
+        return $this->copyCtl->copyToFile($file, $tableOrQuery, $columns, $options);
161
+    }
162
+
163
+    public function copyToProgram($program, $tableOrQuery, $columns = null, $options = [])
164
+    {
165
+        return $this->copyCtl->copyToProgram($program, $tableOrQuery, $columns, $options);
166
+    }
167
+
168
+    public function copyToArray($table, $options = [])
169
+    {
170
+        return $this->copyCtl->copyToArray($table, $options);
171
+    }
172
+
173
+    //endregion
174
+
175
+    //region Transaction Control
176
+
177
+    public function inTransaction()
178
+    {
179
+        return $this->txCtl->inTransaction();
180
+    }
181
+
182
+    public function startTransaction($transactionOptions = 0)
183
+    {
184
+        return $this->txCtl->startTransaction($transactionOptions);
185
+    }
186
+
187
+    public function setupTransaction($transactionOptions)
188
+    {
189
+        $this->txCtl->setupTransaction($transactionOptions);
190
+    }
191
+
192
+    public function setupSubsequentTransactions($transactionOptions)
193
+    {
194
+        $this->txCtl->setupSubsequentTransactions($transactionOptions);
195
+    }
196
+
197
+    public function commit()
198
+    {
199
+        return $this->txCtl->commit();
200
+    }
201
+
202
+    public function rollback()
203
+    {
204
+        return $this->txCtl->rollback();
205
+    }
206
+
207
+    public function savepoint($name)
208
+    {
209
+        $this->txCtl->savepoint($name);
210
+    }
211
+
212
+    public function rollbackToSavepoint($name)
213
+    {
214
+        $this->txCtl->rollbackToSavepoint($name);
215
+    }
216
+
217
+    public function releaseSavepoint($name)
218
+    {
219
+        $this->txCtl->releaseSavepoint($name);
220
+    }
221
+
222
+    public function setTransactionSnapshot($snapshotId)
223
+    {
224
+        return $this->txCtl->setTransactionSnapshot($snapshotId);
225
+    }
226
+
227
+    public function exportTransactionSnapshot()
228
+    {
229
+        return $this->txCtl->exportTransactionSnapshot();
230
+    }
231
+
232
+    public function prepareTransaction($name)
233
+    {
234
+        return $this->txCtl->prepareTransaction($name);
235
+    }
236
+
237
+    public function commitPreparedTransaction($name)
238
+    {
239
+        $this->txCtl->commitPreparedTransaction($name);
240
+    }
241
+
242
+    public function rollbackPreparedTransaction($name)
243
+    {
244
+        $this->txCtl->rollbackPreparedTransaction($name);
245
+    }
246
+
247
+    public function listPreparedTransactions()
248
+    {
249
+        return $this->txCtl->listPreparedTransactions();
250
+    }
251
+
252
+    //endregion
253
+
254
+    //region IPC Control
255
+
256
+    public function getBackendPID()
257
+    {
258
+        return $this->ipcCtl->getBackendPID();
259
+    }
260
+
261
+    public function notify($channel, $payload = null)
262
+    {
263
+        $this->ipcCtl->notify($channel, $payload);
264
+    }
265
+
266
+    public function listen($channel)
267
+    {
268
+        $this->ipcCtl->listen($channel);
269
+    }
270
+
271
+    public function unlisten($channel)
272
+    {
273
+        $this->ipcCtl->unlisten($channel);
274
+    }
275
+
276
+    public function unlistenAll()
277
+    {
278
+        $this->ipcCtl->unlistenAll();
279
+    }
280
+
281
+    public function pollNotification()
282
+    {
283
+        return $this->ipcCtl->pollNotification();
284
+    }
285
+
286
+    //endregion
287 287
 }
Please login to merge, or discard this patch.
src/Ivory/Connection/StatementExecution.php 1 patch
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,8 +38,7 @@  discard block
 block discarded – undo
38 38
                 $namedParamsMap = $fragmentsAndPositionalParamsAndNamedParamsMap[0];
39 39
                 $recipe->setParams($namedParamsMap);
40 40
             }
41
-        }
42
-        else {
41
+        } else {
43 42
             $recipe = SqlRelationRecipe::fromFragments($sqlFragmentPatternOrRecipe, ...$fragmentsAndPositionalParamsAndNamedParamsMap);
44 43
         }
45 44
 
@@ -58,8 +57,7 @@  discard block
 block discarded – undo
58 57
                 $namedParamsMap = $fragmentsAndPositionalParamsAndNamedParamsMap[0];
59 58
                 $recipe->setParams($namedParamsMap);
60 59
             }
61
-        }
62
-        else {
60
+        } else {
63 61
             $recipe = SqlCommandRecipe::fromFragments($sqlFragmentPatternOrRecipe, ...$fragmentsAndPositionalParamsAndNamedParamsMap);
64 62
         }
65 63
 
@@ -180,8 +178,7 @@  discard block
 block discarded – undo
180 178
         if ($resNotice !== $connNotice) {
181 179
             $this->connCtl->setLastNotice($resNotice);
182 180
             return $resNotice;
183
-        }
184
-        else {
181
+        } else {
185 182
             return null;
186 183
         }
187 184
     }
Please login to merge, or discard this patch.
src/Ivory/Query/SqlRecipe.php 1 patch
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -142,14 +142,12 @@  discard block
 block discarded – undo
142 142
                 if (is_string($curFragment)) {
143 143
                     $parser = \Ivory\Ivory::getSqlPatternParser();
144 144
                     $curFragment = $parser->parse($curFragment);
145
-                }
146
-                elseif ((is_array($curFragment) || $curFragment instanceof \Traversable) && // PHP 7.1: is_iterable()
145
+                } elseif ((is_array($curFragment) || $curFragment instanceof \Traversable) && // PHP 7.1: is_iterable()
147 146
                     $argsProcessed > 0 && !array_key_exists($argsProcessed, $fragmentsAndPositionalParams))
148 147
                 {
149 148
                     $namedParamValues = $curFragment;
150 149
                     break;
151
-                }
152
-                else {
150
+                } else {
153 151
                     $ord = StringUtils::englishOrd($curFragmentNum);
154 152
                     throw new \InvalidArgumentException("Invalid type of $ord fragment. Isn't it a misplaced parameter value?");
155 153
                 }
@@ -195,8 +193,7 @@  discard block
 block discarded – undo
195 193
             $posParams = array_slice($fragmentsAndPositionalParams, $argsProcessed, $plcHdrCnt);
196 194
             if (count($posParams) == $plcHdrCnt) {
197 195
                 $overallPosParams = array_merge($overallPosParams, $posParams);
198
-            }
199
-            else {
196
+            } else {
200 197
                 $ord = StringUtils::englishOrd($curFragmentNum);
201 198
                 throw new \InvalidArgumentException("Not enough positional parameters for the $ord fragment");
202 199
             }
@@ -239,8 +236,7 @@  discard block
 block discarded – undo
239 236
     {
240 237
         if (isset($this->unsatisfiedParams[$nameOrPosition])) {
241 238
             unset($this->unsatisfiedParams[$nameOrPosition]);
242
-        }
243
-        elseif (!array_key_exists($nameOrPosition, $this->params)) {
239
+        } elseif (!array_key_exists($nameOrPosition, $this->params)) {
244 240
             throw new \InvalidArgumentException("The SQL pattern does not have parameter '$nameOrPosition'");
245 241
         }
246 242
 
@@ -287,8 +283,7 @@  discard block
 block discarded – undo
287 283
             $names = array_keys($this->unsatisfiedParams);
288 284
             if (count($names) == 1) {
289 285
                 $msg = sprintf('Value for parameter "%s" has not been set.', $names[0]);
290
-            }
291
-            else {
286
+            } else {
292 287
                 $msg = sprintf(
293 288
                     'Values for parameters %s and "%s" have not been set.',
294 289
                     array_map(function ($s) { return "\"$s\""; }, array_slice($names, 0, -1))
@@ -318,14 +313,12 @@  discard block
 block discarded – undo
318 313
                     if (!$placeholder->isSchemaNameQuoted()) {
319 314
                         $schemaName = mb_strtolower($schemaName); // OPT: SqlPatternPlaceholder might also store the lower-case name, which might be cached
320 315
                     }
321
-                }
322
-                elseif ($placeholder->isTypeNameQuoted()) {
316
+                } elseif ($placeholder->isTypeNameQuoted()) {
323 317
                     $schemaName = false;
324 318
                 }
325 319
 
326 320
                 $converter = $typeDictionary->requireTypeByName($typeName, $schemaName);
327
-            }
328
-            else {
321
+            } else {
329 322
                 $converter = $typeDictionary->requireTypeByValue($value);
330 323
             }
331 324
             $serializedValue = $converter->serializeValue($value);
Please login to merge, or discard this patch.
src/Ivory/Result/CommandResult.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 
4 4
 class CommandResult extends Result implements ICommandResult
5 5
 {
6
-	public function __construct($resultHandler, $lastNotice = null)
7
-	{
8
-		parent::__construct($resultHandler, $lastNotice);
9
-	}
6
+    public function __construct($resultHandler, $lastNotice = null)
7
+    {
8
+        parent::__construct($resultHandler, $lastNotice);
9
+    }
10 10
 
11
-	public function getAffectedRows()
12
-	{
11
+    public function getAffectedRows()
12
+    {
13 13
         return pg_affected_rows($this->handler);
14
-	}
14
+    }
15 15
 }
Please login to merge, or discard this patch.