Parser::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
Unused Code introduced by
The parameter $country is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
    private function _parse($addressString, /** @scrutinizer ignore-unused */ $country = AddressStruct::US)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        //TODO: 根据不同国家生成不同实例
65
        return (new USParser())->split($addressString);
66
    }
67
}
68