Conditions | 11 |
Paths | 4 |
Total Lines | 29 |
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 |
||
35 | protected function findClosestUriToToken( $token, array $targets) |
||
36 | { |
||
37 | $tokenLength=strlen($token); |
||
38 | $absSensitivity= round($tokenLength * $this->sensitivity); |
||
39 | $minLength=max( 1, $tokenLength - $absSensitivity); |
||
40 | $maxLength=$tokenLength + $absSensitivity; |
||
41 | $closestTarget = null; |
||
42 | $shortest = -1; |
||
43 | foreach($targets as $targetUri=>$targetTokens){ |
||
44 | if( $shortest === 0 ) break; // a perfect match found. |
||
45 | foreach ($targetTokens as $targetToken ){ |
||
46 | $targetTokenLength=strlen($targetToken); |
||
47 | if( ($targetTokenLength >= $minLength) && ($targetTokenLength <= $maxLength)) { |
||
48 | $lev = levenshtein($token, $targetToken); |
||
49 | if ($lev <= $shortest || $shortest < 0) { |
||
50 | $closestTarget = $targetUri; |
||
51 | $shortest = $lev; |
||
52 | } |
||
53 | if( $shortest === 0 ) break; // a perfect match found. |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | if( $closestTarget && ($shortest <= $absSensitivity) ){ |
||
59 | return $closestTarget; |
||
60 | } else { |
||
61 | return false; |
||
62 | } |
||
63 | } |
||
64 | |||
105 | } |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.