Conditions | 11 |
Paths | 42 |
Total Lines | 37 |
Code Lines | 25 |
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 |
||
40 | private function queryUrl($url) { |
||
41 | $provider = []; |
||
|
|||
42 | try { |
||
43 | $xml = @simplexml_load_file($url); |
||
44 | if (!is_object($xml) || !$xml->emailProvider) { |
||
45 | return []; |
||
46 | } |
||
47 | $provider = [ |
||
48 | 'displayName' => (string) $xml->emailProvider->displayName, |
||
49 | ]; |
||
50 | foreach ($xml->emailProvider->children() as $tag => $server) { |
||
51 | if (!in_array($tag, ['incomingServer', 'outgoingServer'])) { |
||
52 | continue; |
||
53 | } |
||
54 | foreach ($server->attributes() as $name => $value) { |
||
55 | if ($name == 'type') { |
||
56 | $type = (string) $value; |
||
57 | } |
||
58 | } |
||
59 | $data = []; |
||
60 | foreach ($server as $name => $value) { |
||
61 | foreach ($value->children() as $tag => $val) { |
||
62 | $data[$name][$tag] = (string) $val; |
||
63 | } |
||
64 | if (!isset($data[$name])) { |
||
65 | $data[$name] = (string) $value; |
||
66 | } |
||
67 | } |
||
68 | $provider[$type][] = $data; |
||
69 | } |
||
70 | } catch (Exception $e) { |
||
71 | // ignore own not-found exception or xml parsing exceptions |
||
72 | unset($e); |
||
73 | $provider = []; |
||
74 | } |
||
75 | return $provider; |
||
76 | } |
||
77 | |||
110 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.