| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 91 |
| Code Lines | 57 |
| 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 |
||
| 68 | public function run() |
||
| 69 | { |
||
| 70 | $isPost = $this->reqMethod === 'POST'; |
||
| 71 | $src = $isPost ? $_POST : $_GET; |
||
| 72 | $maxInputVars = (! $src || isset($src['targets'])) ? ini_get('max_input_vars') : null; |
||
| 73 | if ((! $src || $maxInputVars) && $rawPostData = file_get_contents('php://input')) { |
||
| 74 | // for max_input_vars and supports IE XDomainRequest() |
||
| 75 | $parts = explode('&', $rawPostData); |
||
| 76 | if (! $src || $maxInputVars < count($parts)) { |
||
| 77 | $src = []; |
||
| 78 | foreach ($parts as $part) { |
||
| 79 | list($key, $value) = array_pad(explode('=', $part), 2, ''); |
||
| 80 | $key = rawurldecode($key); |
||
| 81 | if (preg_match('/^(.+?)\[([^\[\]]*)\]$/', $key, $m)) { |
||
| 82 | $key = $m[1]; |
||
| 83 | $idx = $m[2]; |
||
| 84 | if (! isset($src[$key])) { |
||
| 85 | $src[$key] = []; |
||
| 86 | } |
||
| 87 | if ($idx) { |
||
| 88 | $src[$key][$idx] = rawurldecode($value); |
||
| 89 | } else { |
||
| 90 | $src[$key][] = rawurldecode($value); |
||
| 91 | } |
||
| 92 | } else { |
||
| 93 | $src[$key] = rawurldecode($value); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | $_POST = $this->input_filter($src); |
||
| 97 | $_REQUEST = $this->input_filter(array_merge_recursive($src, $_REQUEST)); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if (isset($src['targets']) && $this->elFinder->maxTargets && count($src['targets']) > $this->elFinder->maxTargets) { |
||
| 102 | $error = $this->elFinder->error(elFinder::ERROR_MAX_TARGTES); |
||
| 103 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_MAX_TARGTES)]); |
||
| 104 | } |
||
| 105 | |||
| 106 | $cmd = isset($src['cmd']) ? $src['cmd'] : ''; |
||
| 107 | $args = []; |
||
| 108 | |||
| 109 | if (! function_exists('json_encode')) { |
||
| 110 | $error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON); |
||
| 111 | $this->output(['error' => '{"error":["'.implode('","', $error).'"]}', 'raw' => true]); |
||
| 112 | } |
||
| 113 | |||
| 114 | if (! $this->elFinder->loaded()) { |
||
| 115 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors]); |
||
| 116 | } |
||
| 117 | |||
| 118 | // telepat_mode: on |
||
| 119 | if (! $cmd && $isPost) { |
||
| 120 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html']); |
||
| 121 | } |
||
| 122 | // telepat_mode: off |
||
| 123 | |||
| 124 | if (! $this->elFinder->commandExists($cmd)) { |
||
| 125 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)]); |
||
| 126 | } |
||
| 127 | |||
| 128 | // collect required arguments to exec command |
||
| 129 | $hasFiles = false; |
||
| 130 | foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) { |
||
| 131 | if ($name === 'FILES') { |
||
| 132 | if (isset($_FILES)) { |
||
| 133 | $hasFiles = true; |
||
| 134 | } elseif ($req) { |
||
| 135 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)]); |
||
| 136 | } |
||
| 137 | } else { |
||
| 138 | $arg = isset($src[$name]) ? $src[$name] : ''; |
||
| 139 | |||
| 140 | if (! is_array($arg) && $req !== '') { |
||
| 141 | $arg = trim($arg); |
||
| 142 | } |
||
| 143 | if ($req && $arg === '') { |
||
| 144 | $this->output(['error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)]); |
||
| 145 | } |
||
| 146 | $args[$name] = $arg; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | $args['debug'] = isset($src['debug']) ? (bool) $src['debug'] : false; |
||
| 151 | |||
| 152 | $args = $this->input_filter($args); |
||
| 153 | if ($hasFiles) { |
||
| 154 | $args['FILES'] = $_FILES; |
||
| 155 | } |
||
| 156 | |||
| 157 | $this->output($this->elFinder->exec($cmd, $args)); |
||
| 158 | } |
||
| 159 | |||
| 335 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.