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 |
||
12 | class DeviceTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | |||
15 | public function testIPhone() |
||
16 | { |
||
17 | $ualist = array( |
||
18 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257', |
||
19 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4', |
||
20 | 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3', |
||
21 | 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3' |
||
22 | ); |
||
23 | |||
24 | testUaList($this,'Device','Name',$ualist,'iPhone'); |
||
25 | testUaListIsProperty($this,'isMobile',$ualist,true); |
||
26 | } |
||
27 | |||
28 | public function testIPad() |
||
29 | { |
||
30 | $ualist = array( |
||
31 | 'Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25', |
||
32 | 'Mozilla/5.0 (iPad; CPU OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/25.0.1364.124 Mobile/10B146 Safari/8536.25', |
||
33 | 'Mozilla/5.0 (iPad; CPU OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B147 Safari/8536.25', |
||
34 | 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206' |
||
35 | ); |
||
36 | |||
37 | testUaList($this,'Device','Name',$ualist,'iPad'); |
||
38 | } |
||
39 | |||
40 | public function testLumia() |
||
41 | { |
||
42 | $ualist = array( |
||
43 | 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 625)', |
||
44 | 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 625H)', |
||
45 | 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1520)', |
||
46 | 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)' |
||
47 | ); |
||
48 | |||
49 | testUaList($this,'Device','Name',$ualist,'Lumia'); |
||
50 | testUaListIsProperty($this,'isMobile',$ualist,true); |
||
51 | } |
||
52 | } |
||
53 |