Conditions | 18 |
Paths | 288 |
Total Lines | 92 |
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 |
||
91 | public function listView($fields = array()) |
||
92 | { |
||
93 | self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])'); |
||
94 | |||
95 | if (method_exists($this, 'before_listView_callback')) { |
||
96 | $this->{'before_listView_callback'}(); |
||
97 | } |
||
98 | |||
99 | // the form action |
||
100 | $fields['formAction'] = $fields['URI']; |
||
101 | |||
102 | // work out how many columns will be in the table |
||
103 | $reflection = new \ReflectionClass(get_class($this->record)); |
||
104 | $properties = array_keys($reflection->getDefaultProperties()); |
||
105 | $fields['colCount'] = 1+count(array_diff($properties, $this->record->getDefaultAttributes(), $this->record->getTransientAttributes())); |
||
106 | |||
107 | // get the class attributes |
||
108 | $properties = $reflection->getProperties(); |
||
109 | |||
110 | $html = ''; |
||
111 | |||
112 | $html .= '<tr>'; |
||
113 | foreach ($properties as $propObj) { |
||
114 | $propName = $propObj->name; |
||
115 | |||
116 | // skip over password fields |
||
117 | $property = $this->record->getPropObject($propName); |
||
118 | if (!($property instanceof SmallText && $property->checkIsPassword())) { |
||
119 | if (!in_array($propName, $this->record->getDefaultAttributes()) && !in_array($propName, $this->record->getTransientAttributes())) { |
||
120 | $html .= ' <th>'.$this->record->getDataLabel($propName).'</th>'; |
||
121 | } |
||
122 | if ($propName == 'ID') { |
||
123 | $html .= ' <th>'.$this->record->getDataLabel($propName).'</th>'; |
||
124 | } |
||
125 | } else { |
||
126 | $fields['colCount'] = $fields['colCount']-1; |
||
127 | } |
||
128 | } |
||
129 | $html .= '</tr><tr>'; |
||
130 | |||
131 | $fields['formHeadings'] = $html; |
||
132 | |||
133 | $html = ''; |
||
134 | |||
135 | // and now the values |
||
136 | foreach ($properties as $propObj) { |
||
137 | $propName = $propObj->name; |
||
138 | |||
139 | $property = $this->record->getPropObject($propName); |
||
140 | if (!($property instanceof SmallText && $property->checkIsPassword())) { |
||
141 | if (!in_array($propName, $this->record->getDefaultAttributes()) && !in_array($propName, $this->record->getTransientAttributes())) { |
||
142 | if ($property instanceof Text) { |
||
143 | $text = htmlentities($this->record->get($propName), ENT_COMPAT, 'utf-8'); |
||
144 | if (mb_strlen($text) > 70) { |
||
145 | $html .= ' <td> '.mb_substr($text, 0, 70).'...</td>'; |
||
146 | } else { |
||
147 | $html .= ' <td> '.$text.'</td>'; |
||
148 | } |
||
149 | } elseif ($property instanceof DEnum) { |
||
150 | $html .= ' <td> '.$property->getDisplayValue().'</td>'; |
||
151 | } else { |
||
152 | $html .= ' <td> '.$property->getValue().'</td>'; |
||
153 | } |
||
154 | } |
||
155 | if ($propName == 'ID') { |
||
156 | $html .= ' <td> '.$this->record->getID().'</td>'; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | $html .= '</tr>'; |
||
161 | |||
162 | $fields['formFields'] = $html; |
||
163 | |||
164 | $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->record).'&oid='.$this->record->getID())."';", 'View', 'viewBut'); |
||
165 | $fields['viewButton'] = $button->render(); |
||
166 | |||
167 | // supressing the edit/delete buttons for Sequences |
||
168 | $fields['adminButtons'] = ''; |
||
169 | |||
170 | // buffer security fields to $formSecurityFields variable |
||
171 | $fields['formSecurityFields'] = $this->renderSecurityFields(); |
||
172 | |||
173 | $html = $this->loadTemplate($this->record, 'list', $fields); |
||
174 | |||
175 | if (method_exists($this, 'after_listView_callback')) { |
||
176 | $this->{'after_listView_callback'}(); |
||
177 | } |
||
178 | |||
179 | self::$logger->debug('<<listView'); |
||
180 | |||
181 | return $html; |
||
182 | } |
||
183 | |||
223 |