| Conditions | 13 |
| Paths | 288 |
| Total Lines | 58 |
| 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 |
||
| 95 | public function execute() |
||
| 96 | { |
||
| 97 | $directory = ''; |
||
| 98 | if (!empty($this->directory)) { |
||
| 99 | $directory = $this->directory; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (!$this->config) { |
||
| 103 | foreach ($this->configs as $config) { |
||
| 104 | if (file_exists($this->builder->buildPath . $config)) { |
||
| 105 | $this->config = true; |
||
| 106 | $this->args .= ' --config=./' . $config; |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | if (!$this->config && !$directory) { |
||
| 113 | $directory = '.'; |
||
| 114 | } |
||
| 115 | |||
| 116 | $phpCsFixer = $this->executable; |
||
| 117 | |||
| 118 | // Determine the version of PHP CS Fixer |
||
| 119 | $cmd = $phpCsFixer . ' --version'; |
||
| 120 | $success = $this->builder->executeCommand($cmd); |
||
|
|
|||
| 121 | $output = $this->builder->getLastOutput(); |
||
| 122 | $matches = []; |
||
| 123 | if (preg_match('/(\d+\.\d+\.\d+)/', $output, $matches)) { |
||
| 124 | $version = $matches[1]; |
||
| 125 | // Appeared in PHP CS Fixer 2.8.0 |
||
| 126 | // https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.12/CHANGELOG.md#changelog-for-v280 |
||
| 127 | $this->supportsUdiff = version_compare($version, '2.8.0', '>='); |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($this->errors) { |
||
| 131 | $this->args .= ' --verbose --format json --diff'; |
||
| 132 | if ($this->supportsUdiff) { |
||
| 133 | $this->args .= ' --diff-format udiff'; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $cmd = $phpCsFixer . ' fix ' . $directory . ' %s'; |
||
| 138 | $success = $this->builder->executeCommand($cmd, $this->args); |
||
| 139 | $output = $this->builder->getLastOutput(); |
||
| 140 | |||
| 141 | if ($this->errors) { |
||
| 142 | $warningCount = $this->processReport($output); |
||
| 143 | |||
| 144 | $this->build->storeMeta((self::pluginName() . '-warnings'), $warningCount); |
||
| 145 | |||
| 146 | if (-1 != $this->allowedWarnings && $warningCount > $this->allowedWarnings) { |
||
| 147 | $success = false; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | return $success; |
||
| 152 | } |
||
| 153 | |||
| 248 |
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.