Code Duplication    Length = 30-30 lines in 2 locations

includes/shipping/local-pickup/class-wc-shipping-local-pickup.php 1 location

@@ 101-130 (lines=30) @@
98
	 * @param  string country code
99
	 * @return boolean
100
	 */
101
	public function is_valid_postcode( $postcode, $country ) {
102
		$codes              = $this->get_valid_postcodes();
103
		$postcode           = $this->clean( $postcode );
104
		$formatted_postcode = wc_format_postcode( $postcode, $country );
105
106
		if ( in_array( $postcode, $codes ) || in_array( $formatted_postcode, $codes ) ) {
107
			return true;
108
		}
109
110
		// Pattern matching
111
		foreach ( $codes as $c ) {
112
			$pattern = '/^' . str_replace( '_', '[0-9a-zA-Z]', preg_quote( $c ) ) . '$/i';
113
			if ( preg_match( $pattern, $postcode ) ) {
114
				return true;
115
			}
116
		}
117
118
		// Wildcard search
119
		$wildcard_postcode = $formatted_postcode . '*';
120
		$postcode_length   = strlen( $formatted_postcode );
121
122
		for ( $i = 0; $i < $postcode_length; $i++ ) {
123
			if ( in_array( $wildcard_postcode, $codes ) ) {
124
				return true;
125
			}
126
			$wildcard_postcode = substr( $wildcard_postcode, 0, -2 ) . '*';
127
		}
128
129
		return false;
130
	}
131
132
	/**
133
	 * See if the method is available.

includes/shipping/legacy-local-pickup/class-wc-shipping-legacy-local-pickup.php 1 location

@@ 154-183 (lines=30) @@
151
	 * @param  string country code
152
	 * @return boolean
153
	 */
154
	public function is_valid_postcode( $postcode, $country ) {
155
		$codes              = $this->get_valid_postcodes();
156
		$postcode           = $this->clean( $postcode );
157
		$formatted_postcode = wc_format_postcode( $postcode, $country );
158
159
		if ( in_array( $postcode, $codes ) || in_array( $formatted_postcode, $codes ) ) {
160
			return true;
161
		}
162
163
		// Pattern matching
164
		foreach ( $codes as $c ) {
165
			$pattern = '/^' . str_replace( '_', '[0-9a-zA-Z]', preg_quote( $c ) ) . '$/i';
166
			if ( preg_match( $pattern, $postcode ) ) {
167
				return true;
168
			}
169
		}
170
171
		// Wildcard search
172
		$wildcard_postcode = $formatted_postcode . '*';
173
		$postcode_length   = strlen( $formatted_postcode );
174
175
		for ( $i = 0; $i < $postcode_length; $i++ ) {
176
			if ( in_array( $wildcard_postcode, $codes ) ) {
177
				return true;
178
			}
179
			$wildcard_postcode = substr( $wildcard_postcode, 0, -2 ) . '*';
180
		}
181
182
		return false;
183
	}
184
185
	/**
186
	 * See if the method is available.