@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @param bool $includeColumnNames - Whether to include column names. Default:false |
25 | 25 | * @return string[] |
26 | 26 | */ |
27 | - public function extractSqlValuesFromFile($filePath, $patternToMatchFor=null, $includeColumnNames=false) |
|
27 | + public function extractSqlValuesFromFile($filePath, $patternToMatchFor = null, $includeColumnNames = false) |
|
28 | 28 | { |
29 | 29 | if (!file_exists($filePath) || !is_string($filePath)) { |
30 | 30 | throw new SqlReplacerException("File '$filePath' does not exist"); |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | * @param bool $includeColumnNames - Whether to include column names. Default:false |
48 | 48 | * @return string[] |
49 | 49 | */ |
50 | - public function extractSqlValues($contents, $patternToMatchFor=null, $includeColumnNames=false) |
|
50 | + public function extractSqlValues($contents, $patternToMatchFor = null, $includeColumnNames = false) |
|
51 | 51 | { |
52 | - $tokens=[]; |
|
52 | + $tokens = []; |
|
53 | 53 | if (preg_match_all("/\(.*\)/U", $contents, $matches)) { |
54 | - $tokens=$matches[0]; |
|
54 | + $tokens = $matches[0]; |
|
55 | 55 | } |
56 | 56 | |
57 | - $tokens = array_filter($tokens, function ($token) { |
|
58 | - return $token[0]=="(" && $token[strlen($token)-1]==")"; |
|
57 | + $tokens = array_filter($tokens, function($token) { |
|
58 | + return $token[0] == "(" && $token[strlen($token)-1] == ")"; |
|
59 | 59 | }); |
60 | - $tokens = array_map(function ($piece) use ($includeColumnNames) { |
|
60 | + $tokens = array_map(function($piece) use ($includeColumnNames) { |
|
61 | 61 | $piece = trim(trim($piece, "("), ")"); |
62 | 62 | $pieces = explode(",", $piece); |
63 | - $pieces= array_filter(array_map('trim', $pieces), function ($p) { |
|
64 | - return !empty($p) && strlen($p)>0; |
|
63 | + $pieces = array_filter(array_map('trim', $pieces), function($p) { |
|
64 | + return !empty($p) && strlen($p) > 0; |
|
65 | 65 | }); |
66 | 66 | $pieces = array_values($pieces); |
67 | - if (!$includeColumnNames && count($pieces)>0) { |
|
67 | + if (!$includeColumnNames && count($pieces) > 0) { |
|
68 | 68 | $firstPiece = $pieces[0]; |
69 | 69 | |
70 | 70 | |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | }, $tokens); |
80 | 80 | |
81 | 81 | $matches = []; |
82 | - array_walk_recursive($tokens, function ($value) use (&$matches,$patternToMatchFor) { |
|
83 | - if ($patternToMatchFor===null || |
|
82 | + array_walk_recursive($tokens, function($value) use (&$matches, $patternToMatchFor) { |
|
83 | + if ($patternToMatchFor === null || |
|
84 | 84 | stripos($value, $patternToMatchFor) !== false) { |
85 | - $matches[]=$value; |
|
85 | + $matches[] = $value; |
|
86 | 86 | } |
87 | 87 | }); |
88 | 88 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function replaceValue($contents, $value, $replaceWith) |
102 | 102 | { |
103 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
103 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
104 | 104 | throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); |
105 | 105 | }); |
106 | 106 | $matches = $this->extractSqlValues($contents, $value); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $matchWithoutQuotes = str_replace("\\\"", "\"", trim(trim($match, "'"))); |
110 | 110 | if (Serialization::isSerializedValue($matchWithoutQuotes)) { |
111 | 111 | $matchReplaced = str_replace($value, $replaceWith, $matchWithoutQuotes); |
112 | - $matchReplaced = preg_replace_callback('!s:(\d+):"(.*?)";!', function ($match) { |
|
112 | + $matchReplaced = preg_replace_callback('!s:(\d+):"(.*?)";!', function($match) { |
|
113 | 113 | return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
114 | 114 | }, $matchReplaced); |
115 | 115 | try { |
@@ -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"); |