Conditions | 8 |
Paths | 60 |
Total Lines | 60 |
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 |
||
143 | public function getGanttOutput() { |
||
144 | |||
145 | $sections = $this->getSections(); |
||
146 | $tasks = $this->getTasks(); |
||
147 | |||
148 | /* |
||
149 | * Bring the "section" with no title to the first position. |
||
150 | * This "section" is the one that hold tasks without any section. |
||
151 | * If we don't display it at the beginning we have to put them into a dummy section |
||
152 | */ |
||
153 | foreach ( $sections as $key => $section ) { |
||
154 | if ( $section->getTitle() === '' ) { |
||
155 | $noSection = $section; |
||
156 | unset( $sections[$key] ); |
||
157 | } |
||
158 | } |
||
159 | // push now the dummy task to the first place of the array |
||
160 | if ( isset( $noSection ) ) { |
||
161 | array_unshift( $sections, $noSection ); |
||
162 | } |
||
163 | |||
164 | $title = $this->getTitle(); |
||
165 | $axisFormat = $this->getAxisFormat(); |
||
166 | |||
167 | $mermaidOut = "gantt\n"; |
||
168 | $mermaidOut .= "dateFormat YYYY-MM-DD\n"; |
||
169 | $mermaidOut .= ( !empty( $title ) ) ? "title $title\n" : ''; |
||
170 | $mermaidOut .= "axisFormat $axisFormat\n"; |
||
171 | |||
172 | // Output section and all related Issues |
||
173 | foreach ( $sections as $section ) { |
||
174 | if ( $section->getTitle() !== "" ) { |
||
175 | $mermaidOut .= 'section ' . $section->getTitle() . "\n"; |
||
176 | } |
||
177 | |||
178 | //loop through related section tasks |
||
179 | foreach ( $section->getTasks() as $sectionTask ) { |
||
180 | |||
181 | $status = $tasks[$sectionTask]->getStatus(); |
||
182 | |||
183 | // Get Date from timestamp |
||
184 | $date = date_create(); |
||
185 | date_timestamp_set( $date, $tasks[$sectionTask]->getStartDate() ); |
||
186 | $startDate = date_format( $date, 'Y-m-d' ) . ', '; |
||
187 | date_timestamp_set( $date, $tasks[$sectionTask]->getEndDate() ); |
||
188 | $endDate = date_format( $date, 'Y-m-d' ); |
||
189 | |||
190 | //get Priority |
||
191 | $priority = $tasks[$sectionTask]->getPriority(); |
||
192 | |||
193 | $mermaidOut .= $tasks[$sectionTask]->getTitle() . "\t :" . $priority . $status . $startDate . $endDate . |
||
194 | "\n"; |
||
195 | } |
||
196 | } |
||
197 | |||
198 | //Hashtags mark a Comment in Mermaid, so we need to replace it with <esc>35</esc> to replace it again after rendering |
||
199 | $mermaidOut = str_replace( '#', '<esc>35</esc>', $mermaidOut ); |
||
200 | |||
201 | return $mermaidOut; |
||
202 | } |
||
203 | } |