@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param bool $includeColumnNames - Whether to include column names. Default:false |
| 24 | 24 | * @return string[] |
| 25 | 25 | */ |
| 26 | - public function extractSqlValuesFromFile($filePath, $patternToMatchFor=null, $includeColumnNames=false) |
|
| 26 | + public function extractSqlValuesFromFile($filePath, $patternToMatchFor = null, $includeColumnNames = false) |
|
| 27 | 27 | { |
| 28 | 28 | if (!file_exists($filePath) || !is_string($filePath)) { |
| 29 | 29 | throw new SqlReplacerException("File '$filePath' does not exist"); |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * @param bool $includeColumnNames - Whether to include column names. Default:false |
| 47 | 47 | * @return string[] |
| 48 | 48 | */ |
| 49 | - public function extractSqlValues($contents, $patternToMatchFor=null, $includeColumnNames=false) |
|
| 49 | + public function extractSqlValues($contents, $patternToMatchFor = null, $includeColumnNames = false) |
|
| 50 | 50 | { |
| 51 | - $tokens=[]; |
|
| 51 | + $tokens = []; |
|
| 52 | 52 | if (preg_match_all("/\(.*\)/U", $contents, $matches)) { |
| 53 | - $tokens=$matches[0]; |
|
| 53 | + $tokens = $matches[0]; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $tokens = array_filter($tokens, function ($token) { |
|
| 57 | - return $token[0]=="(" && $token[strlen($token)-1]==")"; |
|
| 56 | + $tokens = array_filter($tokens, function($token) { |
|
| 57 | + return $token[0] == "(" && $token[strlen($token)-1] == ")"; |
|
| 58 | 58 | }); |
| 59 | - $tokens = array_map(function ($piece) use ($includeColumnNames) { |
|
| 59 | + $tokens = array_map(function($piece) use ($includeColumnNames) { |
|
| 60 | 60 | $piece = trim(trim($piece, "("), ")"); |
| 61 | 61 | $pieces = explode(",", $piece); |
| 62 | - $pieces= array_filter(array_map('trim', $pieces), function ($p) { |
|
| 63 | - return !empty($p) && strlen($p)>0; |
|
| 62 | + $pieces = array_filter(array_map('trim', $pieces), function($p) { |
|
| 63 | + return !empty($p) && strlen($p) > 0; |
|
| 64 | 64 | }); |
| 65 | 65 | $pieces = array_values($pieces); |
| 66 | - if (!$includeColumnNames && count($pieces)>0) { |
|
| 66 | + if (!$includeColumnNames && count($pieces) > 0) { |
|
| 67 | 67 | $firstPiece = $pieces[0]; |
| 68 | 68 | |
| 69 | 69 | |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | }, $tokens); |
| 79 | 79 | |
| 80 | 80 | $matches = []; |
| 81 | - array_walk_recursive($tokens, function ($value) use (&$matches,$patternToMatchFor) { |
|
| 82 | - if ($patternToMatchFor===null || |
|
| 81 | + array_walk_recursive($tokens, function($value) use (&$matches, $patternToMatchFor) { |
|
| 82 | + if ($patternToMatchFor === null || |
|
| 83 | 83 | stripos($value, $patternToMatchFor) !== false) { |
| 84 | - $matches[]=$value; |
|
| 84 | + $matches[] = $value; |
|
| 85 | 85 | } |
| 86 | 86 | }); |
| 87 | 87 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function replaceValue($contents, $value, $replaceWith) |
| 101 | 101 | { |
| 102 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
| 102 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
| 103 | 103 | throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); |
| 104 | 104 | }); |
| 105 | 105 | $matches = $this->extractSqlValues($contents, $value); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $matchWithoutQuotes = str_replace("\\\"", "\"", trim(trim($match, "'"))); |
| 109 | 109 | if ($this->isSerializedValue($matchWithoutQuotes)) { |
| 110 | 110 | $matchReplaced = str_replace($value, $replaceWith, $matchWithoutQuotes); |
| 111 | - $matchReplaced = preg_replace_callback('!s:(\d+):"(.*?)";!', function ($match) { |
|
| 111 | + $matchReplaced = preg_replace_callback('!s:(\d+):"(.*?)";!', function($match) { |
|
| 112 | 112 | return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
| 113 | 113 | }, $matchReplaced); |
| 114 | 114 | try { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | $contents = str_replace($match, $matchReplaced, $contents); |
| 125 | 125 | } |
| 126 | - $contents=str_replace($value, $replaceWith, $contents); |
|
| 126 | + $contents = str_replace($value, $replaceWith, $contents); |
|
| 127 | 127 | restore_error_handler(); |
| 128 | 128 | return $contents; |
| 129 | 129 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @throws Exceptions\SqlReplacerException |
| 139 | 139 | * @return string Updated Contents |
| 140 | 140 | */ |
| 141 | - public function replaceValueFromFile($sourceFile, $value, $replaceWith, $destinationFile=null) |
|
| 141 | + public function replaceValueFromFile($sourceFile, $value, $replaceWith, $destinationFile = null) |
|
| 142 | 142 | { |
| 143 | 143 | if (!file_exists($sourceFile) || !is_string($sourceFile)) { |
| 144 | 144 | throw new SqlReplacerException("Source File '$sourceFile' does not exist"); |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * @param bool $strict - Whether to be strict about the end of the string. |
| 168 | 168 | * @return bool Whether value is serialized or not |
| 169 | 169 | */ |
| 170 | - public function isSerializedValue($data, $strict=true) |
|
| 170 | + public function isSerializedValue($data, $strict = true) |
|
| 171 | 171 | { |
| 172 | 172 | //CREDIT TO: Wordpress.com |
| 173 | 173 | // If it isn't a string, it isn't serialized. |
| 174 | - if (! is_string($data)) { |
|
| 174 | + if (!is_string($data)) { |
|
| 175 | 175 | return false; |
| 176 | 176 | } |
| 177 | 177 | $data = trim($data); |