| Conditions | 8 |
| Paths | 40 |
| Total Lines | 55 |
| 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 |
||
| 75 | public function handle() |
||
| 76 | { |
||
| 77 | // Define custom format for bold text |
||
| 78 | $style = new OutputFormatterStyle('default', 'default', array('bold')); |
||
| 79 | $this->output->getFormatter()->setStyle('bold', $style); |
||
| 80 | |||
| 81 | // Get the verbosity level to set debug mode flag |
||
| 82 | $verbosityLevel = $this->getOutput()->getVerbosity(); |
||
| 83 | if ($verbosityLevel > OutputInterface::VERBOSITY_DEBUG) { |
||
| 84 | $this->debug = true; |
||
| 85 | } |
||
| 86 | |||
| 87 | // Get XDebug desired status from the command line arguments |
||
| 88 | $desiredStatus = $this->argument("status"); |
||
| 89 | |||
| 90 | if ($this->debug) { |
||
| 91 | echo "Desired Status: $desiredStatus\n"; |
||
| 92 | } |
||
| 93 | |||
| 94 | // validate desired XDebug status |
||
| 95 | if (!in_array($desiredStatus, ["on", "off"])) { |
||
| 96 | $this->line("Status should be \"on\" or \"off\". Other values are not accepted.", "fg=red;bold"); |
||
| 97 | return false; |
||
| 98 | } |
||
| 99 | |||
| 100 | // Retrieve the INI path to the global variable |
||
| 101 | $this->getIniPath(); |
||
| 102 | |||
| 103 | // If we can't retrieve the loaded INI path, bail out |
||
| 104 | if ($this->iniPath == false) { |
||
|
|
|||
| 105 | $this->line("Can't get php.ini file path from phpinfo() output. |
||
| 106 | Make sure that the function is allowed inside your php.ini configuration.", "bold"); |
||
| 107 | return false; |
||
| 108 | } |
||
| 109 | |||
| 110 | // Get the XDebug extension information from the INI file |
||
| 111 | $this->getXDebugStatus(); |
||
| 112 | |||
| 113 | // prepare variables for comparison and output |
||
| 114 | $currentStatus = $this->extensionStatus ? "on" : "off"; |
||
| 115 | $styledStatus = $this->extensionStatus ? "<fg=green;bold>on" : "<fg=red;bold>off"; |
||
| 116 | |||
| 117 | // print current status to the user |
||
| 118 | $this->line("<fg=yellow>Current XDebug Status: $styledStatus</>"); |
||
| 119 | |||
| 120 | // if the desired status and current status are the same, we don't need to alter anything |
||
| 121 | // inform the user and exit |
||
| 122 | if ($currentStatus === $desiredStatus) { |
||
| 123 | $this->line("<fg=green>Already at the desired state. No action has been taken.</>"); |
||
| 124 | return false; |
||
| 125 | } |
||
| 126 | |||
| 127 | // we need to alter the status to the new one. Do it! |
||
| 128 | $this->setXDebugStatus($desiredStatus); |
||
| 129 | } |
||
| 130 | |||
| 262 |