| Conditions | 5 |
| Paths | 6 |
| Total Lines | 54 |
| Code Lines | 26 |
| 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 |
||
| 14 | public function __invoke(CDocument $document, Request $request, CDocumentRepository $repo, EntityManagerInterface $em): CDocument |
||
| 15 | { |
||
| 16 | $fileType = $document->getFileType(); |
||
| 17 | $contentData = $request->getContent(); |
||
| 18 | error_log('__invoke'); |
||
| 19 | |||
| 20 | if (!empty($contentData)) { |
||
| 21 | $contentData = json_decode($contentData, true); |
||
| 22 | $title = $contentData['title']; |
||
| 23 | $content = $contentData['contentFile']; |
||
| 24 | $comment = $contentData['comment']; |
||
| 25 | } else { |
||
| 26 | $title = $request->get('title'); |
||
| 27 | $content = $request->request->get('contentFile'); |
||
| 28 | $comment = $request->request->get('comment'); |
||
| 29 | } |
||
| 30 | //$comment = time(); |
||
| 31 | $document->setTitle($title); |
||
| 32 | if ('file' === $fileType && !empty($content)) { |
||
| 33 | $resourceNode = $document->getResourceNode(); |
||
| 34 | |||
| 35 | error_log('to update'); |
||
| 36 | //$document->setUploadFile($file); |
||
| 37 | //$repo->updateResourceFileContent($document, $content); |
||
| 38 | if ($resourceNode->hasResourceFile()) { |
||
| 39 | $resourceNode->setContent($content); |
||
| 40 | $resourceNode->getResourceFile()->setSize(strlen($content)); |
||
| 41 | } |
||
| 42 | $resourceNode->setUpdatedAt(new \DateTime()); |
||
| 43 | $resourceNode->getResourceFile()->setUpdatedAt(new \DateTime()); |
||
| 44 | $document->setResourceNode($resourceNode); |
||
| 45 | } |
||
| 46 | |||
| 47 | /*if ($request->request->has('resourceLinkList')) { |
||
| 48 | $links = $request->get('resourceLinkList'); |
||
| 49 | if (false === strpos($links, '[')) { |
||
| 50 | $links = json_decode('['.$links.']', true); |
||
| 51 | } else { |
||
| 52 | $links = json_decode($links, true); |
||
| 53 | } |
||
| 54 | if (empty($links)) { |
||
| 55 | throw new \InvalidArgumentException( |
||
| 56 | 'resourceLinkList is not a valid json. Example: [{"c_id":1:"visibility":1}]' |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | $document->setResourceLinkList($links); |
||
| 60 | }*/ |
||
| 61 | |||
| 62 | $repo->setResourceTitle($document, $title); |
||
| 63 | $document->setComment($comment); |
||
| 64 | |||
| 65 | error_log('Finish update resource node file action'); |
||
| 66 | |||
| 67 | return $document; |
||
| 68 | } |
||
| 70 |