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