Conditions | 10 |
Paths | 28 |
Total Lines | 57 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
24 | public function extract() |
||
25 | { |
||
26 | $addressElement = $this->webDriver->byXpath($this->getBaseXpath()); |
||
27 | $text = $addressElement->getText(); |
||
28 | $rows = explode("\n", $text); |
||
29 | |||
30 | $rows = array_reverse($rows); |
||
31 | $this->name = trim(array_pop($rows)); |
||
32 | while (count($rows) > 0) { |
||
33 | $row = array_shift($rows); |
||
34 | if (strpos($row, 'T: ') ===0) { |
||
35 | $this->phone = trim(substr($row, 3)); |
||
36 | continue; |
||
37 | } else if (strpos($row, 'F: ') ===0) { |
||
38 | $this->fax = trim(substr($row, 3)); |
||
39 | continue; |
||
40 | } |
||
41 | if ($this->country === null) { |
||
42 | $this->country = trim($row); |
||
43 | continue; |
||
44 | } |
||
45 | if ($this->postCode === null) { |
||
46 | $parts = explode(',', $row); |
||
47 | $this->postCode = trim(array_pop($parts)); |
||
48 | $this->city = trim(array_shift($parts)); |
||
49 | if (count($parts) > 0) { |
||
50 | $this->region = trim(array_shift($parts)); |
||
51 | } |
||
52 | break; // After this point we have to figure out business, st1 and st2; two of which are not required |
||
53 | } |
||
54 | |||
55 | } |
||
56 | // Easy |
||
57 | if (count($rows) == 3) { |
||
58 | $this->street2 = trim(array_shift($rows)); |
||
59 | $this->street1 = trim(array_shift($rows)); |
||
60 | $this->business = trim(array_shift($rows)); |
||
61 | //Easy |
||
62 | }else if (count($rows) == 1) { |
||
63 | $this->street1 = trim(array_shift($rows)); |
||
64 | |||
65 | // Not so easy |
||
66 | } else { |
||
67 | $stOrBus = trim(array_shift($rows)); |
||
68 | if (preg_match('/^\d+ /', $stOrBus)) { // Good chance of street 1 (could be a business, though) |
||
69 | |||
70 | $this->street1 = $stOrBus; |
||
71 | $this->business = trim(array_shift($rows)); |
||
72 | } else { |
||
73 | $this->street1 =trim(array_shift($rows)); |
||
74 | $this->street2 = $stOrBus; |
||
75 | } |
||
76 | |||
77 | } |
||
78 | $this->remainingRows = $rows; |
||
79 | |||
80 | } |
||
81 | |||
172 | } |