@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | throw new SqlReplacerException("File '$filePath' does not exist"); |
| 30 | 30 | } |
| 31 | 31 | return $this->extractSqlValues( |
| 32 | - file_get_contents($filePath), |
|
| 33 | - $patternToMatchFor, |
|
| 34 | - $includeColumnNames |
|
| 35 | - ); |
|
| 32 | + file_get_contents($filePath), |
|
| 33 | + $patternToMatchFor, |
|
| 34 | + $includeColumnNames |
|
| 35 | + ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | throw new SqlReplacerException("Destination File '$destinationFile' is required"); |
| 149 | 149 | } |
| 150 | 150 | $contents = $this->replaceValue( |
| 151 | - file_get_contents($sourceFile), |
|
| 152 | - $value, |
|
| 153 | - $replaceWith |
|
| 151 | + file_get_contents($sourceFile), |
|
| 152 | + $value, |
|
| 153 | + $replaceWith |
|
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | 156 | if ($destinationFile) { |
@@ -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,14 +108,14 @@ 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 { |
| 115 | 115 | unserialize($matchReplaced); |
| 116 | 116 | } catch (\Exception $e) { |
| 117 | 117 | //silently ignore |
| 118 | - $matchReplaced=$match; |
|
| 118 | + $matchReplaced = $match; |
|
| 119 | 119 | continue; |
| 120 | 120 | } |
| 121 | 121 | $matchReplaced = "'$matchReplaced'"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | $contents = str_replace($match, $matchReplaced, $contents); |
| 126 | 126 | } |
| 127 | - $contents=str_replace($value, $replaceWith, $contents); |
|
| 127 | + $contents = str_replace($value, $replaceWith, $contents); |
|
| 128 | 128 | restore_error_handler(); |
| 129 | 129 | return $contents; |
| 130 | 130 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @throws Exceptions\SqlReplacerException |
| 140 | 140 | * @return string Updated Contents |
| 141 | 141 | */ |
| 142 | - public function replaceValueFromFile($sourceFile, $value, $replaceWith, $destinationFile=null) |
|
| 142 | + public function replaceValueFromFile($sourceFile, $value, $replaceWith, $destinationFile = null) |
|
| 143 | 143 | { |
| 144 | 144 | if (!file_exists($sourceFile) || !is_string($sourceFile)) { |
| 145 | 145 | throw new SqlReplacerException("Source File '$sourceFile' does not exist"); |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * @param bool $strict - Whether to be strict about the end of the string. |
| 169 | 169 | * @return bool Whether value is serialized or not |
| 170 | 170 | */ |
| 171 | - public function isSerializedValue($data, $strict=true) |
|
| 171 | + public function isSerializedValue($data, $strict = true) |
|
| 172 | 172 | { |
| 173 | 173 | //CREDIT TO: Wordpress.com |
| 174 | 174 | // If it isn't a string, it isn't serialized. |
| 175 | - if (! is_string($data)) { |
|
| 175 | + if (!is_string($data)) { |
|
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | $data = trim($data); |