Conditions | 3 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
34 | public function fileUpload(): Response |
||
35 | { |
||
36 | $actualClientId = explode(' ', $this->request->getHeaders()->get('authorization'))[1]; |
||
37 | |||
38 | $expectedClientId = Environment::getVar(FrameworkEnv::CRYPTO_CLIENT_ID); |
||
39 | if ($actualClientId != $expectedClientId) { |
||
40 | $response = new JsonResponse( |
||
41 | [ |
||
42 | 'success' => false, |
||
43 | 'status' => ResponseHeaders::HTTP_FORBIDDEN, |
||
44 | ], |
||
45 | ResponseHeaders::HTTP_FORBIDDEN |
||
46 | ); |
||
47 | $response->send(); |
||
48 | |||
49 | return $response; |
||
50 | } |
||
51 | |||
52 | $image = $this->request->getFiles()->get('image'); |
||
53 | if ($image->hasErrors()) { |
||
54 | $response = new JsonResponse( |
||
55 | [ |
||
56 | 'success' => false, |
||
57 | 'status' => ResponseHeaders::HTTP_INTERNAL_SERVER_ERROR, |
||
58 | ], |
||
59 | ResponseHeaders::HTTP_INTERNAL_SERVER_ERROR |
||
60 | ); |
||
61 | $response->send(); |
||
62 | |||
63 | return $response; |
||
64 | } |
||
65 | |||
66 | $basePath = mb_substr(basename($image->getPathname()), 3); |
||
67 | $extension = pathinfo($image->getTempFilename())['extension']; |
||
68 | $filename = sprintf('%s.%s', $basePath, $extension); |
||
69 | |||
70 | $path = sprintf('%s/editor-file-upload', Environment::getVar(FrameworkEnv::DIR_PUBLIC)); |
||
71 | $url = Environment::getVar(WebsiteEnv::WEBSITE_BASE_URL) . 'editor-file-upload/' . $filename; |
||
72 | |||
73 | $image->move($path, $filename); |
||
74 | |||
75 | $response = new JsonResponse( |
||
76 | [ |
||
77 | 'data' => ['url' => $url], |
||
78 | 'success' => true, |
||
79 | 'status' => ResponseHeaders::HTTP_OK, |
||
80 | ], |
||
81 | ResponseHeaders::HTTP_OK |
||
82 | ); |
||
83 | $response->send(); |
||
84 | |||
85 | return $response; |
||
86 | } |
||
88 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths