Passed
Branch master (3a7502)
by Adrian
02:07
created
src/Traits/GroupBy.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
 	 * @return $this
25 25
 	 * @throws QueryException
26 26
 	 */
27
-	public function groupBy( $column, array $allowedColumns = [] )
27
+	public function groupBy($column, array $allowedColumns = [])
28 28
 	{
29
-		$column = trim( $column );
29
+		$column = trim($column);
30 30
 
31
-		if ( !$this->validateColumn( $column, $allowedColumns ) )
32
-			throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
31
+		if (!$this->validateColumn($column, $allowedColumns))
32
+			throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
33 33
 
34
-		$this->queryStructure->setElement( QueryStructure::GROUP_BY, $column );
34
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $column);
35 35
 
36 36
 		return $this;
37 37
 	}
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 	 * @return $this
44 44
 	 * @throws QueryException
45 45
 	 */
46
-	public function groupByDesc( $column, array $allowedColumns = [] )
46
+	public function groupByDesc($column, array $allowedColumns = [])
47 47
 	{
48
-		$column = trim( $column );
48
+		$column = trim($column);
49 49
 
50
-		if ( !$this->validateColumn( $column, $allowedColumns ) )
51
-			throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
50
+		if (!$this->validateColumn($column, $allowedColumns))
51
+			throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
52 52
 
53
-		$this->queryStructure->setElement( QueryStructure::GROUP_BY, $column . ' DESC' );
53
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC');
54 54
 
55 55
 		return $this;
56 56
 	}
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 * @param $expression
61 61
 	 * @return $this
62 62
 	 */
63
-	public function groupByExpression( $expression )
63
+	public function groupByExpression($expression)
64 64
 	{
65
-		$this->queryStructure->setElement( QueryStructure::GROUP_BY, $expression );
65
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression);
66 66
 
67 67
 		return $this;
68 68
 	}
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	private function getGroupBySyntax()
75 75
 	{
76
-		if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) )
77
-			return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' );
76
+		if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY)))
77
+			return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', ');
78 78
 
79 79
 		return '';
80 80
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,8 +28,9 @@  discard block
 block discarded – undo
28 28
 	{
29 29
 		$column = trim( $column );
30 30
 
31
-		if ( !$this->validateColumn( $column, $allowedColumns ) )
32
-			throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
31
+		if ( !$this->validateColumn( $column, $allowedColumns ) ) {
32
+					throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
33
+		}
33 34
 
34 35
 		$this->queryStructure->setElement( QueryStructure::GROUP_BY, $column );
35 36
 
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	{
48 49
 		$column = trim( $column );
49 50
 
50
-		if ( !$this->validateColumn( $column, $allowedColumns ) )
51
-			throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
51
+		if ( !$this->validateColumn( $column, $allowedColumns ) ) {
52
+					throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME );
53
+		}
52 54
 
53 55
 		$this->queryStructure->setElement( QueryStructure::GROUP_BY, $column . ' DESC' );
54 56
 
@@ -73,8 +75,9 @@  discard block
 block discarded – undo
73 75
 	 */
74 76
 	private function getGroupBySyntax()
75 77
 	{
76
-		if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) )
77
-			return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' );
78
+		if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) {
79
+					return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' );
80
+		}
78 81
 
79 82
 		return '';
80 83
 	}
Please login to merge, or discard this patch.
src/Dependencies/QueryHelper.php 2 patches
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 	 * @param string $string
16 16
 	 * @return mixed|string
17 17
 	 */
18
-	public static function clearMultipleSpaces( $string = '' )
18
+	public static function clearMultipleSpaces($string = '')
19 19
 	{
20
-		$string = preg_replace( '/\s+/', ' ', $string );
21
-		$string = trim( $string );
20
+		$string = preg_replace('/\s+/', ' ', $string);
21
+		$string = trim($string);
22 22
 
23 23
 		return $string;
24 24
 	}
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 * @param $val
28 28
 	 * @return bool
29 29
 	 */
30
-	public static function isInteger( $val )
30
+	public static function isInteger($val)
31 31
 	{
32
-		$val = trim( $val );
32
+		$val = trim($val);
33 33
 
34
-		return is_numeric( $val ) && floor( $val ) == $val;
34
+		return is_numeric($val) && floor($val) == $val;
35 35
 	}
36 36
 
37 37
 	/**
@@ -39,34 +39,34 @@  discard block
 block discarded – undo
39 39
 	 * @return bool
40 40
 	 * @i
41 41
 	 */
42
-	public static function isDecimal( $val )
42
+	public static function isDecimal($val)
43 43
 	{
44
-		$val = trim( $val );
44
+		$val = trim($val);
45 45
 
46
-		return is_numeric( $val ) && floor( $val ) != $val;
46
+		return is_numeric($val) && floor($val) != $val;
47 47
 	}
48 48
 
49
-	public static function isValidOrderBy( $order_by_parameter )
49
+	public static function isValidOrderBy($order_by_parameter)
50 50
 	{
51 51
 
52
-		$columns = array( 'first_name', 'last_name', 'zip', 'created_at' );
52
+		$columns = array('first_name', 'last_name', 'zip', 'created_at');
53 53
 
54
-		$parts = preg_split( "/[\s,]+/", $order_by_parameter );
54
+		$parts = preg_split("/[\s,]+/", $order_by_parameter);
55 55
 
56
-		foreach ( $parts as $part ) {
57
-			$subparts = preg_split( "/\s+/", $part );
56
+		foreach ($parts as $part) {
57
+			$subparts = preg_split("/\s+/", $part);
58 58
 
59
-			if ( count( $subparts ) < 0 || count( $subparts ) > 2 ) {
59
+			if (count($subparts) < 0 || count($subparts) > 2) {
60 60
 				// Too many or too few parts.
61 61
 				return false;
62 62
 			}
63 63
 
64
-			if ( !in_array( $subparts[0], $columns ) ) {
64
+			if (!in_array($subparts[0], $columns)) {
65 65
 				// Column name is invalid.
66 66
 				return false;
67 67
 			}
68 68
 
69
-			if ( count( $subparts ) == 2 && !in_array( strtoupper( $subparts[1] ), array( 'ASC', 'DESC' ) ) ) {
69
+			if (count($subparts) == 2 && !in_array(strtoupper($subparts[1]), array('ASC', 'DESC'))) {
70 70
 				// ASC or DESC is invalid
71 71
 				return false;
72 72
 			}
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
 	 * @param string $delimiter
82 82
 	 * @return array
83 83
 	 */
84
-	public static function explode( $string, $delimiter = ',' )
84
+	public static function explode($string, $delimiter = ',')
85 85
 	{
86
-		$brutArray = explode( $delimiter, $string );
86
+		$brutArray = explode($delimiter, $string);
87 87
 		$newArray = array();
88
-		foreach ( $brutArray as $value ) {
89
-			$value = trim( $value );
90
-			if ( '' !== $value ) $newArray[] = $value;
88
+		foreach ($brutArray as $value) {
89
+			$value = trim($value);
90
+			if ('' !== $value) $newArray[] = $value;
91 91
 		}
92 92
 
93 93
 		return $newArray;
94 94
 	}
95 95
 
96
-	public static function alphaNum( $string )
96
+	public static function alphaNum($string)
97 97
 	{
98
-		$string = preg_replace( "/[^a-zA-Z0-9 _,]+/", "", $string );
98
+		$string = preg_replace("/[^a-zA-Z0-9 _,]+/", "", $string);
99 99
 
100
-		return self::clearMultipleSpaces( $string );
100
+		return self::clearMultipleSpaces($string);
101 101
 	}
102 102
 
103 103
 	/**
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 	 * @param string $delimiter
106 106
 	 * @return string
107 107
 	 */
108
-	public static function implode( array $array, $delimiter = ',' )
108
+	public static function implode(array $array, $delimiter = ',')
109 109
 	{
110
-		$string = implode( $delimiter, $array );
111
-		$string = trim( $string );
112
-		$string = trim( $string, trim( $delimiter ) );
113
-		$string = trim( $string );
110
+		$string = implode($delimiter, $array);
111
+		$string = trim($string);
112
+		$string = trim($string, trim($delimiter));
113
+		$string = trim($string);
114 114
 
115 115
 		return $string;
116 116
 	}
@@ -119,36 +119,36 @@  discard block
 block discarded – undo
119 119
 	 * @param $string
120 120
 	 * @return mixed|string
121 121
 	 */
122
-	public static function clearQuotes( $string )
122
+	public static function clearQuotes($string)
123 123
 	{
124
-		$search = array( '"', "'" );
124
+		$search = array('"', "'");
125 125
 		$replace = '';
126
-		$string = str_replace( $search, $replace, $string );
126
+		$string = str_replace($search, $replace, $string);
127 127
 
128
-		return self::clearMultipleSpaces( $string );
128
+		return self::clearMultipleSpaces($string);
129 129
 	}
130 130
 
131 131
 	/**
132 132
 	 * @param int $length
133 133
 	 * @return string
134 134
 	 */
135
-	public static function random( $length = 5 )
135
+	public static function random($length = 5)
136 136
 	{
137 137
 		$characters = 'abcdefghijklmnopqrstuvwxyz';
138
-		$charactersLength = strlen( $characters );
138
+		$charactersLength = strlen($characters);
139 139
 		$randomString = '';
140
-		for ( $i = 0; $i < $length; $i++ )
141
-			$randomString .= $characters[ rand( 0, $charactersLength - 1 ) ];
140
+		for ($i = 0; $i < $length; $i++)
141
+			$randomString .= $characters[rand(0, $charactersLength - 1)];
142 142
 
143
-		return str_shuffle( $randomString );
143
+		return str_shuffle($randomString);
144 144
 	}
145 145
 
146
-	public static function limitString( $rowCount, $offset = null )
146
+	public static function limitString($rowCount, $offset = null)
147 147
 	{
148
-		$rowCount = intval( $rowCount );
149
-		if ( is_null( $offset ) )
148
+		$rowCount = intval($rowCount);
149
+		if (is_null($offset))
150 150
 			return $rowCount;
151
-		$offset = intval( $offset );
151
+		$offset = intval($offset);
152 152
 
153 153
 		return "$offset, $rowCount";
154 154
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -87,7 +87,9 @@  discard block
 block discarded – undo
87 87
 		$newArray = array();
88 88
 		foreach ( $brutArray as $value ) {
89 89
 			$value = trim( $value );
90
-			if ( '' !== $value ) $newArray[] = $value;
90
+			if ( '' !== $value ) {
91
+				$newArray[] = $value;
92
+			}
91 93
 		}
92 94
 
93 95
 		return $newArray;
@@ -137,8 +139,9 @@  discard block
 block discarded – undo
137 139
 		$characters = 'abcdefghijklmnopqrstuvwxyz';
138 140
 		$charactersLength = strlen( $characters );
139 141
 		$randomString = '';
140
-		for ( $i = 0; $i < $length; $i++ )
141
-			$randomString .= $characters[ rand( 0, $charactersLength - 1 ) ];
142
+		for ( $i = 0; $i < $length; $i++ ) {
143
+					$randomString .= $characters[ rand( 0, $charactersLength - 1 ) ];
144
+		}
142 145
 
143 146
 		return str_shuffle( $randomString );
144 147
 	}
@@ -146,8 +149,9 @@  discard block
 block discarded – undo
146 149
 	public static function limitString( $rowCount, $offset = null )
147 150
 	{
148 151
 		$rowCount = intval( $rowCount );
149
-		if ( is_null( $offset ) )
150
-			return $rowCount;
152
+		if ( is_null( $offset ) ) {
153
+					return $rowCount;
154
+		}
151 155
 		$offset = intval( $offset );
152 156
 
153 157
 		return "$offset, $rowCount";
Please login to merge, or discard this patch.
src/Dependencies/QueryStructure.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	{
86 86
 		$this->syntaxEL = $this->init();
87 87
 
88
-		foreach ( $this->syntaxEL as $name => $value )
89
-			$this->typeEL[ $name ] = gettype( $value );
88
+		foreach ($this->syntaxEL as $name => $value)
89
+			$this->typeEL[$name] = gettype($value);
90 90
 
91 91
 	}
92 92
 
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 
129 129
 	private function makeStatementInstance()
130 130
 	{
131
-		$instance = QueryHelper::random( 5 );
132
-		while ( in_array( $instance, self::$usedInstanceIds ) ) {
133
-			$instance = QueryHelper::random( 7 );
131
+		$instance = QueryHelper::random(5);
132
+		while (in_array($instance, self::$usedInstanceIds)) {
133
+			$instance = QueryHelper::random(7);
134 134
 		}
135 135
 		self::$usedInstanceIds[] = $instance;
136 136
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	/**
159 159
 	 * @param $elements
160 160
 	 */
161
-	public function setAllElements( $elements )
161
+	public function setAllElements($elements)
162 162
 	{
163 163
 		$this->syntaxEL = $elements;
164 164
 	}
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 * @throws QueryException
172 172
 	 */
173
-	public function setElement( $name, $value )
173
+	public function setElement($name, $value)
174 174
 	{
175
-		if ( !array_key_exists( $name, $this->syntaxEL ) )
176
-			throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
175
+		if (!array_key_exists($name, $this->syntaxEL))
176
+			throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
177 177
 
178
-		if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) )
178
+		if ($name == self::TABLE && is_a($value, QueryStatement::class))
179 179
 			return true;
180 180
 
181
-		if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY )
182
-			$this->syntaxEL[ $name ][] = $value;
181
+		if ($this->typeEL[$name] === self::ELEMENT_TYPE_ARRAY)
182
+			$this->syntaxEL[$name][] = $value;
183 183
 		else
184
-			$this->syntaxEL[ $name ] = $value;
184
+			$this->syntaxEL[$name] = $value;
185 185
 
186 186
 		return true;
187 187
 	}
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
 	 * @param $elementValue
193 193
 	 * @throws QueryException
194 194
 	 */
195
-	public function replaceElement( $elementName, $elementValue )
195
+	public function replaceElement($elementName, $elementValue)
196 196
 	{
197
-		if ( !array_key_exists( $elementName, $this->syntaxEL ) )
198
-			throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
197
+		if (!array_key_exists($elementName, $this->syntaxEL))
198
+			throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
199 199
 
200
-		$this->syntaxEL[ $elementName ] = $elementValue;
200
+		$this->syntaxEL[$elementName] = $elementValue;
201 201
 	}
202 202
 
203 203
 
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 	 * @param string $name
206 206
 	 * @return mixed
207 207
 	 */
208
-	public function getElement( $name )
208
+	public function getElement($name)
209 209
 	{
210
-		return $this->syntaxEL[ $name ];
210
+		return $this->syntaxEL[$name];
211 211
 	}
212 212
 
213 213
 
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 	 * @param $name
216 216
 	 * @param $value
217 217
 	 */
218
-	public function setParams( $name, $value )
218
+	public function setParams($name, $value)
219 219
 	{
220
-		$this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $name ] = $value;
220
+		$this->syntaxEL[QueryStructure::BIND_PARAMS][$name] = $value;
221 221
 	}
222 222
 
223 223
 
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 	 * @param $value
227 227
 	 * @return string
228 228
 	 */
229
-	public function bindParam( $name, $value )
229
+	public function bindParam($name, $value)
230 230
 	{
231
-		$pdoName = $this->index( $name );
232
-		$this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $pdoName ] = $value;
231
+		$pdoName = $this->index($name);
232
+		$this->syntaxEL[QueryStructure::BIND_PARAMS][$pdoName] = $value;
233 233
 
234 234
 		return ':' . $pdoName;
235 235
 	}
@@ -241,27 +241,27 @@  discard block
 block discarded – undo
241 241
 	 * @param string $search
242 242
 	 * @return string
243 243
 	 */
244
-	public function bindParamsExpression( $expression, array $params = [], $search = '?' )
244
+	public function bindParamsExpression($expression, array $params = [], $search = '?')
245 245
 	{
246
-		if ( !count( $params ) )
246
+		if (!count($params))
247 247
 			return $expression;
248 248
 
249
-		if ( strpos( $expression, $search ) === false )
249
+		if (strpos($expression, $search) === false)
250 250
 			return $expression;
251 251
 
252
-		$params = array_slice( $params, 0, substr_count( $expression, $search ) );
252
+		$params = array_slice($params, 0, substr_count($expression, $search));
253 253
 
254 254
 		$i = 0;
255 255
 		$arrayReturn = [];
256
-		$expressionToArray = explode( $search, $expression );
256
+		$expressionToArray = explode($search, $expression);
257 257
 
258
-		foreach ( $expressionToArray as $sub ) {
258
+		foreach ($expressionToArray as $sub) {
259 259
 			$arrayReturn[] = $sub;
260
-			$arrayReturn[] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : '';
260
+			$arrayReturn[] = array_key_exists($i, $params) ? $this->bindParam('exp', $params[$i]) : '';
261 261
 			$i++;
262 262
 		}
263 263
 
264
-		return implode( '', $arrayReturn );
264
+		return implode('', $arrayReturn);
265 265
 	}
266 266
 
267 267
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 	 * @param string $fieldName
270 270
 	 * @return string
271 271
 	 */
272
-	public function index( $fieldName = '' )
272
+	public function index($fieldName = '')
273 273
 	{
274
-		return trim( $fieldName ) . '_' . $this->syntaxEL[ self::INSTANCE ] . '_' . ++$this->counter . 'i';
274
+		return trim($fieldName) . '_' . $this->syntaxEL[self::INSTANCE] . '_' . ++$this->counter . 'i';
275 275
 	}
276 276
 
277 277
 }
278 278
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +23 added lines, -16 removed lines patch added patch discarded remove patch
@@ -85,8 +85,9 @@  discard block
 block discarded – undo
85 85
 	{
86 86
 		$this->syntaxEL = $this->init();
87 87
 
88
-		foreach ( $this->syntaxEL as $name => $value )
89
-			$this->typeEL[ $name ] = gettype( $value );
88
+		foreach ( $this->syntaxEL as $name => $value ) {
89
+					$this->typeEL[ $name ] = gettype( $value );
90
+		}
90 91
 
91 92
 	}
92 93
 
@@ -172,16 +173,19 @@  discard block
 block discarded – undo
172 173
 	 */
173 174
 	public function setElement( $name, $value )
174 175
 	{
175
-		if ( !array_key_exists( $name, $this->syntaxEL ) )
176
-			throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
176
+		if ( !array_key_exists( $name, $this->syntaxEL ) ) {
177
+					throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
178
+		}
177 179
 
178
-		if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) )
179
-			return true;
180
+		if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) {
181
+					return true;
182
+		}
180 183
 
181
-		if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY )
182
-			$this->syntaxEL[ $name ][] = $value;
183
-		else
184
-			$this->syntaxEL[ $name ] = $value;
184
+		if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) {
185
+					$this->syntaxEL[ $name ][] = $value;
186
+		} else {
187
+					$this->syntaxEL[ $name ] = $value;
188
+		}
185 189
 
186 190
 		return true;
187 191
 	}
@@ -194,8 +198,9 @@  discard block
 block discarded – undo
194 198
 	 */
195 199
 	public function replaceElement( $elementName, $elementValue )
196 200
 	{
197
-		if ( !array_key_exists( $elementName, $this->syntaxEL ) )
198
-			throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
201
+		if ( !array_key_exists( $elementName, $this->syntaxEL ) ) {
202
+					throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND );
203
+		}
199 204
 
200 205
 		$this->syntaxEL[ $elementName ] = $elementValue;
201 206
 	}
@@ -243,11 +248,13 @@  discard block
 block discarded – undo
243 248
 	 */
244 249
 	public function bindParamsExpression( $expression, array $params = [], $search = '?' )
245 250
 	{
246
-		if ( !count( $params ) )
247
-			return $expression;
251
+		if ( !count( $params ) ) {
252
+					return $expression;
253
+		}
248 254
 
249
-		if ( strpos( $expression, $search ) === false )
250
-			return $expression;
255
+		if ( strpos( $expression, $search ) === false ) {
256
+					return $expression;
257
+		}
251 258
 
252 259
 		$params = array_slice( $params, 0, substr_count( $expression, $search ) );
253 260
 
Please login to merge, or discard this patch.
src/Dependencies/Tree.php 2 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * Tree constructor.
59 59
 	 * @param array $flatArray
60 60
 	 */
61
-	public function __construct( array $flatArray )
61
+	public function __construct(array $flatArray)
62 62
 	{
63 63
 		$this->flatArray = $flatArray;
64 64
 		$this->prepareFlatArray();
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 * @param $idName
69 69
 	 * @return $this
70 70
 	 */
71
-	public function withIdName( $idName )
71
+	public function withIdName($idName)
72 72
 	{
73
-		$this->role[ self::ID_NAME ] = $idName;
73
+		$this->role[self::ID_NAME] = $idName;
74 74
 
75 75
 		return $this;
76 76
 	}
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	 * @param $parentIdName
80 80
 	 * @return $this
81 81
 	 */
82
-	public function withParentIdName( $parentIdName )
82
+	public function withParentIdName($parentIdName)
83 83
 	{
84
-		$this->role[ self::PARENT_ID_NAME ] = $parentIdName;
84
+		$this->role[self::PARENT_ID_NAME] = $parentIdName;
85 85
 
86 86
 		return $this;
87 87
 	}
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 	 * @param $childrenName
91 91
 	 * @return $this
92 92
 	 */
93
-	public function withChildrenName( $childrenName )
93
+	public function withChildrenName($childrenName)
94 94
 	{
95
-		$this->role[ self::CHILDREN_NAME ] = $childrenName;
95
+		$this->role[self::CHILDREN_NAME] = $childrenName;
96 96
 
97 97
 		return $this;
98 98
 	}
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	/**
101 101
 	 * @param string $name
102 102
 	 */
103
-	public function withDepthName( $name )
103
+	public function withDepthName($name)
104 104
 	{
105
-		$this->role[ self::DEPTH_NAME ] = $name;
105
+		$this->role[self::DEPTH_NAME] = $name;
106 106
 	}
107 107
 
108 108
 	/**
109 109
 	 * @param int|string $value
110 110
 	 * @return $this
111 111
 	 */
112
-	public function withRootValue( $value = 0 )
112
+	public function withRootValue($value = 0)
113 113
 	{
114 114
 		$this->rootValue = $value;
115 115
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function buildTree()
123 123
 	{
124
-		$this->treeArray = $this->createTree( $this->flatArray, $this->rootValue );
124
+		$this->treeArray = $this->createTree($this->flatArray, $this->rootValue);
125 125
 
126 126
 		return $this;
127 127
 	}
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 	 * @param mixed $nodeId
147 147
 	 * @return array
148 148
 	 */
149
-	public function getChildren( $nodeId )
149
+	public function getChildren($nodeId)
150 150
 	{
151 151
 		$findChildren = array();
152
-		foreach ( $this->flatArray as $key => $value ) {
153
-			if ( $value[ $this->role[ self::PARENT_ID_NAME ] ] == $nodeId ) {
154
-				$findChildren[] = $value[ $this->role[ self::ID_NAME ] ];
155
-				$sub = $this->getChildren( $value[ $this->role[ self::ID_NAME ] ] );
156
-				foreach ( $sub as $k => $v ) {
152
+		foreach ($this->flatArray as $key => $value) {
153
+			if ($value[$this->role[self::PARENT_ID_NAME]] == $nodeId) {
154
+				$findChildren[] = $value[$this->role[self::ID_NAME]];
155
+				$sub = $this->getChildren($value[$this->role[self::ID_NAME]]);
156
+				foreach ($sub as $k => $v) {
157 157
 					$findChildren[] = $v;
158 158
 				}
159 159
 			}
@@ -162,50 +162,50 @@  discard block
 block discarded – undo
162 162
 		return $findChildren;
163 163
 	}
164 164
 
165
-	public function getParents( $nodeId )
165
+	public function getParents($nodeId)
166 166
 	{
167 167
 		$this->parents = [];
168
-		$this->calculateParents( $nodeId );
168
+		$this->calculateParents($nodeId);
169 169
 
170 170
 		return $this->parents;
171 171
 	}
172 172
 
173
-	private function calculateParents( $nodeId )
173
+	private function calculateParents($nodeId)
174 174
 	{
175 175
 
176
-		if(!array_key_exists($this->flatArray[ $nodeId ][ $this->role[ self::PARENT_ID_NAME ] ], $this->flatArray))
176
+		if (!array_key_exists($this->flatArray[$nodeId][$this->role[self::PARENT_ID_NAME]], $this->flatArray))
177 177
 			return false;
178 178
 
179
-		$parentNode = $this->flatArray[ $nodeId ][ $this->role[ self::PARENT_ID_NAME ] ];
179
+		$parentNode = $this->flatArray[$nodeId][$this->role[self::PARENT_ID_NAME]];
180 180
 
181
-		if ( $parentNode != $this->rootValue )
181
+		if ($parentNode != $this->rootValue)
182 182
 			$this->parents[] = $parentNode;
183 183
 
184
-		if ( $parentNode != $this->rootValue ) {
185
-			$this->calculateParents( $parentNode );
184
+		if ($parentNode != $this->rootValue) {
185
+			$this->calculateParents($parentNode);
186 186
 		}
187 187
 
188 188
 		return true;
189 189
 
190 190
 	}
191 191
 
192
-	private function createTree( array $elements, $parentId = 0, $depth = 0 )
192
+	private function createTree(array $elements, $parentId = 0, $depth = 0)
193 193
 	{
194 194
 		$tree = array();
195 195
 
196
-		foreach ( $elements as $element ) {
197
-			if ( $element[ $this->role[ self::PARENT_ID_NAME ] ] == $parentId ) {
196
+		foreach ($elements as $element) {
197
+			if ($element[$this->role[self::PARENT_ID_NAME]] == $parentId) {
198 198
 				$children = $this->createTree(
199 199
 					$elements,
200
-					$element[ $this->role[ self::ID_NAME ] ],
201
-					( $depth + 1 )
200
+					$element[$this->role[self::ID_NAME]],
201
+					($depth + 1)
202 202
 				);
203
-				$element[ $this->role[ self::DEPTH_NAME ] ] = $depth;
204
-				if ( $children ) {
205
-					$element[ $this->role[ self::CHILDREN_NAME ] ] = $children;
203
+				$element[$this->role[self::DEPTH_NAME]] = $depth;
204
+				if ($children) {
205
+					$element[$this->role[self::CHILDREN_NAME]] = $children;
206 206
 				}
207
-				$tree[ $element[ $this->role[ self::ID_NAME ] ] ] = $element;
208
-				unset( $elements[ $element[ $this->role[ self::ID_NAME ] ] ] );
207
+				$tree[$element[$this->role[self::ID_NAME]]] = $element;
208
+				unset($elements[$element[$this->role[self::ID_NAME]]]);
209 209
 			}
210 210
 		}
211 211
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	private function prepareFlatArray()
219 219
 	{
220
-		if ( self::isArrayAssoc( $this->flatArray ) )
220
+		if (self::isArrayAssoc($this->flatArray))
221 221
 			return true;
222 222
 
223 223
 		$newFlat = [];
224 224
 
225
-		foreach ( $this->flatArray as $value )
226
-			$newFlat[ $value[ $this->role[ self::ID_NAME ] ] ] = $value;
225
+		foreach ($this->flatArray as $value)
226
+			$newFlat[$value[$this->role[self::ID_NAME]]] = $value;
227 227
 
228 228
 		$this->flatArray = $newFlat;
229 229
 
@@ -235,11 +235,11 @@  discard block
 block discarded – undo
235 235
 	 * @param array $arr
236 236
 	 * @return bool
237 237
 	 */
238
-	public static function isArrayAssoc( array $arr )
238
+	public static function isArrayAssoc(array $arr)
239 239
 	{
240
-		if ( array() === $arr ) return false;
240
+		if (array() === $arr) return false;
241 241
 
242
-		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
242
+		return array_keys($arr) !== range(0, count($arr) - 1);
243 243
 	}
244 244
 
245 245
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -9 removed lines patch added patch discarded remove patch
@@ -173,13 +173,15 @@  discard block
 block discarded – undo
173 173
 	private function calculateParents( $nodeId )
174 174
 	{
175 175
 
176
-		if(!array_key_exists($this->flatArray[ $nodeId ][ $this->role[ self::PARENT_ID_NAME ] ], $this->flatArray))
177
-			return false;
176
+		if(!array_key_exists($this->flatArray[ $nodeId ][ $this->role[ self::PARENT_ID_NAME ] ], $this->flatArray)) {
177
+					return false;
178
+		}
178 179
 
179 180
 		$parentNode = $this->flatArray[ $nodeId ][ $this->role[ self::PARENT_ID_NAME ] ];
180 181
 
181
-		if ( $parentNode != $this->rootValue )
182
-			$this->parents[] = $parentNode;
182
+		if ( $parentNode != $this->rootValue ) {
183
+					$this->parents[] = $parentNode;
184
+		}
183 185
 
184 186
 		if ( $parentNode != $this->rootValue ) {
185 187
 			$this->calculateParents( $parentNode );
@@ -217,13 +219,15 @@  discard block
 block discarded – undo
217 219
 	 */
218 220
 	private function prepareFlatArray()
219 221
 	{
220
-		if ( self::isArrayAssoc( $this->flatArray ) )
221
-			return true;
222
+		if ( self::isArrayAssoc( $this->flatArray ) ) {
223
+					return true;
224
+		}
222 225
 
223 226
 		$newFlat = [];
224 227
 
225
-		foreach ( $this->flatArray as $value )
226
-			$newFlat[ $value[ $this->role[ self::ID_NAME ] ] ] = $value;
228
+		foreach ( $this->flatArray as $value ) {
229
+					$newFlat[ $value[ $this->role[ self::ID_NAME ] ] ] = $value;
230
+		}
227 231
 
228 232
 		$this->flatArray = $newFlat;
229 233
 
@@ -237,7 +241,9 @@  discard block
 block discarded – undo
237 241
 	 */
238 242
 	public static function isArrayAssoc( array $arr )
239 243
 	{
240
-		if ( array() === $arr ) return false;
244
+		if ( array() === $arr ) {
245
+			return false;
246
+		}
241 247
 
242 248
 		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
243 249
 	}
Please login to merge, or discard this patch.
src/Dependencies/QueryTimer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 	public function __construct()
25 25
 	{
26
-		$this->queryStart = microtime( true );
26
+		$this->queryStart = microtime(true);
27 27
 	}
28 28
 
29 29
 	/**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function getDuration()
33 33
 	{
34
-		$this->queryEnd = microtime( true );
34
+		$this->queryEnd = microtime(true);
35 35
 
36 36
 		return $this->queryEnd - $this->queryStart;
37 37
 	}
Please login to merge, or discard this patch.
src/DB/DbLog.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	private function __construct()
32 32
 	{
33
-		$this->dateTimeZone = new \DateTimeZone( 'Europe/Bucharest' );
33
+		$this->dateTimeZone = new \DateTimeZone('Europe/Bucharest');
34 34
 	}
35 35
 
36 36
 
@@ -38,61 +38,61 @@  discard block
 block discarded – undo
38 38
 	 * @param $query
39 39
 	 * @param $duration
40 40
 	 */
41
-	public function writeQueryDuration( $query, $duration )
41
+	public function writeQueryDuration($query, $duration)
42 42
 	{
43
-		$backtrace = end( debug_backtrace() );
43
+		$backtrace = end(debug_backtrace());
44 44
 		$location = $backtrace['file'] . " Line: " . $backtrace['line'];
45 45
 
46 46
 		$this->path = DbConfig::getInstance()->getLogPathQueryDuration(); //my comments
47
-		$message = "Duration: " . round( $duration, 5 ) . "\r\n";
47
+		$message = "Duration: " . round($duration, 5) . "\r\n";
48 48
 		$message .= "Location: $location\r\n";
49 49
 		$message .= "Query: $query";
50
-		$this->write( $message );
50
+		$this->write($message);
51 51
 	}
52 52
 
53 53
 	/**
54 54
 	 * @param $query
55 55
 	 * @param $duration
56 56
 	 */
57
-	public function writeQueryErros( $query, $code, $error )
57
+	public function writeQueryErros($query, $code, $error)
58 58
 	{
59
-		$backtrace = end( debug_backtrace() );
59
+		$backtrace = end(debug_backtrace());
60 60
 		$location = $backtrace['file'] . " Line: " . $backtrace['line'];
61 61
 
62 62
 		$this->path = DbConfig::getInstance()->getLogPathErrors(); //my comments
63 63
 		$message = "Query: $query" . "\r\n";
64 64
 		$message .= "Location: $location\r\n";
65 65
 		$message .= "Error code : " . $code . "\r\n";
66
-		$message .= "" . $error ;
66
+		$message .= "" . $error;
67 67
 
68
-		$this->write( $message );
68
+		$this->write($message);
69 69
 	}
70 70
 
71 71
 
72
-	public function write( $message )
72
+	public function write($message)
73 73
 	{
74 74
 
75 75
 		$date = new \DateTime();
76
-		$date->setTimezone( $this->dateTimeZone );
76
+		$date->setTimezone($this->dateTimeZone);
77 77
 
78
-		$log = $this->path . $date->format( 'Y-m-d' ) . ".txt";
79
-		$time = $date->format( 'H:i:s' );
78
+		$log = $this->path . $date->format('Y-m-d') . ".txt";
79
+		$time = $date->format('H:i:s');
80 80
 
81 81
 		$messageFormat = "[$time]\r\n$message\r\n\r\n";
82 82
 
83
-		if ( is_dir( $this->path ) ) {
84
-			if ( !file_exists( $log ) ) {
85
-				$fh = fopen( $log, 'a+' ) or die( "Fatal Error !" );
86
-				fwrite( $fh, $messageFormat );
87
-				fclose( $fh );
83
+		if (is_dir($this->path)) {
84
+			if (!file_exists($log)) {
85
+				$fh = fopen($log, 'a+') or die("Fatal Error !");
86
+				fwrite($fh, $messageFormat);
87
+				fclose($fh);
88 88
 			}
89 89
 			else {
90
-				$this->edit( $log, $date, $messageFormat );
90
+				$this->edit($log, $date, $messageFormat);
91 91
 			}
92 92
 		}
93 93
 		else {
94
-			if ( mkdir( $this->path, 0777 ) === true ) {
95
-				$this->write( $message );
94
+			if (mkdir($this->path, 0777) === true) {
95
+				$this->write($message);
96 96
 			}
97 97
 		}
98 98
 	}
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @param \DateTime $date
104 104
 	 * @param  string $message
105 105
 	 */
106
-	private function edit( $log, \DateTime $date, $message )
106
+	private function edit($log, \DateTime $date, $message)
107 107
 	{
108
-		file_put_contents( $log, $message, FILE_APPEND );
108
+		file_put_contents($log, $message, FILE_APPEND);
109 109
 	}
110 110
 
111 111
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public static function getInstance()
116 116
 	{
117
-		if ( null === static::$instance ) {
117
+		if (null === static::$instance) {
118 118
 			static::$instance = new static();
119 119
 		}
120 120
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,12 +85,10 @@
 block discarded – undo
85 85
 				$fh = fopen( $log, 'a+' ) or die( "Fatal Error !" );
86 86
 				fwrite( $fh, $messageFormat );
87 87
 				fclose( $fh );
88
-			}
89
-			else {
88
+			} else {
90 89
 				$this->edit( $log, $date, $messageFormat );
91 90
 			}
92
-		}
93
-		else {
91
+		} else {
94 92
 			if ( mkdir( $this->path, 0777 ) === true ) {
95 93
 				$this->write( $message );
96 94
 			}
Please login to merge, or discard this patch.
src/DB/DbService.php 2 patches
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -52,22 +52,22 @@  discard block
 block discarded – undo
52 52
 	 * @param int $fetchMode
53 53
 	 * @return array|int|null
54 54
 	 */
55
-	public function query( $query, $params = null, $fetchMode = \PDO::FETCH_ASSOC )
55
+	public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC)
56 56
 	{
57 57
 
58
-		$query = trim( str_replace( "\r", " ", $query ) );
59
-		$statement = self::getQueryStatement( $query );
58
+		$query = trim(str_replace("\r", " ", $query));
59
+		$statement = self::getQueryStatement($query);
60 60
 
61
-		$this->queryInit( $query, $params );
61
+		$this->queryInit($query, $params);
62 62
 
63
-		if ( $statement === self::QUERY_TYPE_SELECT ||
63
+		if ($statement === self::QUERY_TYPE_SELECT ||
64 64
 			$statement === self::QUERY_TYPE_SHOW ||
65 65
 			$statement === self::QUERY_TYPE_DESC ||
66 66
 			$statement === self::QUERY_TYPE_EXPLAIN
67 67
 		) {
68
-			return $this->sQuery->fetchAll( $fetchMode );
68
+			return $this->sQuery->fetchAll($fetchMode);
69 69
 		}
70
-		elseif ( $statement === self::QUERY_TYPE_INSERT ||
70
+		elseif ($statement === self::QUERY_TYPE_INSERT ||
71 71
 			$statement === self::QUERY_TYPE_UPDATE ||
72 72
 			$statement === self::QUERY_TYPE_DELETE
73 73
 		) {
@@ -84,46 +84,46 @@  discard block
 block discarded – undo
84 84
 	 * @param null $params
85 85
 	 * @return array|null
86 86
 	 */
87
-	public function column( $query, $params = null )
87
+	public function column($query, $params = null)
88 88
 	{
89
-		$this->queryInit( $query, $params );
89
+		$this->queryInit($query, $params);
90 90
 
91
-		$query = trim( str_replace( "\r", " ", $query ) );
92
-		$statement = self::getQueryStatement( $query );
91
+		$query = trim(str_replace("\r", " ", $query));
92
+		$statement = self::getQueryStatement($query);
93 93
 
94
-		if ( $statement === self::QUERY_TYPE_EXPLAIN )
95
-			return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
94
+		if ($statement === self::QUERY_TYPE_EXPLAIN)
95
+			return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
96 96
 
97
-		$Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM );
97
+		$Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
98 98
 
99 99
 		$column = null;
100 100
 
101
-		foreach ( $Columns as $cells ) {
101
+		foreach ($Columns as $cells) {
102 102
 			$column[] = $cells[0];
103 103
 		}
104 104
 
105 105
 		return $column;
106 106
 	}
107 107
 
108
-	public function row( $query, $params = null, $fetchmode = \PDO::FETCH_ASSOC )
108
+	public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC)
109 109
 	{
110
-		$this->queryInit( $query, $params );
110
+		$this->queryInit($query, $params);
111 111
 
112
-		$query = trim( str_replace( "\r", " ", $query ) );
113
-		$statement = self::getQueryStatement( $query );
112
+		$query = trim(str_replace("\r", " ", $query));
113
+		$statement = self::getQueryStatement($query);
114 114
 
115
-		if ( $statement === self::QUERY_TYPE_EXPLAIN )
116
-			return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
115
+		if ($statement === self::QUERY_TYPE_EXPLAIN)
116
+			return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
117 117
 
118
-		$result = $this->sQuery->fetch( $fetchmode );
118
+		$result = $this->sQuery->fetch($fetchmode);
119 119
 		$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
120 120
 
121 121
 		return $result;
122 122
 	}
123 123
 
124
-	public function single( $query, $params = null )
124
+	public function single($query, $params = null)
125 125
 	{
126
-		$this->queryInit( $query, $params );
126
+		$this->queryInit($query, $params);
127 127
 		$result = $this->sQuery->fetchColumn();
128 128
 		$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
129 129
 
@@ -135,57 +135,57 @@  discard block
 block discarded – undo
135 135
 	 * @param string $query
136 136
 	 * @param array $parameters
137 137
 	 */
138
-	private function queryInit( $query, $parameters = [] )
138
+	private function queryInit($query, $parameters = [])
139 139
 	{
140
-		$this->pdo = DbConnect::getInstance()->getConnection( self::getQueryStatement( $query ) );
141
-		$startQueryTime = microtime( true );
140
+		$this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query));
141
+		$startQueryTime = microtime(true);
142 142
 
143 143
 		try {
144 144
 
145 145
 			/**
146 146
 			 * Prepare query
147 147
 			 */
148
-			$this->sQuery = $this->pdo->prepare( $query );
148
+			$this->sQuery = $this->pdo->prepare($query);
149 149
 
150 150
 			/**
151 151
 			 * Add parameters to the parameter array
152 152
 			 */
153
-			if ( self::isArrayAssoc( $parameters ) )
154
-				$this->bindMore( $parameters );
153
+			if (self::isArrayAssoc($parameters))
154
+				$this->bindMore($parameters);
155 155
 			else
156
-				foreach ( $parameters as $key => $val )
157
-					$this->parameters[] = array( $key + 1, $val );
156
+				foreach ($parameters as $key => $val)
157
+					$this->parameters[] = array($key + 1, $val);
158 158
 
159
-			if ( count( $this->parameters ) ) {
160
-				foreach ( $this->parameters as $param => $value ) {
161
-					if ( is_int( $value[1] ) ) {
159
+			if (count($this->parameters)) {
160
+				foreach ($this->parameters as $param => $value) {
161
+					if (is_int($value[1])) {
162 162
 						$type = \PDO::PARAM_INT;
163 163
 					}
164
-					elseif ( is_bool( $value[1] ) ) {
164
+					elseif (is_bool($value[1])) {
165 165
 						$type = \PDO::PARAM_BOOL;
166 166
 					}
167
-					elseif ( is_null( $value[1] ) ) {
167
+					elseif (is_null($value[1])) {
168 168
 						$type = \PDO::PARAM_NULL;
169 169
 					}
170 170
 					else {
171 171
 						$type = \PDO::PARAM_STR;
172 172
 					}
173
-					$this->sQuery->bindValue( $value[0], $value[1], $type );
173
+					$this->sQuery->bindValue($value[0], $value[1], $type);
174 174
 				}
175 175
 			}
176 176
 
177 177
 			$this->sQuery->execute();
178 178
 
179
-			if ( DbConfig::getInstance()->isEnableLogQueryDuration() ) {
180
-				$duration = microtime( true ) - $startQueryTime;
181
-				DbLog::getInstance()->writeQueryDuration( $query, $duration );
179
+			if (DbConfig::getInstance()->isEnableLogQueryDuration()) {
180
+				$duration = microtime(true) - $startQueryTime;
181
+				DbLog::getInstance()->writeQueryDuration($query, $duration);
182 182
 			}
183 183
 
184
-		} catch ( \PDOException $e ) {
185
-			if ( DbConfig::getInstance()->isEnableLogErrors() ) {
186
-				DbLog::getInstance()->writeQueryErros( $query, $e->getCode(), $e->getMessage() );
184
+		} catch (\PDOException $e) {
185
+			if (DbConfig::getInstance()->isEnableLogErrors()) {
186
+				DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage());
187 187
 			}
188
-			throw new \PDOException( $e->getMessage(), $e->getCode() );
188
+			throw new \PDOException($e->getMessage(), $e->getCode());
189 189
 		}
190 190
 
191 191
 		/**
@@ -195,19 +195,19 @@  discard block
 block discarded – undo
195 195
 	}
196 196
 
197 197
 
198
-	public function bindMore( $parray )
198
+	public function bindMore($parray)
199 199
 	{
200
-		if ( !count( $this->parameters ) && is_array( $parray ) ) {
201
-			$columns = array_keys( $parray );
202
-			foreach ( $columns as $i => &$column ) {
203
-				$this->bind( $column, $parray[ $column ] );
200
+		if (!count($this->parameters) && is_array($parray)) {
201
+			$columns = array_keys($parray);
202
+			foreach ($columns as $i => &$column) {
203
+				$this->bind($column, $parray[$column]);
204 204
 			}
205 205
 		}
206 206
 	}
207 207
 
208
-	public function bind( $para, $value )
208
+	public function bind($para, $value)
209 209
 	{
210
-		$this->parameters[ sizeof( $this->parameters ) ] = [ ":" . $para, $value ];
210
+		$this->parameters[sizeof($this->parameters)] = [":" . $para, $value];
211 211
 	}
212 212
 
213 213
 
@@ -221,16 +221,16 @@  discard block
 block discarded – undo
221 221
 	 * @param $queryString
222 222
 	 * @return string
223 223
 	 */
224
-	public static function getQueryStatement( $queryString )
224
+	public static function getQueryStatement($queryString)
225 225
 	{
226
-		$queryString = trim( $queryString );
226
+		$queryString = trim($queryString);
227 227
 
228
-		if ( $queryString === '' ) {
228
+		if ($queryString === '') {
229 229
 			return self::QUERY_TYPE_EMPTY;
230 230
 		}
231 231
 
232
-		if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) {
233
-			switch ( strtolower( $matches[1] ) ) {
232
+		if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) {
233
+			switch (strtolower($matches[1])) {
234 234
 				case 'select':
235 235
 					return self::QUERY_TYPE_SELECT;
236 236
 					break;
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
 	 * @param array $arr
264 264
 	 * @return bool
265 265
 	 */
266
-	public static function isArrayAssoc( array $arr )
266
+	public static function isArrayAssoc(array $arr)
267 267
 	{
268
-		if ( array() === $arr ) return false;
268
+		if (array() === $arr) return false;
269 269
 
270
-		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
270
+		return array_keys($arr) !== range(0, count($arr) - 1);
271 271
 	}
272 272
 
273 273
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public static function getInstance()
278 278
 	{
279
-		if ( null === static::$instance ) {
279
+		if (null === static::$instance) {
280 280
 			static::$instance = new static();
281 281
 		}
282 282
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -66,14 +66,12 @@  discard block
 block discarded – undo
66 66
 			$statement === self::QUERY_TYPE_EXPLAIN
67 67
 		) {
68 68
 			return $this->sQuery->fetchAll( $fetchMode );
69
-		}
70
-		elseif ( $statement === self::QUERY_TYPE_INSERT ||
69
+		} elseif ( $statement === self::QUERY_TYPE_INSERT ||
71 70
 			$statement === self::QUERY_TYPE_UPDATE ||
72 71
 			$statement === self::QUERY_TYPE_DELETE
73 72
 		) {
74 73
 			return $this->sQuery->rowCount();
75
-		}
76
-		else {
74
+		} else {
77 75
 
78 76
 			return NULL;
79 77
 		}
@@ -91,8 +89,9 @@  discard block
 block discarded – undo
91 89
 		$query = trim( str_replace( "\r", " ", $query ) );
92 90
 		$statement = self::getQueryStatement( $query );
93 91
 
94
-		if ( $statement === self::QUERY_TYPE_EXPLAIN )
95
-			return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
92
+		if ( $statement === self::QUERY_TYPE_EXPLAIN ) {
93
+					return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
94
+		}
96 95
 
97 96
 		$Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM );
98 97
 
@@ -112,8 +111,9 @@  discard block
 block discarded – undo
112 111
 		$query = trim( str_replace( "\r", " ", $query ) );
113 112
 		$statement = self::getQueryStatement( $query );
114 113
 
115
-		if ( $statement === self::QUERY_TYPE_EXPLAIN )
116
-			return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
114
+		if ( $statement === self::QUERY_TYPE_EXPLAIN ) {
115
+					return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
116
+		}
117 117
 
118 118
 		$result = $this->sQuery->fetch( $fetchmode );
119 119
 		$this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
@@ -150,24 +150,22 @@  discard block
 block discarded – undo
150 150
 			/**
151 151
 			 * Add parameters to the parameter array
152 152
 			 */
153
-			if ( self::isArrayAssoc( $parameters ) )
154
-				$this->bindMore( $parameters );
155
-			else
156
-				foreach ( $parameters as $key => $val )
153
+			if ( self::isArrayAssoc( $parameters ) ) {
154
+							$this->bindMore( $parameters );
155
+			} else {
156
+							foreach ( $parameters as $key => $val )
157 157
 					$this->parameters[] = array( $key + 1, $val );
158
+			}
158 159
 
159 160
 			if ( count( $this->parameters ) ) {
160 161
 				foreach ( $this->parameters as $param => $value ) {
161 162
 					if ( is_int( $value[1] ) ) {
162 163
 						$type = \PDO::PARAM_INT;
163
-					}
164
-					elseif ( is_bool( $value[1] ) ) {
164
+					} elseif ( is_bool( $value[1] ) ) {
165 165
 						$type = \PDO::PARAM_BOOL;
166
-					}
167
-					elseif ( is_null( $value[1] ) ) {
166
+					} elseif ( is_null( $value[1] ) ) {
168 167
 						$type = \PDO::PARAM_NULL;
169
-					}
170
-					else {
168
+					} else {
171 169
 						$type = \PDO::PARAM_STR;
172 170
 					}
173 171
 					$this->sQuery->bindValue( $value[0], $value[1], $type );
@@ -253,8 +251,7 @@  discard block
 block discarded – undo
253 251
 					return self::QUERY_TYPE_OTHER;
254 252
 					break;
255 253
 			}
256
-		}
257
-		else {
254
+		} else {
258 255
 			return self::QUERY_TYPE_OTHER;
259 256
 		}
260 257
 	}
@@ -265,7 +262,9 @@  discard block
 block discarded – undo
265 262
 	 */
266 263
 	public static function isArrayAssoc( array $arr )
267 264
 	{
268
-		if ( array() === $arr ) return false;
265
+		if ( array() === $arr ) {
266
+			return false;
267
+		}
269 268
 
270 269
 		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
271 270
 	}
Please login to merge, or discard this patch.
src/DB/DbConnect.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function getMasterConnection()
44 44
 	{
45
-		if ( !is_a( $this->pdoMaster, \PDO::class ) )
46
-			$this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() );
45
+		if (!is_a($this->pdoMaster, \PDO::class))
46
+			$this->pdoMaster = $this->connect($this->config->getMasterDataConnect());
47 47
 
48 48
 		return $this->pdoMaster;
49 49
 	}
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function getSlaveConnection()
55 55
 	{
56
-		if ( !$this->config->getReplicationEnable() )
56
+		if (!$this->config->getReplicationEnable())
57 57
 			return $this->getMasterConnection();
58 58
 
59
-		if ( !is_a( $this->pdoSlave, \PDO::class ) )
60
-			$this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() );
59
+		if (!is_a($this->pdoSlave, \PDO::class))
60
+			$this->pdoSlave = $this->connect($this->config->getSlaveDataConnect());
61 61
 
62 62
 		return $this->pdoSlave;
63 63
 	}
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 * @param $statement
67 67
 	 * @return \PDO
68 68
 	 */
69
-	public function getConnection( $statement )
69
+	public function getConnection($statement)
70 70
 	{
71
-		$statement = trim( strtolower( $statement ) );
71
+		$statement = trim(strtolower($statement));
72 72
 
73
-		if ( $statement === DbService::QUERY_TYPE_SELECT )
73
+		if ($statement === DbService::QUERY_TYPE_SELECT)
74 74
 			return $this->getSlaveConnection();
75 75
 
76 76
 		return $this->getMasterConnection();
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 	 * @param $string
81 81
 	 * @return string
82 82
 	 */
83
-	public function quote( $string )
83
+	public function quote($string)
84 84
 	{
85
-		return $this->getMasterConnection()->quote( $string );
85
+		return $this->getMasterConnection()->quote($string);
86 86
 	}
87 87
 
88 88
 	/**
@@ -97,22 +97,22 @@  discard block
 block discarded – undo
97 97
 	 * @param $dataConnect
98 98
 	 * @return \PDO
99 99
 	 */
100
-	private function connect( $dataConnect )
100
+	private function connect($dataConnect)
101 101
 	{
102 102
 		$dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . '';
103 103
 		try {
104 104
 
105
-			$pdo = new \PDO( $dsn, $dataConnect["user"], $dataConnect["password"],
106
-				array( \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" )
105
+			$pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"],
106
+				array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
107 107
 			);
108 108
 
109
-			$pdo->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );
110
-			$pdo->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false );
111
-		} catch ( \PDOException $e ) {
112
-			if ( DbConfig::getInstance()->isEnableLogErrors() ) {
113
-				DbLog::getInstance()->writeQueryErros( 'Connection fail!', $e->getCode(), $e->getMessage() );
109
+			$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
110
+			$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
111
+		} catch (\PDOException $e) {
112
+			if (DbConfig::getInstance()->isEnableLogErrors()) {
113
+				DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage());
114 114
 			}
115
-			throw new \PDOException( $e->getMessage(), $e->getCode() );
115
+			throw new \PDOException($e->getMessage(), $e->getCode());
116 116
 		}
117 117
 
118 118
 		return $pdo;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public static function getInstance()
126 126
 	{
127
-		if ( null === static::$instance ) {
127
+		if (null === static::$instance) {
128 128
 			static::$instance = new static();
129 129
 		}
130 130
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,8 +42,9 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function getMasterConnection()
44 44
 	{
45
-		if ( !is_a( $this->pdoMaster, \PDO::class ) )
46
-			$this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() );
45
+		if ( !is_a( $this->pdoMaster, \PDO::class ) ) {
46
+					$this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() );
47
+		}
47 48
 
48 49
 		return $this->pdoMaster;
49 50
 	}
@@ -53,11 +54,13 @@  discard block
 block discarded – undo
53 54
 	 */
54 55
 	public function getSlaveConnection()
55 56
 	{
56
-		if ( !$this->config->getReplicationEnable() )
57
-			return $this->getMasterConnection();
57
+		if ( !$this->config->getReplicationEnable() ) {
58
+					return $this->getMasterConnection();
59
+		}
58 60
 
59
-		if ( !is_a( $this->pdoSlave, \PDO::class ) )
60
-			$this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() );
61
+		if ( !is_a( $this->pdoSlave, \PDO::class ) ) {
62
+					$this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() );
63
+		}
61 64
 
62 65
 		return $this->pdoSlave;
63 66
 	}
@@ -70,8 +73,9 @@  discard block
 block discarded – undo
70 73
 	{
71 74
 		$statement = trim( strtolower( $statement ) );
72 75
 
73
-		if ( $statement === DbService::QUERY_TYPE_SELECT )
74
-			return $this->getSlaveConnection();
76
+		if ( $statement === DbService::QUERY_TYPE_SELECT ) {
77
+					return $this->getSlaveConnection();
78
+		}
75 79
 
76 80
 		return $this->getMasterConnection();
77 81
 	}
Please login to merge, or discard this patch.
src/DB/DbConfig.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	private function __construct()
61 61
 	{
62 62
 		$vendorCfg = __DIR__ . '/../../../../../vendor-cfg/qpdb_db_config.php';
63
-		if(file_exists($vendorCfg))
63
+		if (file_exists($vendorCfg))
64 64
 			$this->dbConfig = require $vendorCfg;
65 65
 		else
66 66
 			$this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php';
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param string $fileConfig
73 73
 	 * @return $this
74 74
 	 */
75
-	public function withFileConfig( $fileConfig )
75
+	public function withFileConfig($fileConfig)
76 76
 	{
77 77
 		$this->dbConfig = require $fileConfig;
78 78
 		$this->buildConfig();
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
 	public function useTablePrefix()
148 148
 	{
149
-		if ( !empty( $this->dbConfig['use_table_prefix'] ) )
149
+		if (!empty($this->dbConfig['use_table_prefix']))
150 150
 			return $this->dbConfig['use_table_prefix'];
151 151
 
152 152
 		return false;
@@ -182,18 +182,18 @@  discard block
 block discarded – undo
182 182
 	private function readMasterDataConnect()
183 183
 	{
184 184
 
185
-		if ( !isset( $this->dbConfig['master_data_connect'][0] ) )
186
-			throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING );
185
+		if (!isset($this->dbConfig['master_data_connect'][0]))
186
+			throw new DbException('Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING);
187 187
 
188 188
 		$dataConnection = $this->dbConfig['master_data_connect'];
189 189
 
190
-		if ( !$this->replicationEnable || count( $dataConnection ) == 1 ) {
190
+		if (!$this->replicationEnable || count($dataConnection) == 1) {
191 191
 			$this->masterDataConnect = $dataConnection[0];
192 192
 
193 193
 			return true;
194 194
 		}
195 195
 
196
-		shuffle( $dataConnection );
196
+		shuffle($dataConnection);
197 197
 		$this->masterDataConnect = $dataConnection[0];
198 198
 
199 199
 		return true;
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	private function readSlaveDataConnect()
207 207
 	{
208 208
 
209
-		if ( !isset( $this->dbConfig['slave_data_connect'][0] ) ) {
209
+		if (!isset($this->dbConfig['slave_data_connect'][0])) {
210 210
 			$this->slaveDataConnect = $this->masterDataConnect;
211 211
 
212 212
 			return true;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
 		$dataConnection = $this->dbConfig['slave_data_connect'];
216 216
 
217
-		shuffle( $dataConnection );
217
+		shuffle($dataConnection);
218 218
 		$this->slaveDataConnect = $dataConnection[0];
219 219
 
220 220
 		return true;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public static function getInstance()
227 227
 	{
228
-		if ( null === static::$instance ) {
228
+		if (null === static::$instance) {
229 229
 			static::$instance = new static();
230 230
 		}
231 231
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -60,10 +60,11 @@  discard block
 block discarded – undo
60 60
 	private function __construct()
61 61
 	{
62 62
 		$vendorCfg = __DIR__ . '/../../../../../vendor-cfg/qpdb_db_config.php';
63
-		if(file_exists($vendorCfg))
64
-			$this->dbConfig = require $vendorCfg;
65
-		else
66
-			$this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php';
63
+		if(file_exists($vendorCfg)) {
64
+					$this->dbConfig = require $vendorCfg;
65
+		} else {
66
+					$this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php';
67
+		}
67 68
 
68 69
 		$this->buildConfig();
69 70
 	}
@@ -146,8 +147,9 @@  discard block
 block discarded – undo
146 147
 
147 148
 	public function useTablePrefix()
148 149
 	{
149
-		if ( !empty( $this->dbConfig['use_table_prefix'] ) )
150
-			return $this->dbConfig['use_table_prefix'];
150
+		if ( !empty( $this->dbConfig['use_table_prefix'] ) ) {
151
+					return $this->dbConfig['use_table_prefix'];
152
+		}
151 153
 
152 154
 		return false;
153 155
 	}
@@ -182,8 +184,9 @@  discard block
 block discarded – undo
182 184
 	private function readMasterDataConnect()
183 185
 	{
184 186
 
185
-		if ( !isset( $this->dbConfig['master_data_connect'][0] ) )
186
-			throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING );
187
+		if ( !isset( $this->dbConfig['master_data_connect'][0] ) ) {
188
+					throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING );
189
+		}
187 190
 
188 191
 		$dataConnection = $this->dbConfig['master_data_connect'];
189 192
 
Please login to merge, or discard this patch.