Passed
Push — master ( d44413...7ff405 )
by Adrian
04:24
created
src/Statements/QueryStatement.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     /**
50 50
      * @var array
51 51
      */
52
-    protected $usedInstanceIds = [];
52
+    protected $usedInstanceIds = [ ];
53 53
 
54 54
     /**
55 55
      * @var string
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
      * @param string|QuerySelect $table
64 64
      * @throws QueryException
65 65
      */
66
-    public function __construct(QueryBuild $queryBuild, $table = '')
66
+    public function __construct( QueryBuild $queryBuild, $table = '' )
67 67
     {
68 68
 
69
-        $table = $this->validateTable($table);
69
+        $table = $this->validateTable( $table );
70 70
 
71 71
         $this->queryBuild = $queryBuild;
72 72
         $this->queryStructure = new QueryStructure();
73
-        $this->queryStructure->setElement(QueryStructure::TABLE, $table);
74
-        $this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
75
-        $this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
73
+        $this->queryStructure->setElement( QueryStructure::TABLE, $table );
74
+        $this->queryStructure->setElement( QueryStructure::STATEMENT, $this->statement );
75
+        $this->queryStructure->setElement( QueryStructure::QUERY_TYPE, $this->queryBuild->getType() );
76 76
 
77 77
     }
78 78
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function getBindParams()
83 83
     {
84
-        return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
84
+        return $this->queryStructure->getElement( QueryStructure::BIND_PARAMS );
85 85
     }
86 86
 
87 87
 
Please login to merge, or discard this patch.
src/Statements/QueryStatementInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
      * @param bool $replacement
19 19
      * @return string
20 20
      */
21
-    public function getSyntax($replacement = self::REPLACEMENT_NONE);
21
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE );
22 22
 
23 23
     public function execute();
24 24
 
Please login to merge, or discard this patch.
src/Statements/QueryDelete.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -40,53 +40,53 @@  discard block
 block discarded – undo
40 40
      * @param QueryBuild $queryBuild
41 41
      * @param string $table
42 42
      */
43
-    public function __construct(QueryBuild $queryBuild, $table = null)
43
+    public function __construct( QueryBuild $queryBuild, $table = null )
44 44
     {
45
-        parent::__construct($queryBuild, $table);
45
+        parent::__construct( $queryBuild, $table );
46 46
     }
47 47
 
48
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
48
+    public function getSyntax( $replacement = self::REPLACEMENT_NONE )
49 49
     {
50 50
         $syntax = array();
51 51
 
52 52
         /**
53 53
          *  Explain
54 54
          */
55
-        $syntax[] = $this->getExplainSyntax();
55
+        $syntax[ ] = $this->getExplainSyntax();
56 56
 
57 57
         /**
58 58
          * UPDATE statement
59 59
          */
60
-        $syntax[] = $this->statement;
60
+        $syntax[ ] = $this->statement;
61 61
 
62 62
         /**
63 63
          * PRIORITY
64 64
          */
65
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
65
+        $syntax[ ] = $this->queryStructure->getElement( QueryStructure::PRIORITY );
66 66
 
67 67
         /**
68 68
          * TABLE update
69 69
          */
70
-        $syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
70
+        $syntax[ ] = 'FROM ' . $this->queryStructure->getElement( QueryStructure::TABLE );
71 71
 
72 72
         /**
73 73
          * WHERE clause
74 74
          */
75
-        $syntax[] = $this->getWhereSyntax();
75
+        $syntax[ ] = $this->getWhereSyntax();
76 76
 
77 77
         /**
78 78
          * ORDER BY clause
79 79
          */
80
-        $syntax[] = $this->getOrderBySyntax();
80
+        $syntax[ ] = $this->getOrderBySyntax();
81 81
 
82 82
         /**
83 83
          * LIMIT clause
84 84
          */
85
-        $syntax[] = $this->getLimitSyntax();
85
+        $syntax[ ] = $this->getLimitSyntax();
86 86
 
87
-        $syntax = implode(' ', $syntax);
87
+        $syntax = implode( ' ', $syntax );
88 88
 
89
-        return $this->getSyntaxReplace($syntax, $replacement);
89
+        return $this->getSyntaxReplace( $syntax, $replacement );
90 90
     }
91 91
 
92 92
     /**
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
     public function execute()
97 97
     {
98 98
 
99
-        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
100
-            throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
99
+        if ( $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) )
100
+            throw new QueryException( 'Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER );
101 101
 
102
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
102
+        return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) );
103 103
 
104 104
     }
105 105
 
Please login to merge, or discard this patch.
src/DB/DbLog.php 1 patch
Spacing   +25 added lines, -25 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,26 +38,26 @@  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());
44
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
43
+        $backtrace = end( debug_backtrace() );
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());
60
-        $location = $backtrace['file'] . " Line: " . $backtrace['line'];
59
+        $backtrace = end( debug_backtrace() );
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";
@@ -65,32 +65,32 @@  discard block
 block discarded – undo
65 65
         $message .= "Error code : " . $code . "\r\n";
66 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+');
86
-                fwrite($fh, $messageFormat);
87
-                fclose($fh);
83
+        if ( is_dir( $this->path ) ) {
84
+            if ( !file_exists( $log ) ) {
85
+                $fh = fopen( $log, 'a+' );
86
+                fwrite( $fh, $messageFormat );
87
+                fclose( $fh );
88 88
             } else {
89
-                $this->edit($log, $messageFormat);
89
+                $this->edit( $log, $messageFormat );
90 90
             }
91 91
         } else {
92
-            if (mkdir($this->path, 0777) === true) {
93
-                $this->write($message);
92
+            if ( mkdir( $this->path, 0777 ) === true ) {
93
+                $this->write( $message );
94 94
             }
95 95
         }
96 96
     }
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
      * @param string $log
101 101
      * @param  string $message
102 102
      */
103
-    private function edit($log, $message)
103
+    private function edit( $log, $message )
104 104
     {
105
-        file_put_contents($log, $message, FILE_APPEND);
105
+        file_put_contents( $log, $message, FILE_APPEND );
106 106
     }
107 107
 
108 108
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public static function getInstance()
113 113
     {
114
-        if (null === self::$instance) {
114
+        if ( null === self::$instance ) {
115 115
             self::$instance = new self();
116 116
         }
117 117
 
Please login to merge, or discard this patch.
src/DB/DbService.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
     /**
44 44
      * @var array
45 45
      */
46
-    private $parameters = [];
46
+    private $parameters = [ ];
47 47
 
48 48
     /**
49 49
      * @return DbService
50 50
      */
51 51
     public static function getInstance()
52 52
     {
53
-        if (null === self::$instance) {
53
+        if ( null === self::$instance ) {
54 54
             self::$instance = new self();
55 55
         }
56 56
 
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
      * @param int $fetchMode
64 64
      * @return array|int|null
65 65
      */
66
-    public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC)
66
+    public function query( $query, $params = null, $fetchMode = \PDO::FETCH_ASSOC )
67 67
     {
68 68
 
69
-        $query = trim(str_replace("\r", " ", $query));
70
-        $statement = self::getQueryStatement($query);
69
+        $query = trim( str_replace( "\r", " ", $query ) );
70
+        $statement = self::getQueryStatement( $query );
71 71
 
72
-        $this->queryInit($query, $params);
72
+        $this->queryInit( $query, $params );
73 73
 
74
-        if ($statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN) {
75
-            return $this->sQuery->fetchAll($fetchMode);
76
-        } elseif ($statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE) {
74
+        if ( $statement === self::QUERY_TYPE_SELECT || $statement === self::QUERY_TYPE_SHOW || $statement === self::QUERY_TYPE_DESC || $statement === self::QUERY_TYPE_EXPLAIN ) {
75
+            return $this->sQuery->fetchAll( $fetchMode );
76
+        } elseif ( $statement === self::QUERY_TYPE_INSERT || $statement === self::QUERY_TYPE_UPDATE || $statement === self::QUERY_TYPE_DELETE ) {
77 77
             return $this->sQuery->rowCount();
78 78
         } else {
79 79
 
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
      * @param $queryString
86 86
      * @return string
87 87
      */
88
-    public static function getQueryStatement($queryString)
88
+    public static function getQueryStatement( $queryString )
89 89
     {
90
-        $queryString = trim($queryString);
90
+        $queryString = trim( $queryString );
91 91
 
92
-        if ($queryString === '') {
92
+        if ( $queryString === '' ) {
93 93
             return self::QUERY_TYPE_EMPTY;
94 94
         }
95 95
 
96
-        if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) {
97
-            switch (strtolower($matches[1])) {
96
+        if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) {
97
+            switch ( strtolower( $matches[ 1 ] ) ) {
98 98
                 case 'select':
99 99
                     return self::QUERY_TYPE_SELECT;
100 100
                 case 'insert':
@@ -120,53 +120,53 @@  discard block
 block discarded – undo
120 120
      * @param array $parameters
121 121
      * @throws DbException
122 122
      */
123
-    private function queryInit($query, $parameters = [])
123
+    private function queryInit( $query, $parameters = [ ] )
124 124
     {
125
-        $this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query));
126
-        $startQueryTime = microtime(true);
125
+        $this->pdo = DbConnect::getInstance()->getConnection( self::getQueryStatement( $query ) );
126
+        $startQueryTime = microtime( true );
127 127
 
128 128
         try {
129 129
 
130 130
             /**
131 131
              * Prepare query
132 132
              */
133
-            $this->sQuery = $this->pdo->prepare($query);
133
+            $this->sQuery = $this->pdo->prepare( $query );
134 134
 
135 135
             /**
136 136
              * Add parameters to the parameter array
137 137
              */
138
-            if (self::isArrayAssoc($parameters))
139
-                $this->bindMore($parameters); else
140
-                foreach ($parameters as $key => $val)
141
-                    $this->parameters[] = array($key + 1, $val);
142
-
143
-            if (count($this->parameters)) {
144
-                foreach ($this->parameters as $param => $value) {
145
-                    if (is_int($value[1])) {
138
+            if ( self::isArrayAssoc( $parameters ) )
139
+                $this->bindMore( $parameters ); else
140
+                foreach ( $parameters as $key => $val )
141
+                    $this->parameters[ ] = array( $key + 1, $val );
142
+
143
+            if ( count( $this->parameters ) ) {
144
+                foreach ( $this->parameters as $param => $value ) {
145
+                    if ( is_int( $value[ 1 ] ) ) {
146 146
                         $type = \PDO::PARAM_INT;
147
-                    } elseif (is_bool($value[1])) {
147
+                    } elseif ( is_bool( $value[ 1 ] ) ) {
148 148
                         $type = \PDO::PARAM_BOOL;
149
-                    } elseif (is_null($value[1])) {
149
+                    } elseif ( is_null( $value[ 1 ] ) ) {
150 150
                         $type = \PDO::PARAM_NULL;
151 151
                     } else {
152 152
                         $type = \PDO::PARAM_STR;
153 153
                     }
154
-                    $this->sQuery->bindValue($value[0], $value[1], $type);
154
+                    $this->sQuery->bindValue( $value[ 0 ], $value[ 1 ], $type );
155 155
                 }
156 156
             }
157 157
 
158 158
             $this->sQuery->execute();
159 159
 
160
-            if (DbConfig::getInstance()->isEnableLogQueryDuration()) {
161
-                $duration = microtime(true) - $startQueryTime;
162
-                DbLog::getInstance()->writeQueryDuration($query, $duration);
160
+            if ( DbConfig::getInstance()->isEnableLogQueryDuration() ) {
161
+                $duration = microtime( true ) - $startQueryTime;
162
+                DbLog::getInstance()->writeQueryDuration( $query, $duration );
163 163
             }
164 164
 
165
-        } catch (\PDOException $e) {
166
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
167
-                DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage());
165
+        } catch ( \PDOException $e ) {
166
+            if ( DbConfig::getInstance()->isEnableLogErrors() ) {
167
+                DbLog::getInstance()->writeQueryErros( $query, $e->getCode(), $e->getMessage() );
168 168
             }
169
-            throw new DbException('Database error!', DbException::DB_QUERY_ERROR);
169
+            throw new DbException( 'Database error!', DbException::DB_QUERY_ERROR );
170 170
         }
171 171
 
172 172
         /**
@@ -179,27 +179,27 @@  discard block
 block discarded – undo
179 179
      * @param array $arr
180 180
      * @return bool
181 181
      */
182
-    public static function isArrayAssoc(array $arr)
182
+    public static function isArrayAssoc( array $arr )
183 183
     {
184
-        if (array() === $arr)
184
+        if ( array() === $arr )
185 185
             return false;
186 186
 
187
-        return array_keys($arr) !== range(0, count($arr) - 1);
187
+        return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
188 188
     }
189 189
 
190
-    public function bindMore($parray)
190
+    public function bindMore( $parray )
191 191
     {
192
-        if (!count($this->parameters) && is_array($parray)) {
193
-            $columns = array_keys($parray);
194
-            foreach ($columns as $i => &$column) {
195
-                $this->bind($column, $parray[ $column ]);
192
+        if ( !count( $this->parameters ) && is_array( $parray ) ) {
193
+            $columns = array_keys( $parray );
194
+            foreach ( $columns as $i => &$column ) {
195
+                $this->bind( $column, $parray[ $column ] );
196 196
             }
197 197
         }
198 198
     }
199 199
 
200
-    public function bind($para, $value)
200
+    public function bind( $para, $value )
201 201
     {
202
-        $this->parameters[ sizeof($this->parameters) ] = [":" . $para, $value];
202
+        $this->parameters[ sizeof( $this->parameters ) ] = [ ":" . $para, $value ];
203 203
     }
204 204
 
205 205
     /**
@@ -207,46 +207,46 @@  discard block
 block discarded – undo
207 207
      * @param array $params
208 208
      * @return array|null
209 209
      */
210
-    public function column($query, $params = null)
210
+    public function column( $query, $params = null )
211 211
     {
212
-        $this->queryInit($query, $params);
212
+        $this->queryInit( $query, $params );
213 213
 
214
-        $query = trim(str_replace("\r", " ", $query));
215
-        $statement = self::getQueryStatement($query);
214
+        $query = trim( str_replace( "\r", " ", $query ) );
215
+        $statement = self::getQueryStatement( $query );
216 216
 
217
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
218
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
217
+        if ( $statement === self::QUERY_TYPE_EXPLAIN )
218
+            return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
219 219
 
220
-        $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM);
220
+        $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM );
221 221
 
222 222
         $column = null;
223 223
 
224
-        foreach ($Columns as $cells) {
225
-            $column[] = $cells[0];
224
+        foreach ( $Columns as $cells ) {
225
+            $column[ ] = $cells[ 0 ];
226 226
         }
227 227
 
228 228
         return $column;
229 229
     }
230 230
 
231
-    public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC)
231
+    public function row( $query, $params = null, $fetchmode = \PDO::FETCH_ASSOC )
232 232
     {
233
-        $this->queryInit($query, $params);
233
+        $this->queryInit( $query, $params );
234 234
 
235
-        $query = trim(str_replace("\r", " ", $query));
236
-        $statement = self::getQueryStatement($query);
235
+        $query = trim( str_replace( "\r", " ", $query ) );
236
+        $statement = self::getQueryStatement( $query );
237 237
 
238
-        if ($statement === self::QUERY_TYPE_EXPLAIN)
239
-            return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC);
238
+        if ( $statement === self::QUERY_TYPE_EXPLAIN )
239
+            return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC );
240 240
 
241
-        $result = $this->sQuery->fetch($fetchmode);
241
+        $result = $this->sQuery->fetch( $fetchmode );
242 242
         $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued,
243 243
 
244 244
         return $result;
245 245
     }
246 246
 
247
-    public function single($query, $params = null)
247
+    public function single( $query, $params = null )
248 248
     {
249
-        $this->queryInit($query, $params);
249
+        $this->queryInit( $query, $params );
250 250
         $result = $this->sQuery->fetchColumn();
251 251
         $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued
252 252
 
Please login to merge, or discard this patch.
src/DB/DbConnect.php 1 patch
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,20 +97,20 @@  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
-        $dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . '';
102
+        $dsn = 'mysql:dbname=' . $dataConnect[ "dbname" ] . ';host=' . $dataConnect[ "host" ] . '';
103 103
         try {
104 104
 
105
-            $pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
105
+            $pdo = new \PDO( $dsn, $dataConnect[ "user" ], $dataConnect[ "password" ], array( \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) );
106 106
 
107
-            $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
108
-            $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
109
-        } catch (\PDOException $e) {
110
-            if (DbConfig::getInstance()->isEnableLogErrors()) {
111
-                DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage());
107
+            $pdo->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );
108
+            $pdo->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false );
109
+        } catch ( \PDOException $e ) {
110
+            if ( DbConfig::getInstance()->isEnableLogErrors() ) {
111
+                DbLog::getInstance()->writeQueryErros( 'Connection fail!', $e->getCode(), $e->getMessage() );
112 112
             }
113
-            throw new DbException('Database connection error!', DbException::DB_CONNECTION_ERROR);
113
+            throw new DbException( 'Database connection error!', DbException::DB_CONNECTION_ERROR );
114 114
         }
115 115
 
116 116
         return $pdo;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public static function getInstance()
124 124
     {
125
-        if (null === self::$instance) {
125
+        if ( null === self::$instance ) {
126 126
             self::$instance = new self();
127 127
         }
128 128
 
Please login to merge, or discard this patch.
src/DB/DbConfig.php 1 patch
Spacing   +23 added lines, -23 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; else
65 65
             $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php';
66 66
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * @param string $fileConfig
72 72
      * @return $this
73 73
      */
74
-    public function withFileConfig($fileConfig)
74
+    public function withFileConfig( $fileConfig )
75 75
     {
76 76
         $this->dbConfig = require $fileConfig;
77 77
         $this->buildConfig();
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function getLogConfig()
110 110
     {
111
-        return $this->dbConfig['db_log'];
111
+        return $this->dbConfig[ 'db_log' ];
112 112
     }
113 113
 
114 114
     /**
@@ -145,21 +145,21 @@  discard block
 block discarded – undo
145 145
 
146 146
     public function useTablePrefix()
147 147
     {
148
-        if (!empty($this->dbConfig['use_table_prefix']))
149
-            return $this->dbConfig['use_table_prefix'];
148
+        if ( !empty( $this->dbConfig[ 'use_table_prefix' ] ) )
149
+            return $this->dbConfig[ 'use_table_prefix' ];
150 150
 
151 151
         return false;
152 152
     }
153 153
 
154 154
     public function getTablePrefix()
155 155
     {
156
-        return $this->dbConfig['table_prefix'];
156
+        return $this->dbConfig[ 'table_prefix' ];
157 157
     }
158 158
 
159 159
 
160 160
     private function buildConfig()
161 161
     {
162
-        $this->replicationEnable = $this->dbConfig['replicationEnable'];
162
+        $this->replicationEnable = $this->dbConfig[ 'replicationEnable' ];
163 163
         $this->readMasterDataConnect();
164 164
         $this->readSlaveDataConnect();
165 165
         $this->configLogger();
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
 
168 168
     private function configLogger()
169 169
     {
170
-        $this->enableLogErrors = $this->dbConfig['db_log']['enable_log_errors'];
171
-        $this->enableLogQueryDuration = $this->dbConfig['db_log']['enable_log_query_duration'];
172
-        $this->logPathErrors = $this->dbConfig['db_log']['log_path_errors'];
173
-        $this->logPathQueryDuration = $this->dbConfig['db_log']['log_path_query_duration'];
170
+        $this->enableLogErrors = $this->dbConfig[ 'db_log' ][ 'enable_log_errors' ];
171
+        $this->enableLogQueryDuration = $this->dbConfig[ 'db_log' ][ 'enable_log_query_duration' ];
172
+        $this->logPathErrors = $this->dbConfig[ 'db_log' ][ 'log_path_errors' ];
173
+        $this->logPathQueryDuration = $this->dbConfig[ 'db_log' ][ 'log_path_query_duration' ];
174 174
 
175 175
     }
176 176
 
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
     private function readMasterDataConnect()
182 182
     {
183 183
 
184
-        if (!isset($this->dbConfig['master_data_connect'][0]))
185
-            throw new DbException('Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING);
184
+        if ( !isset( $this->dbConfig[ 'master_data_connect' ][ 0 ] ) )
185
+            throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING );
186 186
 
187
-        $dataConnection = $this->dbConfig['master_data_connect'];
187
+        $dataConnection = $this->dbConfig[ 'master_data_connect' ];
188 188
 
189
-        if (!$this->replicationEnable || count($dataConnection) == 1) {
190
-            $this->masterDataConnect = $dataConnection[0];
189
+        if ( !$this->replicationEnable || count( $dataConnection ) == 1 ) {
190
+            $this->masterDataConnect = $dataConnection[ 0 ];
191 191
 
192 192
             return true;
193 193
         }
194 194
 
195
-        shuffle($dataConnection);
196
-        $this->masterDataConnect = $dataConnection[0];
195
+        shuffle( $dataConnection );
196
+        $this->masterDataConnect = $dataConnection[ 0 ];
197 197
 
198 198
         return true;
199 199
     }
@@ -205,16 +205,16 @@  discard block
 block discarded – undo
205 205
     private function readSlaveDataConnect()
206 206
     {
207 207
 
208
-        if (!isset($this->dbConfig['slave_data_connect'][0])) {
208
+        if ( !isset( $this->dbConfig[ 'slave_data_connect' ][ 0 ] ) ) {
209 209
             $this->slaveDataConnect = $this->masterDataConnect;
210 210
 
211 211
             return true;
212 212
         }
213 213
 
214
-        $dataConnection = $this->dbConfig['slave_data_connect'];
214
+        $dataConnection = $this->dbConfig[ 'slave_data_connect' ];
215 215
 
216
-        shuffle($dataConnection);
217
-        $this->slaveDataConnect = $dataConnection[0];
216
+        shuffle( $dataConnection );
217
+        $this->slaveDataConnect = $dataConnection[ 0 ];
218 218
 
219 219
         return true;
220 220
     }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     public static function getInstance()
226 226
     {
227
-        if (null === self::$instance) {
227
+        if ( null === self::$instance ) {
228 228
             self::$instance = new self();
229 229
         }
230 230
 
Please login to merge, or discard this patch.
config/qpdb_db_config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 
10 10
     'replicationEnable' => false,
11 11
 
12
-    'slave_statements' => ['SELECT'],
12
+    'slave_statements' => [ 'SELECT' ],
13 13
 
14 14
     /**
15 15
      * if not Replication support use only first entry in master_data_connect
16 16
      */
17
-    'master_data_connect' => [['host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels']],
17
+    'master_data_connect' => [ [ 'host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels' ] ],
18 18
 
19 19
     /**
20 20
      * Use if replicationEnable is true. Config one or multiple slave connection
21 21
      */
22
-    'slave_data_connect' => [['host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels'], ['host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels']],
22
+    'slave_data_connect' => [ [ 'host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels' ], [ 'host' => 'localhost', 'user' => 'guser', 'password' => '1234', 'dbname' => 'classicmodels' ] ],
23 23
 
24
-    'db_log' => ['enable_log_errors' => false, 'enable_log_query_duration' => false, 'log_path_errors' => $_SERVER['DOCUMENT_ROOT'] . '/tmp/db_errors/', 'log_path_query_duration' => $_SERVER['DOCUMENT_ROOT'] . '/tmp/db_query_duration/',],
24
+    'db_log' => [ 'enable_log_errors' => false, 'enable_log_query_duration' => false, 'log_path_errors' => $_SERVER[ 'DOCUMENT_ROOT' ] . '/tmp/db_errors/', 'log_path_query_duration' => $_SERVER[ 'DOCUMENT_ROOT' ] . '/tmp/db_query_duration/', ],
25 25
 
26 26
     'use_table_prefix' => false, 'table_prefix' => 'prefix_',
27 27
 
Please login to merge, or discard this patch.