| Conditions | 5 | 
| Total Lines | 53 | 
| Code Lines | 45 | 
| 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 | import * as chalk from "chalk"; | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Handle given input | ||
| 186 | */ | ||
| 187 |     private handleInput(input) { | ||
| 188 |         input = input.split(" "); | ||
| 189 | let cmd = input[0]; | ||
| 190 | let arg1 = input[1]; | ||
| 191 |         switch (cmd) { | ||
| 192 | case "help": | ||
| 193 | let helpText = ""; | ||
| 194 |                 helpText += this.getHelp("pause", "Stops observing file changes"); | ||
| 195 |                 helpText += this.getHelp("resume", "Continue checking files"); | ||
| 196 |                 helpText += this.getHelp("resume -u", "Continue checking files and upload all the changed files while paused."); | ||
| 197 |                 helpText += this.getHelp("help", "Displays this text"); | ||
| 198 |                 helpText += this.getHelp("clear", "Clears the screen"); | ||
| 199 |                 helpText += this.getHelp("exit", "Exits the script"); | ||
| 200 | this.write(helpText); | ||
| 201 | break; | ||
| 202 | case "clear": | ||
| 203 | this.workspace(); | ||
| 204 | break; | ||
| 205 | case "exit": | ||
| 206 | process.exit(EXIT_CODE.NORMAL); | ||
| 207 | break; | ||
| 208 | case "pause": | ||
| 209 | this.paused = true; | ||
| 210 |                 this.pauseEvents.map((ev) => { | ||
| 211 | ev(this.paused); | ||
| 212 | }); | ||
| 213 | this.workspace(); | ||
| 214 | break; | ||
| 215 | case "resume": | ||
| 216 |                 if (this.paused) { | ||
| 217 |                     if (arg1 != "-u") { | ||
| 218 | this.lastRun = +(new Date()); | ||
| 219 | this.timeDiff = 0; | ||
| 220 | } | ||
| 221 | this.paused = false; | ||
| 222 | this.workspace(); | ||
| 223 |                     if (arg1 == "-u") { | ||
| 224 |                         this.write("Finding all changed files while waiting.\n"); | ||
| 225 | } | ||
| 226 |                     this.pauseEvents.map((ev) => { | ||
| 227 | ev(this.paused); | ||
| 228 | }); | ||
| 229 |                 } else { | ||
| 230 |                     this.write("Already running\n"); | ||
| 231 | } | ||
| 232 | break; | ||
| 233 | case "": break; | ||
| 234 | default: | ||
| 235 |                 this.write(chalk.red(`Unknown command: ${cmd}\nType "help" to see commands`)); | ||
| 236 | } | ||
| 240 |