| Conditions | 6 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 30 |
| 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 |
||
| 18 | public function addcrypted2Action(Request $request) |
||
| 19 | { |
||
| 20 | $data = array( |
||
| 21 | 'success' => false, |
||
| 22 | 'message' => $this->get('Translator')->trans('TARTANA_CLICKNLOAD_ERROR_ADDING_TO_QUEUE') |
||
| 23 | ); |
||
| 24 | |||
| 25 | preg_match('/\'(.*?)\'/', $request->get('jk'), $matches); |
||
| 26 | |||
| 27 | if (count($matches) < 1) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | $key = hex2bin($matches[1]); |
||
| 32 | |||
| 33 | $cp = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', ''); |
||
| 34 | @mcrypt_generic_init($cp, $key, $key); |
||
|
|
|||
| 35 | $dec = mdecrypt_generic($cp, base64_decode($request->get('crypted'))); |
||
| 36 | mcrypt_generic_deinit($cp); |
||
| 37 | mcrypt_module_close($cp); |
||
| 38 | |||
| 39 | $folder = $this->container->getParameter('tartana.config')['links']['folder']; |
||
| 40 | $folder = Util::realPath($folder); |
||
| 41 | |||
| 42 | if (!empty($folder)) { |
||
| 43 | $fs = new Local($folder); |
||
| 44 | |||
| 45 | $name = $request->get('package', rand(0, 1000)) . '.txt'; |
||
| 46 | |||
| 47 | // Sanitize content |
||
| 48 | $content = ''; |
||
| 49 | foreach (preg_split('/\r\n|\r|\n/', $dec) as $file) { |
||
| 50 | if (strpos($file, 'http://') !== 0) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | |||
| 54 | $content .= $file . PHP_EOL; |
||
| 55 | } |
||
| 56 | |||
| 57 | $content = trim($content); |
||
| 58 | |||
| 59 | if ($content) { |
||
| 60 | $fs->write($name, $content, new Config()); |
||
| 61 | |||
| 62 | $data = array( |
||
| 63 | 'success' => true, |
||
| 64 | 'message' => $this->get('Translator')->trans('TARTANA_CLICKNLOAD_CONTENT_ADDED_TO_QUEUE') |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return new JsonResponse($data); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |
If you suppress an error, we recommend checking for the error condition explicitly: