| Conditions | 16 |
| Paths | 216 |
| Total Lines | 90 |
| 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 |
||
| 221 | public function getGanttOutput() {
|
||
| 222 | |||
| 223 | $sections = $this->getSections(); |
||
| 224 | $tasks = $this->getTasks(); |
||
| 225 | $sortKey = $this->getSortKey(); |
||
| 226 | |||
| 227 | if ( !empty( $sortKey ) ) {
|
||
| 228 | // Order Sections |
||
| 229 | usort( $sections, [ $this, "sortSections" ] ); |
||
| 230 | usort( $tasks, [ $this, "sortTasks" ] ); |
||
| 231 | |||
| 232 | // reorder TaskArray of current section |
||
| 233 | foreach ( $sections as $section ) {
|
||
| 234 | $orderedTasks = []; |
||
| 235 | foreach ( $tasks as $task ) {
|
||
| 236 | |||
| 237 | // check if $section->getTasks() holds ID of current task |
||
| 238 | if ( in_array( $task->getID(), $section->getTasks() ) ) {
|
||
| 239 | $sectionTasks = $section->getTasks(); |
||
| 240 | //loop through tasks of current section |
||
| 241 | foreach ( $sectionTasks as $taskKey => $sectionTask ) {
|
||
| 242 | if ( $task->getID() == $sectionTask ) {
|
||
| 243 | array_push( $orderedTasks, $sectionTask ); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | } |
||
| 247 | } |
||
| 248 | $section->setTasks( $orderedTasks ); |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | /* |
||
| 253 | * Bring the "section" with no title to the first position. |
||
| 254 | * This "section" is the one that hold tasks without any section. |
||
| 255 | * If we don't display it at the beginning we have to put them into a dummy section |
||
| 256 | */ |
||
| 257 | foreach ( $sections as $key => $section ) {
|
||
| 258 | if ( $section->getTitle() == "" ) {
|
||
| 259 | $noSection = $section; |
||
| 260 | unset( $sections[$key] ); |
||
| 261 | } |
||
| 262 | } |
||
| 263 | // push now the dummy task to the first place of the array |
||
| 264 | if ( isset( $noSection ) ) {
|
||
| 265 | array_unshift( $sections, $noSection ); |
||
| 266 | } |
||
| 267 | |||
| 268 | $title = $this->getTitle(); |
||
| 269 | $axisFormat = $this->getAxisFormat(); |
||
| 270 | |||
| 271 | $mermaidOut = "gantt\n"; |
||
| 272 | $mermaidOut .= "dateFormat YYYY-MM-DD\n"; |
||
| 273 | $mermaidOut .= ( !empty( $title ) ) ? "title $title\n" : ""; |
||
| 274 | $mermaidOut .= "axisFormat $axisFormat\n"; |
||
| 275 | |||
| 276 | // Output section and all related Issues |
||
| 277 | foreach ( $sections as $section ) {
|
||
| 278 | if ( $section->getTitle() != "" ) {
|
||
| 279 | $mermaidOut .= "section " . $section->getTitle() . "\n"; |
||
| 280 | } |
||
| 281 | |||
| 282 | //loop through related section tasks |
||
| 283 | foreach ( $section->getTasks() as $sectionTaskValue ) {
|
||
| 284 | foreach ( $tasks as $taskObj ) {
|
||
| 285 | if ( $taskObj->getID() === $sectionTaskValue ) {
|
||
| 286 | |||
| 287 | $status = $taskObj->getStatus(); |
||
| 288 | |||
| 289 | // Get Date from timestamp |
||
| 290 | $date = date_create(); |
||
| 291 | date_timestamp_set( $date, $taskObj->getStartDate() ); |
||
| 292 | $startDate = date_format( $date, 'Y-m-d' ) . ", "; |
||
| 293 | date_timestamp_set( $date, $taskObj->getEndDate() ); |
||
| 294 | $endDate = date_format( $date, 'Y-m-d' ); |
||
| 295 | |||
| 296 | //get Priority |
||
| 297 | $priority = $taskObj->getPriority(); |
||
| 298 | |||
| 299 | $mermaidOut .= $taskObj->getTitle() . "\t :" . $priority . $status . $startDate . $endDate . |
||
| 300 | "\n"; |
||
| 301 | } |
||
| 302 | } |
||
| 303 | } |
||
| 304 | } |
||
| 305 | |||
| 306 | //Hashtags mark a Comment in Mermaid, so we need to replace it with <esc>35</esc> to replace it again after rendering |
||
| 307 | $mermaidOut = str_replace( "#", "<esc>35</esc>", $mermaidOut ); |
||
| 308 | |||
| 309 | return $mermaidOut; |
||
| 310 | } |
||
| 311 | } |