Completed
Push — master ( 7a7049...b55932 )
by Nicholas
02:26
created

Address::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 SimpleXMLElement
17
     */
18
    public static function Verify($address,$address2,$city,$state,$zip)
19
    {
20
        $Address = new \SimpleXMLElement("<AddressValidateRequest></AddressValidateRequest>");
21
        $Address->addAttribute('USERID', self::$user);
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)
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::$user);
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)
57
    {
58
        $CityState = new \SimpleXMLElement("<CityStateLookupRequest></CityStateLookupRequest>");
59
        $CityState->addAttribute('USERID', self::$user);
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)
78
    {
79
        $Address = new \SimpleXMLElement("<ZipCodeLookupRequest></ZipCodeLookupRequest>");
80
        $Address->addAttribute('USERID', self::$user);
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