| Conditions | 1 |
| Paths | 1 |
| Total Lines | 124 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 37 | public function characterProvider() { |
||
| 38 | |||
| 39 | $provider[] = array( |
||
|
|
|||
| 40 | 'Foo', |
||
| 41 | 'unknownFlag', |
||
| 42 | 'Foo', |
||
| 43 | ); |
||
| 44 | |||
| 45 | $provider[] = array( |
||
| 46 | 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž', |
||
| 47 | Transliterator::NONE, |
||
| 48 | 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž', |
||
| 49 | ); |
||
| 50 | |||
| 51 | $provider[] = array( |
||
| 52 | 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž', |
||
| 53 | Transliterator::DIACRITICS, |
||
| 54 | 'AAAAAEAaaaaaeaOOOOOOEOoooooeoEEEEeeeeðCcÐIIIIiiiiUUUUEuuuueNnSsYyyZz' |
||
| 55 | ); |
||
| 56 | |||
| 57 | $provider[] = array( |
||
| 58 | 'ỆᶍǍᶆṔƚÉ áéíóúýčďěňřšťžů', |
||
| 59 | Transliterator::DIACRITICS, |
||
| 60 | 'ExAmPlE aeiouycdenrstzu' |
||
| 61 | ); |
||
| 62 | |||
| 63 | $provider[] = array( |
||
| 64 | 'àáâãäå', |
||
| 65 | Transliterator::DIACRITICS, |
||
| 66 | 'aaaaaea' |
||
| 67 | ); |
||
| 68 | |||
| 69 | $provider[] = array( |
||
| 70 | 'èéêë', |
||
| 71 | Transliterator::DIACRITICS, |
||
| 72 | 'eeee' |
||
| 73 | ); |
||
| 74 | |||
| 75 | $provider[] = array( |
||
| 76 | 'òóôõö', |
||
| 77 | Transliterator::DIACRITICS, |
||
| 78 | 'oooooe' |
||
| 79 | ); |
||
| 80 | |||
| 81 | $provider[] = array( |
||
| 82 | 'ùúûü', |
||
| 83 | Transliterator::DIACRITICS, |
||
| 84 | 'uuuue' |
||
| 85 | ); |
||
| 86 | |||
| 87 | $provider[] = array( |
||
| 88 | 'ç', |
||
| 89 | Transliterator::DIACRITICS, |
||
| 90 | 'c' |
||
| 91 | ); |
||
| 92 | |||
| 93 | $provider[] = array( |
||
| 94 | 'æ', |
||
| 95 | Transliterator::DIACRITICS, |
||
| 96 | 'ae' |
||
| 97 | ); |
||
| 98 | |||
| 99 | $provider[] = array( |
||
| 100 | 'ñ', |
||
| 101 | Transliterator::DIACRITICS, |
||
| 102 | 'n' |
||
| 103 | ); |
||
| 104 | |||
| 105 | $provider[] = array( |
||
| 106 | 'œ', |
||
| 107 | Transliterator::DIACRITICS, |
||
| 108 | 'oe' |
||
| 109 | ); |
||
| 110 | |||
| 111 | $provider[] = array( |
||
| 112 | 'ýÿ', |
||
| 113 | Transliterator::DIACRITICS, |
||
| 114 | 'yy' |
||
| 115 | ); |
||
| 116 | |||
| 117 | $provider[] = array( |
||
| 118 | 'ß', |
||
| 119 | Transliterator::DIACRITICS, |
||
| 120 | 'ss' |
||
| 121 | ); |
||
| 122 | |||
| 123 | $provider[] = array( |
||
| 124 | 'Vilʹândimaa', |
||
| 125 | Transliterator::DIACRITICS, |
||
| 126 | 'Vilʹandimaa' |
||
| 127 | ); |
||
| 128 | |||
| 129 | $provider[] = array( |
||
| 130 | 'Ελληνική Δημοκρατία', |
||
| 131 | Transliterator::GREEK, |
||
| 132 | 'Ellīnikī́ Dīmokratía' |
||
| 133 | ); |
||
| 134 | |||
| 135 | $provider[] = array( |
||
| 136 | 'Ελληνική Δημοκρατία', |
||
| 137 | Transliterator::DIACRITICS | Transliterator::GREEK, |
||
| 138 | 'Ellinikí Dimokratia' |
||
| 139 | ); |
||
| 140 | |||
| 141 | $provider[] = array( |
||
| 142 | 'Γκ γκ γξ Ει ει Ηυ Μπ μπ', |
||
| 143 | Transliterator::GREEK, |
||
| 144 | 'Gk gk gx Ei ei Īy Mp mp' |
||
| 145 | ); |
||
| 146 | |||
| 147 | $provider[] = array( |
||
| 148 | 'Μετατροπή του ελληνικού αλφαβήτου με λατινικούς χαρακτήρες', |
||
| 149 | Transliterator::GREEK, |
||
| 150 | 'Metatropī́ tou ellīnikoú alfavī́tou me latinikoús charaktī́res', |
||
| 151 | ); |
||
| 152 | |||
| 153 | $provider[] = array( |
||
| 154 | 'Ελληνικός Οργανισμός Τυποποίησης', |
||
| 155 | Transliterator::GREEK, |
||
| 156 | 'Ellīnikós Organismós Typopoíīsīs', |
||
| 157 | ); |
||
| 158 | |||
| 159 | return $provider; |
||
| 160 | } |
||
| 161 | |||
| 163 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.