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