Conditions | 10 |
Paths | 10 |
Total Lines | 38 |
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 |
||
30 | public function safelist(array $safelist) |
||
31 | { |
||
32 | $this->_definitions = array(); |
||
33 | |||
34 | foreach ($safelist as $definition) |
||
35 | { |
||
36 | // Pre-configured object |
||
37 | if (is_object($definition)) |
||
38 | { |
||
39 | if ($definition instanceof Definition\IDefinition) |
||
40 | $definitionObject = $definition; |
||
41 | else |
||
42 | throw new \InvalidArgumentException('Definition objects must implement IDefinition'); |
||
43 | } |
||
44 | // IPv4 address |
||
45 | elseif (preg_match('/[a-z:\/]/', $definition) === 0) |
||
46 | $definitionObject = new Definition\IPv4Address($definition); |
||
47 | // IPv4 CIDR notation |
||
48 | elseif (preg_match('/[a-z:]/', $definition) === 0) |
||
49 | $definitionObject = new Definition\IPv4CIDR($definition); |
||
50 | // IPv6 address |
||
51 | elseif (preg_match('/^[0-9a-f:]+$/', $definition)) |
||
52 | $definitionObject = new Definition\IPv6Address($definition); |
||
53 | // IPv6 CIDR notation |
||
54 | elseif (preg_match('/^[0-9a-f:\/]+$/', $definition)) |
||
55 | $definitionObject = new Definition\IPv6CIDR($definition); |
||
56 | // Wildcard domain |
||
57 | elseif (preg_match('/^\*\.[\w\.\-]+$/', $definition)) |
||
58 | $definitionObject = new Definition\WildcardDomain($definition); |
||
59 | // Domain |
||
60 | elseif (preg_match('/^[\w\.\-]+$/', $definition)) |
||
61 | $definitionObject = new Definition\Domain($definition); |
||
62 | else |
||
63 | throw new \InvalidArgumentException('Unable to parse definition "'.$definition.'"'); |
||
64 | |||
65 | $this->_definitions[] = $definitionObject; |
||
66 | } |
||
67 | } |
||
68 | |||
85 |