| Conditions | 12 |
| Paths | 28 |
| Total Lines | 89 |
| 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 |
||
| 40 | protected function getGroups() |
||
| 41 | { |
||
| 42 | $groups = array(); |
||
| 43 | $label = 0; |
||
| 44 | |||
| 45 | foreach ($this->element->children() as $element) |
||
| 46 | { |
||
| 47 | switch ($element->getName()) |
||
| 48 | { |
||
| 49 | // The element is an <option /> |
||
| 50 | case 'option': |
||
| 51 | // Initialize the group if necessary. |
||
| 52 | if (!isset($groups[$label])) |
||
| 53 | { |
||
| 54 | $groups[$label] = array(); |
||
| 55 | } |
||
| 56 | |||
| 57 | // Create a new option object based on the <option /> element. |
||
| 58 | $tmp = HtmlSelect::option( |
||
| 59 | ($element['value']) ? (string) $element['value'] : trim((string) $element), |
||
| 60 | Text::alt(trim((string) $element), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text', |
||
| 61 | ((string) $element['disabled'] == 'true') |
||
| 62 | ); |
||
| 63 | |||
| 64 | // Set some option attributes. |
||
| 65 | $tmp->class = (string) $element['class']; |
||
| 66 | |||
| 67 | // Set some JavaScript option attributes. |
||
| 68 | $tmp->onclick = (string) $element['onclick']; |
||
| 69 | |||
| 70 | // Add the option. |
||
| 71 | $groups[$label][] = $tmp; |
||
| 72 | break; |
||
| 73 | |||
| 74 | // The element is a <group /> |
||
| 75 | case 'group': |
||
| 76 | // Get the group label. |
||
| 77 | if ($groupLabel = (string) $element['label']) |
||
| 78 | { |
||
| 79 | $label = Text::_($groupLabel); |
||
| 80 | } |
||
| 81 | |||
| 82 | // Initialize the group if necessary. |
||
| 83 | if (!isset($groups[$label])) |
||
| 84 | { |
||
| 85 | $groups[$label] = array(); |
||
| 86 | } |
||
| 87 | |||
| 88 | // Iterate through the children and build an array of options. |
||
| 89 | foreach ($element->children() as $option) |
||
| 90 | { |
||
| 91 | // Only add <option /> elements. |
||
| 92 | if ($option->getName() != 'option') |
||
| 93 | { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Create a new option object based on the <option /> element. |
||
| 98 | $tmp = HtmlSelect::option( |
||
| 99 | ($option['value']) ? (string) $option['value'] : Text::_(trim((string) $option)), |
||
| 100 | Text::_(trim((string) $option)), 'value', 'text', ((string) $option['disabled'] == 'true') |
||
| 101 | ); |
||
| 102 | |||
| 103 | // Set some option attributes. |
||
| 104 | $tmp->class = (string) $option['class']; |
||
| 105 | |||
| 106 | // Set some JavaScript option attributes. |
||
| 107 | $tmp->onclick = (string) $option['onclick']; |
||
| 108 | |||
| 109 | // Add the option. |
||
| 110 | $groups[$label][] = $tmp; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($groupLabel) |
||
| 114 | { |
||
| 115 | $label = count($groups); |
||
| 116 | } |
||
| 117 | break; |
||
| 118 | |||
| 119 | // Unknown element type. |
||
| 120 | default: |
||
| 121 | throw new UnexpectedValueException(sprintf('Unsupported element %s in JFormFieldGroupedList', $element->getName()), 500); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | reset($groups); |
||
| 126 | |||
| 127 | return $groups; |
||
| 128 | } |
||
| 129 | |||
| 184 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.