Completed
Branch BETA-4.9-message-activity (c2a8e0)
by
unknown
18:28 queued 10s
created

MultiLineAddressFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 40
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B format() 24 24 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace EventEspresso\core\services\address\formatters;
3
4
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
	exit( 'No direct script access allowed' );
6
}
7
8
9
10
/**
11
 * Class MultiLineAddressFormatter
12
 * This class will format an address and add line breaks in appropriate places
13
 *
14
 * @package       Event Espresso
15
 * @subpackage    core/services/address/formatters
16
 * @author        Brent Christensen
17
 * @since         4.8
18
 */
19 View Code Duplication
class MultiLineAddressFormatter extends AddressFormatter implements \EEI_Address_Formatter {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
21
22
	/**
23
	 * @param string $address
24
	 * @param string $address2
25
	 * @param string $city
26
	 * @param string $state
27
	 * @param string $zip
28
	 * @param string $country
29
	 * @param string $CNT_ISO
30
	 * @return string
31
	 */
32
	public function format( $address, $address2, $city, $state, $zip, $country, $CNT_ISO ) {
33
		$address_formats = apply_filters(
34
			'FHEE__EE_MultiLine_Address_Formatter__address_formats',
35
			array(
36
				'CA' => "{address}%{address2}%{city}%{state}%{country}%{zip}",
37
				'GB' => "{address}%{address2}%{city}%{state}%{zip}%{country}",
38
				'US' => "{address}%{address2}%{city}%{state}%{zip}%{country}",
39
				'ZZ' => "{address}%{address2}%{city}%{state}%{zip}%{country}",
40
			)
41
		);
42
		// if the incoming country has a set format, use that, else use the default
43
		$formatted_address = isset( $address_formats[ $CNT_ISO ] ) ? $address_formats[ $CNT_ISO ]
44
			: $address_formats['ZZ'];
45
		return $this->parse_formatted_address(
46
			$address,
47
			$address2,
48
			$city,
49
			$state,
50
			$zip,
51
			$country,
52
			$formatted_address,
53
			'<br />'
54
		);
55
	}
56
57
58
}
59
// End of file MultiLineAddressFormatter.php
60
// Location: core/services/address/formatters/MultiLineAddressFormatter.php