| Conditions | 9 |
| Paths | 24 |
| Total Lines | 57 |
| Code Lines | 36 |
| 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 |
||
| 30 | public static function processSniff(Application $app, Request $request) |
||
| 31 | { |
||
| 32 | $file = $request->files->get('file'); |
||
| 33 | $git_url = $request->get('git_url'); |
||
| 34 | $options = $request->get('options'); |
||
| 35 | |||
| 36 | $valid_git_url = (is_null($git_url) || !Validator::isGitUrl($git_url)); |
||
| 37 | if ($valid_git_url && is_null($file)) { |
||
| 38 | throw new SnifferReportException('File or Git URL required', 400); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (!is_null($file)) { |
||
| 42 | $file_name = $file->getClientOriginalName(); |
||
| 43 | $file->move(FILES_DIRECTORY_ROOT, $file_name); |
||
| 44 | $files = FilesHandler::handle($file_name, $file->getClientMimeType()); |
||
| 45 | } else { |
||
| 46 | try { |
||
| 47 | $files = GitHandler::handle($git_url); |
||
| 48 | } catch (Exception $e) { |
||
| 49 | throw new SnifferReportException("Error when trying to clone git repository: {$e->getMessage()}", 500); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | $options = json_decode($options); |
||
| 54 | |||
| 55 | if (!Validator::areStandardsValid($options->standards)) { |
||
| 56 | throw new SnifferReportException( |
||
| 57 | 'One or more standards are not valid. Please try again with different values', |
||
| 58 | 400 |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!Validator::areExtensionsValid($options->extensions)) { |
||
| 63 | throw new SnifferReportException( |
||
| 64 | 'One or more extensions are not valid. Please try again with different values', |
||
| 65 | 400 |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | $standards = implode(',', $options->standards); |
||
| 70 | $extensions = implode(',', $options->extensions); |
||
| 71 | |||
| 72 | $sniff_result = Sniffer::sniffFiles($files, $standards, $extensions); |
||
| 73 | |||
| 74 | // Delete all files that were generated in this request. |
||
| 75 | $fs = new Filesystem(); |
||
| 76 | $fs->remove(FILES_DIRECTORY_ROOT); |
||
| 77 | |||
| 78 | try { |
||
| 79 | $sniffParser = new SniffParser($app['pdo']); |
||
| 80 | $response = $sniffParser->parseSniff($sniff_result); |
||
| 81 | } catch (\PDOException $e) { |
||
| 82 | throw new SnifferReportException("Error when trying to save sniff: {$e->getMessage()}", 500); |
||
| 83 | } |
||
| 84 | |||
| 85 | return $response; |
||
| 86 | } |
||
| 87 | } |
||
| 88 |