| Conditions | 10 |
| Paths | 15 |
| Total Lines | 46 |
| 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 |
||
| 33 | * @return mixed |
||
| 34 | */ |
||
| 35 | public static function resolveAlias(string $context, string $alias) |
||
| 36 | { |
||
| 37 | return self::$aliases[$context][$alias] ?? $alias; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Allows to convert options array to html string |
||
| 42 | * @param array $htmlOptions |
||
| 43 | * @param array $context - context is variables, which are allowed to use when property value calculated dynamically |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public static function htmlOptionsToString(array $htmlOptions, array $context = []) : string |
||
| 47 | { |
||
| 48 | if (empty($htmlOptions)) { |
||
| 49 | return ''; |
||
| 50 | } |
||
| 51 | |||
| 52 | $out = []; |
||
| 53 | |||
| 54 | foreach ($htmlOptions as $k => $v) { |
||
| 55 | |||
| 56 | if ($v instanceof \Closure) { |
||
| 57 | $v = call_user_func_array($v, $context); |
||
| 58 | } |
||
| 59 | |||
| 60 | $out[] = htmlentities($k) . '="' . htmlentities($v, ENT_COMPAT) . '"'; |
||
| 61 | } |
||
| 62 | |||
| 63 | return implode(' ', $out); |
||
| 64 | } |
||
| 65 | } |