Code Duplication    Length = 48-48 lines in 2 locations

packages/redirect/src/class-redirect.php 1 location

@@ 56-103 (lines=48) @@
53
	 *
54
	 * @return string The built URL
55
	 */
56
	public static function get_url( $source, $args = array() ) {
57
58
		$url           = 'https://jetpack.com/redirect';
59
		$args          = wp_parse_args( $args, array( 'site' => self::build_raw_urls( get_home_url() ) ) );
60
		$accepted_args = array( 'site', 'path', 'query', 'anchor' );
61
62
		$source_key = 'source';
63
		$is_url     = false;
64
65
		if ( 0 === strpos( $source, 'https://' ) ) {
66
			$source_key = 'url';
67
			$is_url     = true;
68
			$source_url = \wp_parse_url( $source );
69
70
			// discard any query and fragments.
71
			$source = 'https://' . $source_url['host'] . ( isset( $source_url['path'] ) ? $source_url['path'] : '' );
72
		}
73
74
		$to_be_added = array(
75
			$source_key => rawurlencode( $source ),
76
		);
77
78
		foreach ( $args as $arg_name => $arg_value ) {
79
80
			if ( ! in_array( $arg_name, $accepted_args, true ) || empty( $arg_value ) ) {
81
				continue;
82
			}
83
84
			$to_be_added[ $arg_name ] = rawurlencode( $arg_value );
85
86
		}
87
88
		if ( ! empty( $to_be_added ) ) {
89
			$url = add_query_arg( $to_be_added, $url );
90
		}
91
92
		/**
93
		 * Filters the return of the Redirect URL.
94
		 *
95
		 * @since 8.6.0
96
		 *
97
		 * @param string  $url    The redirect URL.
98
		 * @param string  $source The $source informed to Redirect::get_url.
99
		 * @param array   $args   The arguments informed to Redirect::get_url.
100
		 * @param boolean $is_url Whether $source is a URL or not.
101
		 */
102
		return \apply_filters( 'jetpack_redirects_get_url', $url, $source, $args, $is_url );
103
	}
104
}
105

packages/soft-wordpress-test/src/class-soft-wordpress.php 1 location

@@ 56-103 (lines=48) @@
53
	 *
54
	 * @return string The built URL
55
	 */
56
	public static function get_url( $source, $args = array() ) {
57
58
		$url           = 'https://jetpack.com/redirect';
59
		$args          = wp_parse_args( $args, array( 'site' => self::build_raw_urls( get_home_url() ) ) );
60
		$accepted_args = array( 'site', 'path', 'query', 'anchor' );
61
62
		$source_key = 'source';
63
		$is_url     = false;
64
65
		if ( 0 === strpos( $source, 'https://' ) ) {
66
			$source_key = 'url';
67
			$is_url     = true;
68
			$source_url = \wp_parse_url( $source );
69
70
			// discard any query and fragments.
71
			$source = 'https://' . $source_url['host'] . ( isset( $source_url['path'] ) ? $source_url['path'] : '' );
72
		}
73
74
		$to_be_added = array(
75
			$source_key => rawurlencode( $source ),
76
		);
77
78
		foreach ( $args as $arg_name => $arg_value ) {
79
80
			if ( ! in_array( $arg_name, $accepted_args, true ) || empty( $arg_value ) ) {
81
				continue;
82
			}
83
84
			$to_be_added[ $arg_name ] = rawurlencode( $arg_value );
85
86
		}
87
88
		if ( ! empty( $to_be_added ) ) {
89
			$url = add_query_arg( $to_be_added, $url );
90
		}
91
92
		/**
93
		 * Filters the return of the Redirect URL.
94
		 *
95
		 * @since 8.6.0
96
		 *
97
		 * @param string  $url    The redirect URL.
98
		 * @param string  $source The $source informed to Redirect::get_url.
99
		 * @param array   $args   The arguments informed to Redirect::get_url.
100
		 * @param boolean $is_url Whether $source is a URL or not.
101
		 */
102
		return \apply_filters( 'jetpack_redirects_get_url', $url, $source, $args, $is_url );
103
	}
104
105
	public static function store( $name, $value ) {
106
		update_option( $name, $value );