We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | trait SmrMySqlSecrets { |
| 3 | 3 | protected static $databaseName = 'smr_live'; |
| 4 | 4 | private static $host = 'smr-mysql'; // must match MYSQL_HOST in .env |
| 5 | - private static $user = 'smr'; // must match MYSQL_USER in .env |
|
| 6 | - private static $password = 'smr'; // must match MYSQL_PASSWORD in .env |
|
| 5 | + private static $user = 'smr'; // must match MYSQL_USER in .env |
|
| 6 | + private static $password = 'smr'; // must match MYSQL_PASSWORD in .env |
|
| 7 | 7 | |
| 8 | 8 | // Set to null to use defaults |
| 9 | 9 | private static $port = null; |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct($dbName) { |
| 14 | 14 | if(!self::$dbConn) { |
| 15 | 15 | self::$dbConn = new mysqli(self::$host, self::$user, self::$password, |
| 16 | - $dbName, self::$port, self::$socket); |
|
| 16 | + $dbName, self::$port, self::$socket); |
|
| 17 | 17 | if (self::$dbConn->connect_errno) { |
| 18 | 18 | $this->error('Connection failed: ' . self::$dbConn->connect_error); |
| 19 | 19 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | protected $dbRecord = null; |
| 12 | 12 | |
| 13 | 13 | public function __construct($dbName) { |
| 14 | - if(!self::$dbConn) { |
|
| 14 | + if (!self::$dbConn) { |
|
| 15 | 15 | self::$dbConn = new mysqli(self::$host, self::$user, self::$password, |
| 16 | 16 | $dbName, self::$port, self::$socket); |
| 17 | 17 | if (self::$dbConn->connect_errno) { |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function query($query) { |
| 41 | - if(!$this->dbResult = self::$dbConn->query($query)) { |
|
| 41 | + if (!$this->dbResult = self::$dbConn->query($query)) { |
|
| 42 | 42 | $this->error('SQL query failed (' . $query . ')'); |
| 43 | 43 | // the SQL error message will be reported by logException |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function nextRecord() { |
| 48 | - if(!$this->dbResult) |
|
| 48 | + if (!$this->dbResult) |
|
| 49 | 49 | $this->error('No resource to get record from.'); |
| 50 | 50 | |
| 51 | - if($this->dbRecord = $this->dbResult->fetch_assoc()) { |
|
| 51 | + if ($this->dbRecord = $this->dbResult->fetch_assoc()) { |
|
| 52 | 52 | return true; |
| 53 | 53 | } |
| 54 | 54 | return false; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function getBoolean($name) { |
| 64 | - if($this->dbRecord[$name] == 'TRUE') |
|
| 64 | + if ($this->dbRecord[$name] == 'TRUE') |
|
| 65 | 65 | return true; |
| 66 | 66 | // if($this->dbRecord[$name] == 'FALSE') |
| 67 | 67 | return false; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | // For backwards compatibility, set $pad_msec=true to try to guess at the |
| 81 | 81 | // intended value. This is not safe if the Microtime length is wrong for an |
| 82 | 82 | // unrelated reason! |
| 83 | - public function getMicrotime($name, $pad_msec=false) { |
|
| 83 | + public function getMicrotime($name, $pad_msec = false) { |
|
| 84 | 84 | $data = $this->dbRecord[$name]; |
| 85 | 85 | $sec = substr($data, 0, 10); |
| 86 | 86 | $msec = substr($data, 10); |
@@ -88,15 +88,15 @@ discard block |
||
| 88 | 88 | if ($pad_msec) { |
| 89 | 89 | $msec = str_pad($msec, 6, '0', STR_PAD_LEFT); |
| 90 | 90 | } else { |
| 91 | - throw new Exception('Field is not an escaped microtime ('.$data.')'); |
|
| 91 | + throw new Exception('Field is not an escaped microtime (' . $data . ')'); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | return "$sec.$msec"; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function getObject($name,$compressed=false) { |
|
| 97 | + public function getObject($name, $compressed = false) { |
|
| 98 | 98 | $object = $this->getField($name); |
| 99 | - if($compressed===true) |
|
| 99 | + if ($compressed === true) |
|
| 100 | 100 | $object = gzuncompress($object); |
| 101 | 101 | return unserialize($object); |
| 102 | 102 | } |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | public function lockTable($table) { |
| 109 | - if(!self::$dbConn->query('LOCK TABLES ' . $table . ' WRITE')) { |
|
| 110 | - $this->error('Unable to lock table: '. $table); |
|
| 109 | + if (!self::$dbConn->query('LOCK TABLES ' . $table . ' WRITE')) { |
|
| 110 | + $this->error('Unable to lock table: ' . $table); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public function unlock() { |
| 115 | - if(!self::$dbConn->query('UNLOCK TABLES')) { |
|
| 115 | + if (!self::$dbConn->query('UNLOCK TABLES')) { |
|
| 116 | 116 | $this->error('Unable to remove table locks.'); |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -137,70 +137,70 @@ discard block |
||
| 137 | 137 | throw new Exception($err); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function escape($escape,$autoQuotes=true,$quotes=true) { |
|
| 141 | - if(is_bool($escape)) { |
|
| 142 | - if($autoQuotes) |
|
| 140 | + public function escape($escape, $autoQuotes = true, $quotes = true) { |
|
| 141 | + if (is_bool($escape)) { |
|
| 142 | + if ($autoQuotes) |
|
| 143 | 143 | return $this->escapeBoolean($escape); |
| 144 | 144 | else |
| 145 | - return $this->escapeBoolean($escape,$quotes); |
|
| 145 | + return $this->escapeBoolean($escape, $quotes); |
|
| 146 | 146 | } |
| 147 | - if(is_numeric($escape)) { |
|
| 147 | + if (is_numeric($escape)) { |
|
| 148 | 148 | return $this->escapeNumber($escape); |
| 149 | 149 | } |
| 150 | - if(is_string($escape)) { |
|
| 151 | - if($autoQuotes) |
|
| 150 | + if (is_string($escape)) { |
|
| 151 | + if ($autoQuotes) |
|
| 152 | 152 | return $this->escapeString($escape); |
| 153 | 153 | else |
| 154 | - return $this->escapeString($escape,$quotes); |
|
| 154 | + return $this->escapeString($escape, $quotes); |
|
| 155 | 155 | } |
| 156 | - if(is_array($escape)) { |
|
| 157 | - return $this->escapeArray($escape,$autoQuotes,$quotes); |
|
| 156 | + if (is_array($escape)) { |
|
| 157 | + return $this->escapeArray($escape, $autoQuotes, $quotes); |
|
| 158 | 158 | } |
| 159 | - if(is_object($escape)) { |
|
| 160 | - if($autoQuotes) |
|
| 159 | + if (is_object($escape)) { |
|
| 160 | + if ($autoQuotes) |
|
| 161 | 161 | return $this->escapeObject($escape); |
| 162 | 162 | else |
| 163 | - return $this->escapeObject($escape,$quotes); |
|
| 163 | + return $this->escapeObject($escape, $quotes); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function escapeString($string,$quotes=true,$nullable=false) { |
|
| 168 | - if($nullable===true && ($string===null || $string==='')) |
|
| 167 | + public function escapeString($string, $quotes = true, $nullable = false) { |
|
| 168 | + if ($nullable === true && ($string === null || $string === '')) |
|
| 169 | 169 | return 'NULL'; |
| 170 | - if($string===true) |
|
| 170 | + if ($string === true) |
|
| 171 | 171 | $string = 'TRUE'; |
| 172 | - else if($string===false) |
|
| 172 | + else if ($string === false) |
|
| 173 | 173 | $string = 'FALSE'; |
| 174 | - if(is_array($string)) { |
|
| 174 | + if (is_array($string)) { |
|
| 175 | 175 | $escapedString = ''; |
| 176 | - foreach($string as $value) { |
|
| 177 | - $escapedString .= $this->escapeString($value, $quotes) .','; |
|
| 176 | + foreach ($string as $value) { |
|
| 177 | + $escapedString .= $this->escapeString($value, $quotes) . ','; |
|
| 178 | 178 | } |
| 179 | - return substr($escapedString,0,-1); |
|
| 179 | + return substr($escapedString, 0, -1); |
|
| 180 | 180 | } |
| 181 | - if($quotes) { |
|
| 181 | + if ($quotes) { |
|
| 182 | 182 | return '\'' . self::$dbConn->real_escape_string($string) . '\''; |
| 183 | 183 | } |
| 184 | 184 | return self::$dbConn->real_escape_string($string); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | public function escapeBinary($binary) { |
| 188 | - return '0x'.bin2hex($binary); |
|
| 188 | + return '0x' . bin2hex($binary); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - public function escapeArray(array $array,$autoQuotes=true,$quotes=true,$implodeString=',',$escapeIndividually=true) { |
|
| 191 | + public function escapeArray(array $array, $autoQuotes = true, $quotes = true, $implodeString = ',', $escapeIndividually = true) { |
|
| 192 | 192 | $string = ''; |
| 193 | - if($escapeIndividually) { |
|
| 194 | - foreach($array as $value) { |
|
| 195 | - if(is_array($value)) |
|
| 196 | - $string .= $this->escapeArray($value,$autoQuotes,$quotes,$implodeString,$escapeIndividually).$implodeString; |
|
| 193 | + if ($escapeIndividually) { |
|
| 194 | + foreach ($array as $value) { |
|
| 195 | + if (is_array($value)) |
|
| 196 | + $string .= $this->escapeArray($value, $autoQuotes, $quotes, $implodeString, $escapeIndividually) . $implodeString; |
|
| 197 | 197 | else |
| 198 | - $string .= $this->escape($value, $autoQuotes, $quotes).$implodeString; |
|
| 198 | + $string .= $this->escape($value, $autoQuotes, $quotes) . $implodeString; |
|
| 199 | 199 | } |
| 200 | - $string = substr($string,0,-1); |
|
| 200 | + $string = substr($string, 0, -1); |
|
| 201 | 201 | } |
| 202 | 202 | else { |
| 203 | - $string = $this->escape(implode($implodeString,$array), $autoQuotes, $quotes); |
|
| 203 | + $string = $this->escape(implode($implodeString, $array), $autoQuotes, $quotes); |
|
| 204 | 204 | } |
| 205 | 205 | return $string; |
| 206 | 206 | } |
@@ -211,29 +211,29 @@ discard block |
||
| 211 | 211 | if (is_numeric($num)) { |
| 212 | 212 | return $num; |
| 213 | 213 | } else { |
| 214 | - throw new Exception('Not a number! ('.$num.')'); |
|
| 214 | + throw new Exception('Not a number! (' . $num . ')'); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - public function escapeMicrotime($microtime,$quotes=false) { |
|
| 218 | + public function escapeMicrotime($microtime, $quotes = false) { |
|
| 219 | 219 | $sec_str = sprintf('%010d', $microtime); |
| 220 | - $usec_str = sprintf('%06d', fmod($microtime,1) * 1E6); |
|
| 220 | + $usec_str = sprintf('%06d', fmod($microtime, 1) * 1E6); |
|
| 221 | 221 | return $this->escapeString($sec_str . $usec_str, $quotes); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - public function escapeBoolean($bool,$quotes=true) { |
|
| 225 | - if($bool===true) |
|
| 226 | - return $this->escapeString('TRUE',$quotes); |
|
| 227 | - else if($bool===false) |
|
| 228 | - return $this->escapeString('FALSE',$quotes); |
|
| 224 | + public function escapeBoolean($bool, $quotes = true) { |
|
| 225 | + if ($bool === true) |
|
| 226 | + return $this->escapeString('TRUE', $quotes); |
|
| 227 | + else if ($bool === false) |
|
| 228 | + return $this->escapeString('FALSE', $quotes); |
|
| 229 | 229 | else |
| 230 | 230 | throw new Exception('Not a boolean!'); //TEST |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - public function escapeObject($object,$compress=false,$quotes=true,$nullable=false) { |
|
| 234 | - if($compress===true) |
|
| 233 | + public function escapeObject($object, $compress = false, $quotes = true, $nullable = false) { |
|
| 234 | + if ($compress === true) |
|
| 235 | 235 | return $this->escapeBinary(gzcompress(serialize($object))); |
| 236 | - return $this->escapeString(serialize($object),$quotes,$nullable); |
|
| 236 | + return $this->escapeString(serialize($object), $quotes, $nullable); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | } |