1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: carpcai |
||
5 | * Date: 2018/11/30 |
||
6 | * Time: 6:23 PM |
||
7 | */ |
||
8 | |||
9 | namespace CarpCai\AddressParser; |
||
10 | |||
11 | use CarpCai\AddressParser\Countries\USParser; |
||
12 | |||
13 | class Parser |
||
14 | { |
||
15 | public $country; |
||
16 | |||
17 | /** |
||
18 | * CarpCai <2018/12/1 10:46 PM> |
||
19 | * @param $addressString |
||
20 | * @param string $country |
||
21 | * @return AddressStruct |
||
22 | */ |
||
23 | public function __construct($country = AddressStruct::US) |
||
24 | { |
||
25 | $this->setCountry($country); |
||
26 | } |
||
27 | |||
28 | public function setCountry($country) |
||
29 | { |
||
30 | if (in_array($country, [AddressStruct::US])) { |
||
31 | $this->country = AddressStruct::US; |
||
32 | return $this; |
||
33 | } |
||
34 | return $this; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * CarpCai <2018/12/1 10:20 PM> |
||
40 | */ |
||
41 | static function newParse($addressString, $country = AddressStruct::US) |
||
42 | { |
||
43 | $class = new static($addressString); |
||
44 | $class->setCountry($country); |
||
45 | return $class->_parse($addressString); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * CarpCai <2018/12/1 10:19 PM> |
||
50 | */ |
||
51 | public function parse($addressString) |
||
52 | { |
||
53 | return $this->_parse($addressString); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * CarpCai <2018/12/1 10:46 PM> |
||
58 | * @param $addressString |
||
59 | * @param string $country |
||
60 | * @return AddressStruct |
||
61 | */ |
||
62 | private function _parse($addressString, $country = AddressStruct::US) |
||
0 ignored issues
–
show
|
|||
63 | { |
||
64 | //TODO: 根据不同国家生成不同实例 |
||
65 | return (new USParser())->split($addressString); |
||
66 | } |
||
67 | } |
||
68 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.