Passed
Branch master (73cfe8)
by Ondřej
06:41
created
src/Ivory/Relation/ProjectedRelation.php 1 patch
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,14 +32,12 @@  discard block
 block discarded – undo
32 32
                 }
33 33
                 $columns[] = new Column($this, count($this->projectionList), $colName, $srcCols[$value]->getType());
34 34
                 $this->projectionList[] = (int)$value;
35
-            }
36
-            elseif (is_string($value)) { // column name
35
+            } elseif (is_string($value)) { // column name
37 36
                 if ($value[0] == '/') { // PCRE macro
38 37
                     $pcre = $value;
39 38
                     $matchAll = true;
40 39
                     $repl = ($nameSpecified ? $key : null);
41
-                }
42
-                else {
40
+                } else {
43 41
                     $pcre = self::simpleMacroPatternToPcre($value, $starCnt);
44 42
                     $matchAll = ($starCnt > 0);
45 43
                     $repl = ($nameSpecified ? self::simpleMacroReplacementToPcre($key) : null);
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
                     if (!$matchAll) {
56 54
                         $matched = array_slice($matched, 0, 1, true);
57 55
                     }
58
-                }
59
-                else {
56
+                } else {
60 57
                     $matched = [];
61 58
                     foreach ($srcCols as $i => $c) {
62 59
                         if ($c->getName() !== null) {
@@ -77,12 +74,10 @@  discard block
 block discarded – undo
77 74
                     $columns[] = new Column($this, count($this->projectionList), $cn, $srcCols[$i]->getType());
78 75
                     $this->projectionList[] = $i;
79 76
                 }
80
-            }
81
-            elseif ($value instanceof ITupleEvaluator || $value instanceof \Closure) {
77
+            } elseif ($value instanceof ITupleEvaluator || $value instanceof \Closure) {
82 78
                 $columns[] = new Column($this, $value, $colName, null);
83 79
                 $this->projectionList[] = $value;
84
-            }
85
-            else {
80
+            } else {
86 81
                 throw new \InvalidArgumentException("Invalid specification of the projection item '$key'");
87 82
             }
88 83
         }
@@ -98,14 +93,11 @@  discard block
 block discarded – undo
98 93
         foreach ($this->projectionList as $i => $spec) {
99 94
             if (is_int($spec)) {
100 95
                 $data[$i] = $srcTuple[$spec];
101
-            }
102
-            elseif ($spec instanceof ITupleEvaluator) {
96
+            } elseif ($spec instanceof ITupleEvaluator) {
103 97
                 $data[$i] = $spec->evaluate($srcTuple);
104
-            }
105
-            elseif ($spec instanceof \Closure) {
98
+            } elseif ($spec instanceof \Closure) {
106 99
                 $data[$i] = call_user_func($spec, $srcTuple);
107
-            }
108
-            else {
100
+            } else {
109 101
                 throw new InternalException("The type of projection list item $i is not supported");
110 102
             }
111 103
         }
Please login to merge, or discard this patch.
src/Ivory/Connection/ICachingConnConfig.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -29,35 +29,35 @@
 block discarded – undo
29 29
  */
30 30
 interface ICachingConnConfig extends IConnConfig
31 31
 {
32
-	/**
33
-	 * Invalidates the cache of configuration values. Next time a configuration option is read, its fresh value is
34
-	 * queried from the database.
35
-	 *
36
-	 * @param string|string[] one or more names of parameters the cached values of which to invalidate;
37
-	 *                        <tt>null</tt> invalidates everything
38
-	 */
39
-	function invalidateCache($paramName = null);;
32
+    /**
33
+     * Invalidates the cache of configuration values. Next time a configuration option is read, its fresh value is
34
+     * queried from the database.
35
+     *
36
+     * @param string|string[] one or more names of parameters the cached values of which to invalidate;
37
+     *                        <tt>null</tt> invalidates everything
38
+     */
39
+    function invalidateCache($paramName = null);;
40 40
 
41
-	/**
42
-	 * Disables caching of values of a given configuration parameter, or of any configuration parameter.
43
-	 *
44
-	 * This is useful for parameters changed indirectly, e.g., using a custom SQL query or within a stored function.
45
-	 *
46
-	 * Use {@link enableCaching()} to enable the caching again.
47
-	 *
48
-	 * @param string|string[] $paramName one or more names of parameters to disabled caching values of;
49
-	 *                                   <tt>null</tt> disables the caching altogether
50
-	 */
51
-	function disableCaching($paramName = null);
41
+    /**
42
+     * Disables caching of values of a given configuration parameter, or of any configuration parameter.
43
+     *
44
+     * This is useful for parameters changed indirectly, e.g., using a custom SQL query or within a stored function.
45
+     *
46
+     * Use {@link enableCaching()} to enable the caching again.
47
+     *
48
+     * @param string|string[] $paramName one or more names of parameters to disabled caching values of;
49
+     *                                   <tt>null</tt> disables the caching altogether
50
+     */
51
+    function disableCaching($paramName = null);
52 52
 
53
-	/**
54
-	 * Enables caching of configuration parameter values again, after it has been disabled by {@link disableCaching()}.
55
-	 *
56
-	 * Note that, if caching was disabled altogether using {@link disableCaching()}, this method will only turn caching
57
-	 * on for the requested parameters. Others will remain non-cached. To turn caching generally on, use `null` as the
58
-	 * argument (which is the default).
59
-	 *
60
-	 * @param string|string[] $paramName
61
-	 */
62
-	function enableCaching($paramName = null);
53
+    /**
54
+     * Enables caching of configuration parameter values again, after it has been disabled by {@link disableCaching()}.
55
+     *
56
+     * Note that, if caching was disabled altogether using {@link disableCaching()}, this method will only turn caching
57
+     * on for the requested parameters. Others will remain non-cached. To turn caching generally on, use `null` as the
58
+     * argument (which is the default).
59
+     *
60
+     * @param string|string[] $paramName
61
+     */
62
+    function enableCaching($paramName = null);
63 63
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 	 * @param string|string[] one or more names of parameters the cached values of which to invalidate;
37 37
 	 *                        <tt>null</tt> invalidates everything
38 38
 	 */
39
-	function invalidateCache($paramName = null);;
39
+	function invalidateCache($paramName = null); ;
40 40
 
41 41
 	/**
42 42
 	 * Disables caching of values of a given configuration parameter, or of any configuration parameter.
Please login to merge, or discard this patch.
src/Ivory/Connection/Connection.php 1 patch
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -8,270 +8,270 @@
 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
108
-
109
-	public function getStatementExceptionFactory()
110
-	{
111
-		return $this->stmtExec->getStatementExceptionFactory();
112
-	}
113
-
114
-	public function rawQuery($sqlStatement)
115
-	{
116
-		return $this->stmtExec->rawQuery($sqlStatement);
117
-	}
118
-
119
-	public function rawMultiQuery($sqlStatements)
120
-	{
121
-		return $this->stmtExec->rawMultiQuery($sqlStatements);
122
-	}
123
-
124
-	public function runScript($sqlScript)
125
-	{
126
-		return $this->stmtExec->runScript($sqlScript);
127
-	}
128
-
129
-	//endregion
130
-
131
-	//region Copy Control
132
-
133
-	public function copyFromFile($file, $table, $columns = null, $options = [])
134
-	{
135
-		return $this->copyCtl->copyFromFile($file, $table, $columns, $options);
136
-	}
137
-
138
-	public function copyFromProgram($program, $table, $columns = null, $options = [])
139
-	{
140
-		return $this->copyCtl->copyFromProgram($program, $table, $columns, $options);
141
-	}
142
-
143
-	public function copyFromInput($table, $columns = null, $options = [])
144
-	{
145
-		return $this->copyCtl->copyFromInput($table, $columns, $options);
146
-	}
147
-
148
-	public function copyToFile($file, $tableOrQuery, $columns = null, $options = [])
149
-	{
150
-		return $this->copyCtl->copyToFile($file, $tableOrQuery, $columns, $options);
151
-	}
152
-
153
-	public function copyToProgram($program, $tableOrQuery, $columns = null, $options = [])
154
-	{
155
-		return $this->copyCtl->copyToProgram($program, $tableOrQuery, $columns, $options);
156
-	}
157
-
158
-	public function copyToArray($table, $options = [])
159
-	{
160
-		return $this->copyCtl->copyToArray($table, $options);
161
-	}
162
-
163
-	//endregion
164
-
165
-	//region Transaction Control
166
-
167
-	public function inTransaction()
168
-	{
169
-		return $this->txCtl->inTransaction();
170
-	}
171
-
172
-	public function startTransaction($transactionOptions = 0)
173
-	{
174
-		return $this->txCtl->startTransaction($transactionOptions);
175
-	}
176
-
177
-	public function setupTransaction($transactionOptions)
178
-	{
179
-		$this->txCtl->setupTransaction($transactionOptions);
180
-	}
181
-
182
-	public function setupSubsequentTransactions($transactionOptions)
183
-	{
184
-		$this->txCtl->setupSubsequentTransactions($transactionOptions);
185
-	}
186
-
187
-	public function commit()
188
-	{
189
-		return $this->txCtl->commit();
190
-	}
191
-
192
-	public function rollback()
193
-	{
194
-		return $this->txCtl->rollback();
195
-	}
196
-
197
-	public function savepoint($name)
198
-	{
199
-		$this->txCtl->savepoint($name);
200
-	}
201
-
202
-	public function rollbackToSavepoint($name)
203
-	{
204
-		$this->txCtl->rollbackToSavepoint($name);
205
-	}
206
-
207
-	public function releaseSavepoint($name)
208
-	{
209
-		$this->txCtl->releaseSavepoint($name);
210
-	}
211
-
212
-	public function setTransactionSnapshot($snapshotId)
213
-	{
214
-		return $this->txCtl->setTransactionSnapshot($snapshotId);
215
-	}
216
-
217
-	public function exportTransactionSnapshot()
218
-	{
219
-		return $this->txCtl->exportTransactionSnapshot();
220
-	}
221
-
222
-	public function prepareTransaction($name)
223
-	{
224
-		return $this->txCtl->prepareTransaction($name);
225
-	}
226
-
227
-	public function commitPreparedTransaction($name)
228
-	{
229
-		$this->txCtl->commitPreparedTransaction($name);
230
-	}
231
-
232
-	public function rollbackPreparedTransaction($name)
233
-	{
234
-		$this->txCtl->rollbackPreparedTransaction($name);
235
-	}
236
-
237
-	public function listPreparedTransactions()
238
-	{
239
-		return $this->txCtl->listPreparedTransactions();
240
-	}
241
-
242
-	//endregion
243
-
244
-	//region IPC Control
245
-
246
-	public function getBackendPID()
247
-	{
248
-		return $this->ipcCtl->getBackendPID();
249
-	}
250
-
251
-	public function notify($channel, $payload = null)
252
-	{
253
-		$this->ipcCtl->notify($channel, $payload);
254
-	}
255
-
256
-	public function listen($channel)
257
-	{
258
-		$this->ipcCtl->listen($channel);
259
-	}
260
-
261
-	public function unlisten($channel)
262
-	{
263
-		$this->ipcCtl->unlisten($channel);
264
-	}
265
-
266
-	public function unlistenAll()
267
-	{
268
-		$this->ipcCtl->unlistenAll();
269
-	}
270
-
271
-	public function pollNotification()
272
-	{
273
-		return $this->ipcCtl->pollNotification();
274
-	}
275
-
276
-	//endregion
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
+
109
+    public function getStatementExceptionFactory()
110
+    {
111
+        return $this->stmtExec->getStatementExceptionFactory();
112
+    }
113
+
114
+    public function rawQuery($sqlStatement)
115
+    {
116
+        return $this->stmtExec->rawQuery($sqlStatement);
117
+    }
118
+
119
+    public function rawMultiQuery($sqlStatements)
120
+    {
121
+        return $this->stmtExec->rawMultiQuery($sqlStatements);
122
+    }
123
+
124
+    public function runScript($sqlScript)
125
+    {
126
+        return $this->stmtExec->runScript($sqlScript);
127
+    }
128
+
129
+    //endregion
130
+
131
+    //region Copy Control
132
+
133
+    public function copyFromFile($file, $table, $columns = null, $options = [])
134
+    {
135
+        return $this->copyCtl->copyFromFile($file, $table, $columns, $options);
136
+    }
137
+
138
+    public function copyFromProgram($program, $table, $columns = null, $options = [])
139
+    {
140
+        return $this->copyCtl->copyFromProgram($program, $table, $columns, $options);
141
+    }
142
+
143
+    public function copyFromInput($table, $columns = null, $options = [])
144
+    {
145
+        return $this->copyCtl->copyFromInput($table, $columns, $options);
146
+    }
147
+
148
+    public function copyToFile($file, $tableOrQuery, $columns = null, $options = [])
149
+    {
150
+        return $this->copyCtl->copyToFile($file, $tableOrQuery, $columns, $options);
151
+    }
152
+
153
+    public function copyToProgram($program, $tableOrQuery, $columns = null, $options = [])
154
+    {
155
+        return $this->copyCtl->copyToProgram($program, $tableOrQuery, $columns, $options);
156
+    }
157
+
158
+    public function copyToArray($table, $options = [])
159
+    {
160
+        return $this->copyCtl->copyToArray($table, $options);
161
+    }
162
+
163
+    //endregion
164
+
165
+    //region Transaction Control
166
+
167
+    public function inTransaction()
168
+    {
169
+        return $this->txCtl->inTransaction();
170
+    }
171
+
172
+    public function startTransaction($transactionOptions = 0)
173
+    {
174
+        return $this->txCtl->startTransaction($transactionOptions);
175
+    }
176
+
177
+    public function setupTransaction($transactionOptions)
178
+    {
179
+        $this->txCtl->setupTransaction($transactionOptions);
180
+    }
181
+
182
+    public function setupSubsequentTransactions($transactionOptions)
183
+    {
184
+        $this->txCtl->setupSubsequentTransactions($transactionOptions);
185
+    }
186
+
187
+    public function commit()
188
+    {
189
+        return $this->txCtl->commit();
190
+    }
191
+
192
+    public function rollback()
193
+    {
194
+        return $this->txCtl->rollback();
195
+    }
196
+
197
+    public function savepoint($name)
198
+    {
199
+        $this->txCtl->savepoint($name);
200
+    }
201
+
202
+    public function rollbackToSavepoint($name)
203
+    {
204
+        $this->txCtl->rollbackToSavepoint($name);
205
+    }
206
+
207
+    public function releaseSavepoint($name)
208
+    {
209
+        $this->txCtl->releaseSavepoint($name);
210
+    }
211
+
212
+    public function setTransactionSnapshot($snapshotId)
213
+    {
214
+        return $this->txCtl->setTransactionSnapshot($snapshotId);
215
+    }
216
+
217
+    public function exportTransactionSnapshot()
218
+    {
219
+        return $this->txCtl->exportTransactionSnapshot();
220
+    }
221
+
222
+    public function prepareTransaction($name)
223
+    {
224
+        return $this->txCtl->prepareTransaction($name);
225
+    }
226
+
227
+    public function commitPreparedTransaction($name)
228
+    {
229
+        $this->txCtl->commitPreparedTransaction($name);
230
+    }
231
+
232
+    public function rollbackPreparedTransaction($name)
233
+    {
234
+        $this->txCtl->rollbackPreparedTransaction($name);
235
+    }
236
+
237
+    public function listPreparedTransactions()
238
+    {
239
+        return $this->txCtl->listPreparedTransactions();
240
+    }
241
+
242
+    //endregion
243
+
244
+    //region IPC Control
245
+
246
+    public function getBackendPID()
247
+    {
248
+        return $this->ipcCtl->getBackendPID();
249
+    }
250
+
251
+    public function notify($channel, $payload = null)
252
+    {
253
+        $this->ipcCtl->notify($channel, $payload);
254
+    }
255
+
256
+    public function listen($channel)
257
+    {
258
+        $this->ipcCtl->listen($channel);
259
+    }
260
+
261
+    public function unlisten($channel)
262
+    {
263
+        $this->ipcCtl->unlisten($channel);
264
+    }
265
+
266
+    public function unlistenAll()
267
+    {
268
+        $this->ipcCtl->unlistenAll();
269
+    }
270
+
271
+    public function pollNotification()
272
+    {
273
+        return $this->ipcCtl->pollNotification();
274
+    }
275
+
276
+    //endregion
277 277
 }
Please login to merge, or discard this patch.
src/Ivory/Connection/ConnectionParameters.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -11,228 +11,228 @@
 block discarded – undo
11 11
  */
12 12
 class ConnectionParameters implements \ArrayAccess, \IteratorAggregate
13 13
 {
14
-	private $params = [];
15
-
16
-
17
-	public static function create($params)
18
-	{
19
-		if (is_array($params)) {
20
-			return new ConnectionParameters($params);
21
-		}
22
-		elseif (is_string($params)) {
23
-			if (preg_match("~^[^=']+://~", $params)) {
24
-				return self::fromUri($params);
25
-			}
26
-			else {
27
-				return self::fromConnectionString($params);
28
-			}
29
-		}
30
-		elseif ($params instanceof ConnectionParameters) {
31
-			return clone $params;
32
-		}
33
-		else {
34
-			throw new \InvalidArgumentException('params');
35
-		}
36
-	}
37
-
38
-
39
-	/**
40
-	 * Creates a connection parameters object from a RFC 3986 URI, e.g., `"postgresql://usr@localhost:5433/db"`.
41
-	 *
42
-	 * The accepted URI is the same as for the libpq connect function, described in the
43
-	 * {@link http://www.postgresql.org/docs/9.4/static/libpq-connect.html PostgreSQL documentation}.
44
-	 *
45
-	 * The following holds for the accepted URIs:
46
-	 * - the URI scheme designator must either be `"postgresql"` or `"postgres"`,
47
-	 * - any part of the URI is optional,
48
-	 * - username and password are used as credentials when connecting,
49
-	 * - server and port specify the server and port to connect to,
50
-	 * - the path specifies the name of the database to connect to,
51
-	 * - URI parameters are also supported, e.g., `"postgresql:///mydb?host=localhost&port=5433"`.
52
-	 *
53
-	 * @param string $uri
54
-	 * @return ConnectionParameters
55
-	 */
56
-	public static function fromUri($uri)
57
-	{
58
-		$c = parse_url($uri);
59
-		if ($c === false) {
60
-			// NOTE: parse_url() denies the input if the host part is omitted, even though RFC 3986 says it is optional
61
-			$auxUri = preg_replace('~//~', '//host', $uri, 1, $found); // NOTE: only preg_replace has a limit :-(
62
-			if (!$found || ($c = parse_url($auxUri)) === false) {
63
-				throw new \InvalidArgumentException('uri is malformed');
64
-			}
65
-			unset($c['host']);
66
-		}
67
-		if (!isset($c['scheme'])) {
68
-			throw new \InvalidArgumentException('uri scheme not specified');
69
-		}
70
-		if ($c['scheme'] != 'postgresql' && $c['scheme'] != 'postgres') {
71
-			throw new UnsupportedException('Only "postgresql" or "postgres" scheme is supported');
72
-		}
73
-
74
-		$params = array_filter(
75
-			[
76
-				'host' => (isset($c['host']) ? $c['host'] : null),
77
-				'port' => (isset($c['port']) ? $c['port'] : null),
78
-				'dbname' => (isset($c['path']) && strlen($c['path']) > 1 ? substr($c['path'], 1) : null),
79
-				'user' => (isset($c['user']) ? $c['user'] : null),
80
-				'password' => (isset($c['pass']) ? $c['pass'] : null),
81
-			],
82
-			'strlen'
83
-		);
84
-		if (isset($c['query'])) {
85
-			parse_str($c['query'], $pars);
86
-			$params = array_merge($params, $pars);
87
-		}
88
-
89
-		foreach ($params as &$par) {
90
-			$par = rawurldecode($par); // NOTE: neither parse_url() nor parse_str() do that automatically
91
-		}
92
-
93
-		return new ConnectionParameters($params);
94
-	}
95
-
96
-	/**
97
-	 * Creates a connection parameters object from a PostgreSQL connection string (see {@link pg_connect()}).
98
-	 *
99
-	 * A connection string is a set of `keyword = value` pairs, separated by space. Spaces around the equal sign are
100
-	 * optional. To contain special characters, the value may be enclosed in single quotes, using backslash as the
101
-	 * escape character.
102
-	 *
103
-	 * For details about the connection parameter keywords and values, see {@link __construct()}.
104
-	 *
105
-	 * @param string $connStr a PostgreSQL connection string
106
-	 * @return ConnectionParameters
107
-	 */
108
-	public static function fromConnectionString($connStr)
109
-	{
110
-		$params = [];
111
-		$offset = 0;
112
-		while (preg_match("~\\s*([^=\\s]+)\\s*=\\s*([^'\\s]+|'(?:[^'\\\\]|\\\\['\\\\])*')~", $connStr, $m, 0, $offset)) {
113
-			$k = $m[1];
114
-			$v = $m[2];
115
-			if ($v[0] == "'") {
116
-				$v = strtr(substr($v, 1, -1), ["\\'" => "'", '\\\\' => '\\']);
117
-			}
118
-			$params[$k] = $v;
119
-			$offset += strlen($m[0]);
120
-		}
121
-		if (strlen(trim(substr($connStr, $offset))) > 0) {
122
-			throw new \InvalidArgumentException('connStr');
123
-		}
124
-
125
-		return new ConnectionParameters($params);
126
-	}
127
-
128
-	/**
129
-	 * Initializes the connection parameters from an associative array of keywords to values.
130
-	 *
131
-	 * The most important are the following parameters:
132
-	 * - `host (string)`: the database server to connect to,
133
-	 * - `port (int)`: the port to connect to,
134
-	 * - `user (string)`: username to authenticate as,
135
-	 * - `password (string)`: password for the given username,
136
-	 * - `dbname (string)`: name of the database to connect to,
137
-	 * - `connect_timeout (int)`: connection timeout (0 means to wait indefinitely),
138
-	 * - `options (string)`: the runtime options to send to the server.
139
-	 *
140
-	 * For details, see the
141
-	 * {@link http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS PostgreSQL documentation}.
142
-	 * Any parameter may be omitted - the default is used then.
143
-	 *
144
-	 * @param array $params map: connection parameter keyword => value
145
-	 */
146
-	public function __construct($params)
147
-	{
148
-		$this->params = $params;
149
-	}
150
-
151
-	/**
152
-	 * @return string connection string suitable for the pg_connect() function
153
-	 */
154
-	public function buildConnectionString()
155
-	{
156
-		$kvPairs = [];
157
-		foreach ($this->params as $k => $v) {
158
-			if (strlen($v) == 0 || preg_match("~[\\s']~", $v)) {
159
-				$vstr = "'" . strtr($v, ["'" => "\\'", '\\' => '\\\\']) . "'";
160
-			}
161
-			else {
162
-				$vstr = $v;
163
-			}
164
-
165
-			$kvPairs[] = $k . '=' . $vstr;
166
-		}
167
-
168
-		return implode(' ', $kvPairs);
169
-	}
170
-
171
-
172
-	/**
173
-	 * @return string|null
174
-	 */
175
-	public function getHost()
176
-	{
177
-		return (isset($this->params['host']) ? $this->params['host'] : null);
178
-	}
179
-
180
-	/**
181
-	 * @return int|null
182
-	 */
183
-	public function getPort()
184
-	{
185
-		return (isset($this->params['port']) ? (int)$this->params['port'] : null);
186
-	}
187
-
188
-	/**
189
-	 * @return string|null
190
-	 */
191
-	public function getDbName()
192
-	{
193
-		return (isset($this->params['dbname']) ? $this->params['dbname'] : null);
194
-	}
195
-
196
-	/**
197
-	 * @return string|null
198
-	 */
199
-	public function getUsername()
200
-	{
201
-		return (isset($this->params['user']) ? $this->params['user'] : null);
202
-	}
203
-
204
-	/**
205
-	 * @return string|null
206
-	 */
207
-	public function getPassword()
208
-	{
209
-		return (isset($this->params['password']) ? $this->params['password'] : null);
210
-	}
211
-
212
-
213
-	public function getIterator()
214
-	{
215
-		return new \ArrayIterator($this->params);
216
-	}
217
-
218
-
219
-	public function offsetExists($offset)
220
-	{
221
-		return array_key_exists($offset, $this->params);
222
-	}
223
-
224
-	public function offsetGet($offset)
225
-	{
226
-		return $this->params[$offset];
227
-	}
228
-
229
-	public function offsetSet($offset, $value)
230
-	{
231
-		$this->params[$offset] = ($value === null ? null : (string)$value);
232
-	}
233
-
234
-	public function offsetUnset($offset)
235
-	{
236
-		unset($this->params[$offset]);
237
-	}
14
+    private $params = [];
15
+
16
+
17
+    public static function create($params)
18
+    {
19
+        if (is_array($params)) {
20
+            return new ConnectionParameters($params);
21
+        }
22
+        elseif (is_string($params)) {
23
+            if (preg_match("~^[^=']+://~", $params)) {
24
+                return self::fromUri($params);
25
+            }
26
+            else {
27
+                return self::fromConnectionString($params);
28
+            }
29
+        }
30
+        elseif ($params instanceof ConnectionParameters) {
31
+            return clone $params;
32
+        }
33
+        else {
34
+            throw new \InvalidArgumentException('params');
35
+        }
36
+    }
37
+
38
+
39
+    /**
40
+     * Creates a connection parameters object from a RFC 3986 URI, e.g., `"postgresql://usr@localhost:5433/db"`.
41
+     *
42
+     * The accepted URI is the same as for the libpq connect function, described in the
43
+     * {@link http://www.postgresql.org/docs/9.4/static/libpq-connect.html PostgreSQL documentation}.
44
+     *
45
+     * The following holds for the accepted URIs:
46
+     * - the URI scheme designator must either be `"postgresql"` or `"postgres"`,
47
+     * - any part of the URI is optional,
48
+     * - username and password are used as credentials when connecting,
49
+     * - server and port specify the server and port to connect to,
50
+     * - the path specifies the name of the database to connect to,
51
+     * - URI parameters are also supported, e.g., `"postgresql:///mydb?host=localhost&port=5433"`.
52
+     *
53
+     * @param string $uri
54
+     * @return ConnectionParameters
55
+     */
56
+    public static function fromUri($uri)
57
+    {
58
+        $c = parse_url($uri);
59
+        if ($c === false) {
60
+            // NOTE: parse_url() denies the input if the host part is omitted, even though RFC 3986 says it is optional
61
+            $auxUri = preg_replace('~//~', '//host', $uri, 1, $found); // NOTE: only preg_replace has a limit :-(
62
+            if (!$found || ($c = parse_url($auxUri)) === false) {
63
+                throw new \InvalidArgumentException('uri is malformed');
64
+            }
65
+            unset($c['host']);
66
+        }
67
+        if (!isset($c['scheme'])) {
68
+            throw new \InvalidArgumentException('uri scheme not specified');
69
+        }
70
+        if ($c['scheme'] != 'postgresql' && $c['scheme'] != 'postgres') {
71
+            throw new UnsupportedException('Only "postgresql" or "postgres" scheme is supported');
72
+        }
73
+
74
+        $params = array_filter(
75
+            [
76
+                'host' => (isset($c['host']) ? $c['host'] : null),
77
+                'port' => (isset($c['port']) ? $c['port'] : null),
78
+                'dbname' => (isset($c['path']) && strlen($c['path']) > 1 ? substr($c['path'], 1) : null),
79
+                'user' => (isset($c['user']) ? $c['user'] : null),
80
+                'password' => (isset($c['pass']) ? $c['pass'] : null),
81
+            ],
82
+            'strlen'
83
+        );
84
+        if (isset($c['query'])) {
85
+            parse_str($c['query'], $pars);
86
+            $params = array_merge($params, $pars);
87
+        }
88
+
89
+        foreach ($params as &$par) {
90
+            $par = rawurldecode($par); // NOTE: neither parse_url() nor parse_str() do that automatically
91
+        }
92
+
93
+        return new ConnectionParameters($params);
94
+    }
95
+
96
+    /**
97
+     * Creates a connection parameters object from a PostgreSQL connection string (see {@link pg_connect()}).
98
+     *
99
+     * A connection string is a set of `keyword = value` pairs, separated by space. Spaces around the equal sign are
100
+     * optional. To contain special characters, the value may be enclosed in single quotes, using backslash as the
101
+     * escape character.
102
+     *
103
+     * For details about the connection parameter keywords and values, see {@link __construct()}.
104
+     *
105
+     * @param string $connStr a PostgreSQL connection string
106
+     * @return ConnectionParameters
107
+     */
108
+    public static function fromConnectionString($connStr)
109
+    {
110
+        $params = [];
111
+        $offset = 0;
112
+        while (preg_match("~\\s*([^=\\s]+)\\s*=\\s*([^'\\s]+|'(?:[^'\\\\]|\\\\['\\\\])*')~", $connStr, $m, 0, $offset)) {
113
+            $k = $m[1];
114
+            $v = $m[2];
115
+            if ($v[0] == "'") {
116
+                $v = strtr(substr($v, 1, -1), ["\\'" => "'", '\\\\' => '\\']);
117
+            }
118
+            $params[$k] = $v;
119
+            $offset += strlen($m[0]);
120
+        }
121
+        if (strlen(trim(substr($connStr, $offset))) > 0) {
122
+            throw new \InvalidArgumentException('connStr');
123
+        }
124
+
125
+        return new ConnectionParameters($params);
126
+    }
127
+
128
+    /**
129
+     * Initializes the connection parameters from an associative array of keywords to values.
130
+     *
131
+     * The most important are the following parameters:
132
+     * - `host (string)`: the database server to connect to,
133
+     * - `port (int)`: the port to connect to,
134
+     * - `user (string)`: username to authenticate as,
135
+     * - `password (string)`: password for the given username,
136
+     * - `dbname (string)`: name of the database to connect to,
137
+     * - `connect_timeout (int)`: connection timeout (0 means to wait indefinitely),
138
+     * - `options (string)`: the runtime options to send to the server.
139
+     *
140
+     * For details, see the
141
+     * {@link http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS PostgreSQL documentation}.
142
+     * Any parameter may be omitted - the default is used then.
143
+     *
144
+     * @param array $params map: connection parameter keyword => value
145
+     */
146
+    public function __construct($params)
147
+    {
148
+        $this->params = $params;
149
+    }
150
+
151
+    /**
152
+     * @return string connection string suitable for the pg_connect() function
153
+     */
154
+    public function buildConnectionString()
155
+    {
156
+        $kvPairs = [];
157
+        foreach ($this->params as $k => $v) {
158
+            if (strlen($v) == 0 || preg_match("~[\\s']~", $v)) {
159
+                $vstr = "'" . strtr($v, ["'" => "\\'", '\\' => '\\\\']) . "'";
160
+            }
161
+            else {
162
+                $vstr = $v;
163
+            }
164
+
165
+            $kvPairs[] = $k . '=' . $vstr;
166
+        }
167
+
168
+        return implode(' ', $kvPairs);
169
+    }
170
+
171
+
172
+    /**
173
+     * @return string|null
174
+     */
175
+    public function getHost()
176
+    {
177
+        return (isset($this->params['host']) ? $this->params['host'] : null);
178
+    }
179
+
180
+    /**
181
+     * @return int|null
182
+     */
183
+    public function getPort()
184
+    {
185
+        return (isset($this->params['port']) ? (int)$this->params['port'] : null);
186
+    }
187
+
188
+    /**
189
+     * @return string|null
190
+     */
191
+    public function getDbName()
192
+    {
193
+        return (isset($this->params['dbname']) ? $this->params['dbname'] : null);
194
+    }
195
+
196
+    /**
197
+     * @return string|null
198
+     */
199
+    public function getUsername()
200
+    {
201
+        return (isset($this->params['user']) ? $this->params['user'] : null);
202
+    }
203
+
204
+    /**
205
+     * @return string|null
206
+     */
207
+    public function getPassword()
208
+    {
209
+        return (isset($this->params['password']) ? $this->params['password'] : null);
210
+    }
211
+
212
+
213
+    public function getIterator()
214
+    {
215
+        return new \ArrayIterator($this->params);
216
+    }
217
+
218
+
219
+    public function offsetExists($offset)
220
+    {
221
+        return array_key_exists($offset, $this->params);
222
+    }
223
+
224
+    public function offsetGet($offset)
225
+    {
226
+        return $this->params[$offset];
227
+    }
228
+
229
+    public function offsetSet($offset, $value)
230
+    {
231
+        $this->params[$offset] = ($value === null ? null : (string)$value);
232
+    }
233
+
234
+    public function offsetUnset($offset)
235
+    {
236
+        unset($this->params[$offset]);
237
+    }
238 238
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,19 +18,15 @@  discard block
 block discarded – undo
18 18
 	{
19 19
 		if (is_array($params)) {
20 20
 			return new ConnectionParameters($params);
21
-		}
22
-		elseif (is_string($params)) {
21
+		} elseif (is_string($params)) {
23 22
 			if (preg_match("~^[^=']+://~", $params)) {
24 23
 				return self::fromUri($params);
25
-			}
26
-			else {
24
+			} else {
27 25
 				return self::fromConnectionString($params);
28 26
 			}
29
-		}
30
-		elseif ($params instanceof ConnectionParameters) {
27
+		} elseif ($params instanceof ConnectionParameters) {
31 28
 			return clone $params;
32
-		}
33
-		else {
29
+		} else {
34 30
 			throw new \InvalidArgumentException('params');
35 31
 		}
36 32
 	}
@@ -157,8 +153,7 @@  discard block
 block discarded – undo
157 153
 		foreach ($this->params as $k => $v) {
158 154
 			if (strlen($v) == 0 || preg_match("~[\\s']~", $v)) {
159 155
 				$vstr = "'" . strtr($v, ["'" => "\\'", '\\' => '\\\\']) . "'";
160
-			}
161
-			else {
156
+			} else {
162 157
 				$vstr = $v;
163 158
 			}
164 159
 
Please login to merge, or discard this patch.
src/Ivory/Connection/ConfigParamType.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -102,8 +102,7 @@
 block discarded – undo
102 102
             case self::INTEGER_WITH_UNIT:
103 103
                 if ($unit !== null) {
104 104
                     return Quantity::fromValue($valueString, $unit);
105
-                }
106
-                else {
105
+                } else {
107 106
                     return Quantity::fromString($valueString);
108 107
                 }
109 108
         }
Please login to merge, or discard this patch.
src/Ivory/Connection/TxConfig.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,11 +63,9 @@
 block discarded – undo
63 63
                 throw new \InvalidArgumentException(__CLASS__ . " options specify both $errorDesc");
64 64
             }
65 65
             return true;
66
-        }
67
-        elseif ($options & $falseBit) {
66
+        } elseif ($options & $falseBit) {
68 67
             return false;
69
-        }
70
-        else {
68
+        } else {
71 69
             return null;
72 70
         }
73 71
     }
Please login to merge, or discard this patch.
src/Ivory/Connection/StatementExecution.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -138,8 +138,7 @@
 block discarded – undo
138 138
         if ($resNotice !== $connNotice) {
139 139
             $this->connCtl->setLastNotice($resNotice);
140 140
             return $resNotice;
141
-        }
142
-        else {
141
+        } else {
143 142
             return null;
144 143
         }
145 144
     }
Please login to merge, or discard this patch.
src/Ivory/Connection/CachingConnConfig.php 1 patch
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
     {
21 21
         if ($paramName === null) {
22 22
             $this->cachedValues = [];
23
-        }
24
-        else {
23
+        } else {
25 24
             foreach ((array)$paramName as $pn) {
26 25
                 unset($this->cachedValues[$pn]);
27 26
             }
@@ -33,13 +32,11 @@  discard block
 block discarded – undo
33 32
         if ($paramName === null) {
34 33
             $this->cacheEnabled = false;
35 34
             $this->cacheExceptions = [];
36
-        }
37
-        elseif ($this->cacheEnabled) {
35
+        } elseif ($this->cacheEnabled) {
38 36
             foreach ((array)$paramName as $pn) {
39 37
                 $this->cacheExceptions[$pn] = true;
40 38
             }
41
-        }
42
-        else {
39
+        } else {
43 40
             foreach ((array)$paramName as $pn) {
44 41
                 unset($this->cacheExceptions[$pn]);
45 42
             }
@@ -53,13 +50,11 @@  discard block
 block discarded – undo
53 50
         if ($paramName === null) {
54 51
             $this->cacheEnabled = true;
55 52
             $this->cacheExceptions = [];
56
-        }
57
-        elseif (!$this->cacheEnabled) {
53
+        } elseif (!$this->cacheEnabled) {
58 54
             foreach ((array)$paramName as $pn) {
59 55
                 $this->cacheExceptions[$pn] = true;
60 56
             }
61
-        }
62
-        else {
57
+        } else {
63 58
             foreach ((array)$paramName as $pn) {
64 59
                 unset($this->cacheExceptions[$pn]);
65 60
             }
Please login to merge, or discard this patch.
src/Ivory/Connection/TypeControl.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
 
64 64
     private function setupTypeDictionaryUndefinedHandler()
65 65
     {
66
-        $handler = function ($oid, $schemaName, $typeName, $value) {
66
+        $handler = function($oid, $schemaName, $typeName, $value) {
67 67
             $compiler = new IntrospectingTypeDictionaryCompiler($this->connection, $this->connCtl->requireConnection());
68 68
             $dict = $compiler->compileTypeDictionary($this);
69 69
             $this->initTypeDictionary($dict);
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,14 +70,11 @@
 block discarded – undo
70 70
 
71 71
             if ($oid !== null) {
72 72
                 $type = $dict->requireTypeByOid($oid);
73
-            }
74
-            elseif ($typeName !== null) {
73
+            } elseif ($typeName !== null) {
75 74
                 $type = $dict->requireTypeByName($typeName, $schemaName);
76
-            }
77
-            elseif ($value !== null) {
75
+            } elseif ($value !== null) {
78 76
                 $type = $dict->requireTypeByValue($value);
79
-            }
80
-            else {
77
+            } else {
81 78
                 return null;
82 79
             }
83 80
 
Please login to merge, or discard this patch.