| Conditions | 24 |
| Paths | 87 |
| Total Lines | 109 |
| 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 |
||
| 169 | protected function getResultText( SMWQueryResult $queryResult, $outputmode ) {
|
||
| 170 | |||
| 171 | // Show warning if Extension:Mermaid is not available |
||
| 172 | if ( !class_exists( 'Mermaid' ) && !class_exists( 'Mermaid\\MermaidParserFunction' ) ) {
|
||
| 173 | $queryResult->addErrors( [wfMessage('')->text()] );
|
||
| 174 | return ''; |
||
| 175 | } |
||
| 176 | |||
| 177 | // Load general Modules |
||
| 178 | SMWOutputs::requireResource( 'ext.srf.gantt' ); |
||
| 179 | |||
| 180 | //Add Tasks & Sections |
||
| 181 | while ( $row = $queryResult->getNext() ) {
|
||
| 182 | |||
| 183 | $status = []; |
||
| 184 | $priority = []; |
||
| 185 | $startDate = ''; |
||
| 186 | $endDate = ''; |
||
| 187 | $taskID = ''; |
||
| 188 | $taskTitle = ''; |
||
| 189 | $sections = []; |
||
| 190 | |||
| 191 | // Loop through all field of a row |
||
| 192 | foreach ( $row as $field ) {
|
||
| 193 | |||
| 194 | $fieldLabel = $field->getPrintRequest()->getLabel(); |
||
| 195 | |||
| 196 | //get values |
||
| 197 | foreach ( $field->getContent() as $dataItem ) {
|
||
| 198 | |||
| 199 | switch ( $fieldLabel ) {
|
||
| 200 | case 'section': |
||
| 201 | $sections[$dataItem->getTitle()->getPrefixedDBKey()] = $dataItem->getSortKey(); |
||
| 202 | break; |
||
| 203 | case 'task': |
||
| 204 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 205 | $taskTitle = $dataItem->getString(); |
||
| 206 | $taskID = $field->getResultSubject()->getTitle()->getPrefixedDBKey(); |
||
| 207 | } |
||
| 208 | break; |
||
| 209 | case 'startdate': |
||
| 210 | if ( $dataItem instanceof SMWDITime ) {
|
||
| 211 | $startDate = $dataItem->getMwTimestamp(); |
||
| 212 | } |
||
| 213 | break; |
||
| 214 | case 'enddate': |
||
| 215 | if ( $dataItem instanceof SMWDITime ) {
|
||
| 216 | $endDate = $dataItem->getMwTimestamp(); |
||
| 217 | } |
||
| 218 | break; |
||
| 219 | case 'status': |
||
| 220 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 221 | $status[] = $dataItem->getString(); |
||
| 222 | } |
||
| 223 | break; |
||
| 224 | case 'priority': |
||
| 225 | if ( $dataItem instanceof SMWDIBlob ) {
|
||
| 226 | $priority[] = $dataItem->getString(); |
||
| 227 | } |
||
| 228 | break; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | } |
||
| 232 | |||
| 233 | // Add section/Task |
||
| 234 | // Title, TaskID, StartDate and EndDate are required |
||
| 235 | if ( $taskID !== '' && $taskTitle !== '' && $startDate !== '' && $endDate !== '' ) {
|
||
| 236 | $this->mGantt->addTask( $taskID, $taskTitle, $status, $priority, $startDate, $endDate ); |
||
| 237 | |||
| 238 | // If no section was found, put task into a dummy section object |
||
| 239 | // "gantt-no-section#21780240" is used to identify Tasks that with no section (dummy section) |
||
| 240 | if ( count( $sections ) == 0 ) {
|
||
| 241 | $this->mGantt->addSection( 'gantt-no-section#21780240', '', $startDate, $endDate, $taskID ); |
||
| 242 | } else {
|
||
| 243 | foreach ( $sections as $sectionID => $sectionTitle ) {
|
||
| 244 | $this->mGantt->addSection( $sectionID, $sectionTitle, $startDate, $endDate, $taskID ); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | } |
||
| 248 | } |
||
| 249 | |||
| 250 | // Improve unique id by adding a random number |
||
| 251 | $id = uniqid( 'srf-gantt-' . rand( 1, 10000 ) ); |
||
| 252 | |||
| 253 | // Add gantt configurations |
||
| 254 | $config = [ |
||
| 255 | 'theme' => $this->params['theme'], |
||
| 256 | 'gantt' => [ |
||
| 257 | 'leftPadding' => intval( $this->params['leftpadding'] ), |
||
| 258 | 'titleTopMargin' => intval( $this->params['titletopmargin'] ), |
||
| 259 | 'barHeight' => intval( $this->params['barheight'] ), |
||
| 260 | 'barGap' => intval( $this->params['bargap'] ) |
||
| 261 | ] |
||
| 262 | ]; |
||
| 263 | |||
| 264 | // Manage Output |
||
| 265 | if ( !empty( $this->mErrors ) ) {
|
||
| 266 | return $queryResult->addErrors( $this->mErrors ); |
||
| 267 | } else {
|
||
| 268 | return Html::rawElement( 'div', [ |
||
| 269 | 'id' => $id, |
||
| 270 | 'class' => 'srf-gantt', |
||
| 271 | 'data-mermaid' => json_encode( [ |
||
| 272 | 'content' => $this->mGantt->getGanttOutput(), |
||
| 273 | 'config' => $config |
||
| 274 | ]) |
||
| 275 | ], Html::rawElement( 'div', [ 'class' => 'mermaid-dots' ])); |
||
| 276 | } |
||
| 277 | } |
||
| 278 | |||
| 298 | } |