| Conditions | 15 |
| Paths | 648 |
| Total Lines | 86 |
| 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 |
||
| 165 | public function getGanttOutput() {
|
||
| 166 | |||
| 167 | $sections = $this->getSections(); |
||
| 168 | $tasks = $this->getTasks(); |
||
| 169 | |||
| 170 | // Sort Sections |
||
| 171 | usort( $sections, [ $this, 'sortSections' ] ); |
||
| 172 | |||
| 173 | // reorder TaskArray of current section |
||
| 174 | foreach ( $sections as $section ) {
|
||
| 175 | $orderedTasks = []; |
||
| 176 | foreach ( $tasks as $task ) {
|
||
| 177 | |||
| 178 | // check if $section->getTasks() holds ID of current task |
||
| 179 | if ( in_array( $task->getID(), $section->getTasks() ) ) {
|
||
| 180 | $sectionTasks = $section->getTasks(); |
||
| 181 | //loop through tasks of current section |
||
| 182 | foreach ( $sectionTasks as $taskKey => $sectionTask ) {
|
||
| 183 | if ( $task->getID() === $sectionTask ) {
|
||
| 184 | $orderedTasks[] = $sectionTask; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | $section->setTasks( $orderedTasks ); |
||
| 190 | } |
||
| 191 | |||
| 192 | /* |
||
| 193 | * Bring the "section" with no title to the first position. |
||
| 194 | * This "section" is the one that hold tasks without any section. |
||
| 195 | * If we don't display it at the beginning we have to put them into a dummy section |
||
| 196 | */ |
||
| 197 | foreach ( $sections as $key => $section ) {
|
||
| 198 | if ( $section->getTitle() === '' ) {
|
||
| 199 | $noSection = $section; |
||
| 200 | unset( $sections[$key] ); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | // push now the dummy task to the first place of the array |
||
| 204 | if ( isset( $noSection ) ) {
|
||
| 205 | array_unshift( $sections, $noSection ); |
||
| 206 | } |
||
| 207 | |||
| 208 | $title = $this->getTitle(); |
||
| 209 | $axisFormat = $this->getAxisFormat(); |
||
| 210 | |||
| 211 | $mermaidOut = "gantt\n"; |
||
| 212 | $mermaidOut .= "dateFormat YYYY-MM-DD\n"; |
||
| 213 | $mermaidOut .= ( !empty( $title ) ) ? "title $title\n" : ''; |
||
| 214 | $mermaidOut .= "axisFormat $axisFormat\n"; |
||
| 215 | |||
| 216 | // Output section and all related Issues |
||
| 217 | foreach ( $sections as $section ) {
|
||
| 218 | if ( $section->getTitle() !== "" ) {
|
||
| 219 | $mermaidOut .= 'section ' . $section->getTitle() . "\n"; |
||
| 220 | } |
||
| 221 | |||
| 222 | //loop through related section tasks |
||
| 223 | foreach ( $section->getTasks() as $sectionTaskValue ) {
|
||
| 224 | foreach ( $tasks as $taskObj ) {
|
||
| 225 | if ( $taskObj->getID() === $sectionTaskValue ) {
|
||
| 226 | |||
| 227 | $status = $taskObj->getStatus(); |
||
| 228 | |||
| 229 | // Get Date from timestamp |
||
| 230 | $date = date_create(); |
||
| 231 | date_timestamp_set( $date, $taskObj->getStartDate() ); |
||
| 232 | $startDate = date_format( $date, 'Y-m-d' ) . ', '; |
||
| 233 | date_timestamp_set( $date, $taskObj->getEndDate() ); |
||
| 234 | $endDate = date_format( $date, 'Y-m-d' ); |
||
| 235 | |||
| 236 | //get Priority |
||
| 237 | $priority = $taskObj->getPriority(); |
||
| 238 | |||
| 239 | $mermaidOut .= $taskObj->getTitle() . "\t :" . $priority . $status . $startDate . $endDate . |
||
| 240 | "\n"; |
||
| 241 | } |
||
| 242 | } |
||
| 243 | } |
||
| 244 | } |
||
| 245 | |||
| 246 | //Hashtags mark a Comment in Mermaid, so we need to replace it with <esc>35</esc> to replace it again after rendering |
||
| 247 | $mermaidOut = str_replace( '#', '<esc>35</esc>', $mermaidOut ); |
||
| 248 | |||
| 249 | return $mermaidOut; |
||
| 250 | } |
||
| 251 | } |