Completed
Push — master ( b55932...7ec029 )
by Nicholas
04:51
created

Address   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 11.9 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 10
loc 84
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 16 1
A cityState() 10 10 1
A cityStateMultiple() 0 12 2
A zipCode() 0 13 1

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
3
namespace Nickcheek\USPSLookup\Service;
4
5
use Nickcheek\USPSLookup\USPSLookup;
6
7
class Address extends USPSLookup
8
{
9
    /**
10
     * Verify Address is current and/or inhabited
11
     * @param $address
12
     * @param $address2
13
     * @param $city
14
     * @param $state
15
     * @param $zip
16
     * @return object
17
     */
18
    public static function verify($address,$address2,$city,$state,$zip): object
19
    {
20
        $Address = new \SimpleXMLElement("<AddressValidateRequest></AddressValidateRequest>");
21
        $Address->addAttribute('USERID', self::$USPSuser);
22
        $Address->addChild('Revision','1');
23
        $add = $Address->addChild('Address');
24
        $add->addAttribute('ID', '0');
25
        $add->addChild('Address1',$address);
26
        $add->addChild('Address2',$address2);
27
        $add->addChild('City',$city);
28
        $add->addChild('State',$state);
29
        $add->addChild('Zip5',$zip);
30
        $add->addChild('Zip4');
31
        $url = self::$service . 'Verify&XML=' . $Address->asXML();
32
        return simplexml_load_file($url);
33
    }
34
35
    /**
36
     * City and State lookup from zipcode.
37
     * @param $zip
38
     * @return \SimpleXMLElement
39
     */
40 View Code Duplication
    public static function cityState($zip): object
0 ignored issues
show
Duplication introduced by
This method 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...
41
    {
42
        $CityState = new \SimpleXMLElement("<CityStateLookupRequest></CityStateLookupRequest>");
43
        $CityState->addAttribute('USERID', self::$USPSuser);
44
        $ZipCode = $CityState->addChild('ZipCode');
45
        $ZipCode->addAttribute('ID', '0');
46
        $ZipCode->addChild('Zip5',$zip);
47
        $url = self::$service . 'CityStateLookup&XML=' . $CityState->asXML();
48
        return simplexml_load_file($url);
49
    }
50
51
    /**
52
     * Mulitple city and state lookup
53
     * @param $zip (array)
54
     * @return \SimpleXMLElement
55
     */
56
    public static function cityStateMultiple($zip): object
57
    {
58
        $CityState = new \SimpleXMLElement("<CityStateLookupRequest></CityStateLookupRequest>");
59
        $CityState->addAttribute('USERID', self::$USPSuser);
60
        foreach($zip as $k=>$v){
61
            $ZipCode = $CityState->addChild('ZipCode');
62
            $ZipCode->addAttribute('ID', $k);
63
            $ZipCode->addChild('Zip5',$v);
64
        }
65
        $url = self::$service . 'CityStateLookup&XML=' . $CityState->asXML();
66
        return simplexml_load_file($url);
67
    }
68
69
    /**
70
     * Zipcode lookup by Address, City, and State
71
     * @param $address
72
     * @param $address2
73
     * @param $city
74
     * @param $state
75
     * @return \SimpleXMLElement
76
     */
77
    public static function zipCode($address,$address2,$city,$state): object
78
    {
79
        $Address = new \SimpleXMLElement("<ZipCodeLookupRequest></ZipCodeLookupRequest>");
80
        $Address->addAttribute('USERID', self::$USPSuser);
81
        $add = $Address->addChild('Address');
82
        $add->addAttribute('ID', '0');
83
        $add->addChild('Address1',$address);
84
        $add->addChild('Address2',$address2);
85
        $add->addChild('City',$city);
86
        $add->addChild('State',$state);
87
        $url = self::$service . 'ZipCodeLookup&XML=' . $Address->asXML();
88
        return simplexml_load_file($url);
89
    }
90
}
91