| Conditions | 11 |
| Paths | 2 |
| Total Lines | 50 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 31 | public function Links($dom) |
||
| 32 | { |
||
| 33 | $tags = $dom->getElementsByTagName('a'); |
||
| 34 | $links = array(); |
||
| 35 | |||
| 36 | if($tags->length) |
||
| 37 | { |
||
| 38 | foreach($tags as $item) |
||
| 39 | { |
||
| 40 | $link = $item->getAttribute('href'); |
||
| 41 | |||
| 42 | if($link != '' && strpos($link,'#') !== 0 && strpos(strtolower($link),'javascript:') !== 0) |
||
| 43 | { |
||
| 44 | $link = parse_url($link); |
||
| 45 | |||
| 46 | if(!isset($link['scheme'])) |
||
| 47 | { |
||
| 48 | $link['scheme'] = $this->data['parsed_url']['scheme']; |
||
| 49 | } |
||
| 50 | |||
| 51 | if(!isset($link['host'])) |
||
| 52 | { |
||
| 53 | $link['host'] = $this->data['parsed_url']['host']; |
||
| 54 | } |
||
| 55 | |||
| 56 | if(!isset($link['path'])) |
||
| 57 | { |
||
| 58 | $link['path'] = ''; |
||
| 59 | } else { |
||
| 60 | if(strpos($link['path'],'/') !== 0) |
||
| 61 | { |
||
| 62 | $link['path'] = '/'.$link['path']; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | if(!isset($link['query'])) |
||
| 67 | { |
||
| 68 | $link['query'] = ''; |
||
| 69 | } else { |
||
| 70 | $link['query'] = '?'.$link['query']; |
||
| 71 | } |
||
| 72 | |||
| 73 | $links[] = $link['scheme'].'://'.$link['host'].$link['path'].$link['query']; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $this->links = array_unique($links); |
||
| 79 | |||
| 80 | return $this; |
||
| 81 | } |
||
| 127 | } |