Skip to content

Commit 30b9044

Browse files
Copilotswissspidy
andcommitted
Refactor: make json_encode_strip_quotes() public static and reuse from SearchReplacer
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent d007b98 commit 30b9044

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/Search_Replace_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ private static function esc_like( $old ) {
939939
* @param string $str The string to encode.
940940
* @return string The JSON-encoded string without surrounding quotes, or the original string on failure.
941941
*/
942-
private static function json_encode_strip_quotes( $str ) {
942+
public static function json_encode_strip_quotes( $str ) {
943943
$encoded = json_encode( $str ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
944944
return false !== $encoded ? substr( $encoded, 1, -1 ) : $str;
945945
}

src/WP_CLI/SearchReplacer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ public function __construct( $from, $to, $recurse_objects = false, $regex = fals
8989
$this->clear_log_data();
9090

9191
// Compute JSON-encoded versions (stripping outer quotes) for handling raw JSON values in the database.
92-
$from_encoded = json_encode( $from ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
93-
$this->from_json = false !== $from_encoded ? substr( $from_encoded, 1, -1 ) : $from;
94-
$to_encoded = json_encode( $to ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
95-
$this->to_json = false !== $to_encoded ? substr( $to_encoded, 1, -1 ) : $to;
92+
$this->from_json = \Search_Replace_Command::json_encode_strip_quotes( $from );
93+
$this->to_json = \Search_Replace_Command::json_encode_strip_quotes( $to );
9694

9795
// Get the XDebug nesting level. Will be zero (no limit) if no value is set
9896
$this->max_recursion = intval( ini_get( 'xdebug.max_nesting_level' ) );

0 commit comments

Comments
 (0)