Conditions | 11 |
Paths | 8 |
Total Lines | 42 |
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 |
||
9 | public function match($pattern, $input) |
||
10 | { |
||
11 | $result = false; |
||
12 | |||
13 | if (!is_array($input) && !is_string($input)) { |
||
14 | return false; |
||
15 | } |
||
16 | |||
17 | if (!is_array($input)) { |
||
18 | if (!$result = preg_match($pattern, $this->applyExceptions($input))) { |
||
19 | return false; |
||
20 | } |
||
21 | |||
22 | return $this->checkContent($result); |
||
23 | } |
||
24 | |||
25 | foreach ($input as $key => $value) { |
||
26 | if (is_array($value)) { |
||
27 | if (!$result = $this->match($pattern, $value)) { |
||
28 | continue; |
||
29 | } |
||
30 | |||
31 | break; |
||
32 | } |
||
33 | |||
34 | if (!$this->isInput($key)) { |
||
35 | continue; |
||
36 | } |
||
37 | |||
38 | if (!$result = preg_match($pattern, $this->applyExceptions($value))) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | if (!$this->checkContent($result)) { |
||
43 | continue; |
||
44 | } |
||
45 | |||
46 | break; |
||
47 | } |
||
48 | |||
49 | return $result; |
||
50 | } |
||
51 | |||
77 |