Conditions | 22 |
Paths | 4352 |
Total Lines | 63 |
Code Lines | 39 |
Lines | 0 |
Ratio | 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 |
||
51 | public function run() { |
||
52 | $isPost = $_SERVER["REQUEST_METHOD"] == 'POST'; |
||
53 | $src = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET; |
||
54 | if ($isPost && !$src && $rawPostData = @file_get_contents('php://input')) { |
||
55 | // for support IE XDomainRequest() |
||
56 | $parts = explode('&', $rawPostData); |
||
57 | foreach($parts as $part) { |
||
58 | list($key, $value) = array_pad(explode('=', $part), 2, ''); |
||
59 | $key = rawurldecode($key); |
||
60 | if (substr($key, -2) === '[]') { |
||
61 | $key = substr($key, 0, strlen($key) - 2); |
||
62 | if (!isset($src[$key])) { |
||
63 | $src[$key] = array(); |
||
64 | } |
||
65 | $src[$key][] = rawurldecode($value); |
||
66 | } else { |
||
67 | $src[$key] = rawurldecode($value); |
||
68 | } |
||
69 | } |
||
70 | $_POST = $this->input_filter($src); |
||
71 | $_REQUEST = $this->input_filter(array_merge_recursive($src, $_REQUEST)); |
||
72 | } |
||
73 | $cmd = isset($src['cmd']) ? $src['cmd'] : ''; |
||
74 | $args = array(); |
||
75 | |||
76 | if (!function_exists('json_encode')) { |
||
77 | $error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON); |
||
78 | $this->output(array('error' => '{"error":["'.implode('","', $error).'"]}', 'raw' => true)); |
||
79 | } |
||
80 | |||
81 | if (!$this->elFinder->loaded()) { |
||
82 | $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors)); |
||
83 | } |
||
84 | |||
85 | // telepat_mode: on |
||
86 | if (!$cmd && $isPost) { |
||
87 | $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html')); |
||
88 | } |
||
89 | // telepat_mode: off |
||
90 | |||
91 | if (!$this->elFinder->commandExists($cmd)) { |
||
92 | $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD))); |
||
93 | } |
||
94 | |||
95 | // collect required arguments to exec command |
||
96 | foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) { |
||
97 | $arg = $name == 'FILES' |
||
98 | ? $_FILES |
||
99 | : (isset($src[$name]) ? $src[$name] : ''); |
||
100 | |||
101 | if (!is_array($arg)) { |
||
102 | $arg = trim($arg); |
||
103 | } |
||
104 | if ($req && (!isset($arg) || $arg === '')) { |
||
105 | $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd))); |
||
106 | } |
||
107 | $args[$name] = $arg; |
||
108 | } |
||
109 | |||
110 | $args['debug'] = isset($src['debug']) ? !!$src['debug'] : false; |
||
111 | |||
112 | $this->output($this->elFinder->exec($cmd, $this->input_filter($args))); |
||
113 | } |
||
114 | |||
226 |
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.