| Conditions | 6 |
| Paths | 13 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 119 | public static function detect(string $subjectString) : ?ConvertHelper_EOL |
||
| 120 | { |
||
| 121 | if(empty($subjectString)) { |
||
| 122 | return null; |
||
| 123 | } |
||
| 124 | |||
| 125 | if(!isset(self::$eolChars)) |
||
| 126 | { |
||
| 127 | $cr = chr((int)hexdec('0d')); |
||
| 128 | $lf = chr((int)hexdec('0a')); |
||
| 129 | |||
| 130 | self::$eolChars = array( |
||
| 131 | array( |
||
| 132 | 'char' => $cr.$lf, |
||
| 133 | 'type' => ConvertHelper_EOL::TYPE_CRLF, |
||
| 134 | 'description' => t('Carriage return followed by a line feed'), |
||
| 135 | ), |
||
| 136 | array( |
||
| 137 | 'char' => $lf.$cr, |
||
| 138 | 'type' => ConvertHelper_EOL::TYPE_LFCR, |
||
| 139 | 'description' => t('Line feed followed by a carriage return'), |
||
| 140 | ), |
||
| 141 | array( |
||
| 142 | 'char' => $lf, |
||
| 143 | 'type' => ConvertHelper_EOL::TYPE_LF, |
||
| 144 | 'description' => t('Line feed'), |
||
| 145 | ), |
||
| 146 | array( |
||
| 147 | 'char' => $cr, |
||
| 148 | 'type' => ConvertHelper_EOL::TYPE_CR, |
||
| 149 | 'description' => t('Carriage Return'), |
||
| 150 | ), |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 154 | $max = 0; |
||
| 155 | $results = array(); |
||
| 156 | foreach(self::$eolChars as $def) |
||
| 157 | { |
||
| 158 | $amount = substr_count($subjectString, $def['char']); |
||
| 159 | |||
| 160 | if($amount > $max) |
||
| 161 | { |
||
| 162 | $max = $amount; |
||
| 163 | $results[] = $def; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | if(empty($results)) { |
||
| 168 | return null; |
||
| 169 | } |
||
| 170 | |||
| 171 | return new ConvertHelper_EOL( |
||
| 172 | $results[0]['char'], |
||
| 173 | $results[0]['type'], |
||
| 174 | $results[0]['description'] |
||
| 175 | ); |
||
| 178 |