| Conditions | 11 | 
| Paths | 30 | 
| Total Lines | 56 | 
| Code 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 | ||
| 52 | private function permute(array $charset, $length = null) | ||
| 53 |     { | ||
| 54 | $n = count($charset); | ||
| 55 | |||
| 56 |         if (null === $length) { | ||
| 57 | $length = $n; | ||
| 58 | } | ||
| 59 | |||
| 60 |         if ($length > $n) { | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | $indices = range(0, $n - 1); | ||
| 65 | $cycles = range($n, $n - $length + 1, -1); | ||
| 66 | |||
| 67 | yield array_slice($charset, 0, $length); | ||
| 68 | |||
| 69 |         if ($n <= 0) { | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | |||
| 73 |         while (true) { | ||
| 74 | $exitEarly = false; | ||
| 75 |             for ($i = $length; $i--;) { | ||
| 76 | $cycles[$i]-= 1; | ||
| 77 |                 if ($cycles[$i] == 0) { | ||
| 78 |                     if ($i < count($indices)) { | ||
| 79 | $removed = array_splice($indices, $i, 1); | ||
| 80 | $indices[] = $removed[0]; | ||
| 81 | } | ||
| 82 | $cycles[$i] = $n - $i; | ||
| 83 |                 } else { | ||
| 84 | $j = $cycles[$i]; | ||
| 85 | $value = $indices[$i]; | ||
| 86 | $negative = $indices[count($indices) - $j]; | ||
| 87 | $indices[$i] = $negative; | ||
| 88 | $indices[count($indices) - $j] = $value; | ||
| 89 | $result = []; | ||
| 90 | $counter = 0; | ||
| 91 |                     foreach ($indices as $index) { | ||
| 92 | $result[] = $charset[$index]; | ||
| 93 | $counter++; | ||
| 94 |                         if ($counter == $length) { | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | yield $result; | ||
| 99 | $exitEarly = true; | ||
| 100 | break; | ||
| 101 | } | ||
| 102 | } | ||
| 103 |             if (!$exitEarly) { | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 136 | 
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.