| Conditions | 8 |
| Paths | 12 |
| Total Lines | 68 |
| Code Lines | 36 |
| 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 |
||
| 15 | public function __invoke(CDocument $document, Request $request, CDocumentRepository $repo, EntityManagerInterface $em): CDocument |
||
| 16 | { |
||
| 17 | $fileType = $document->getFileType(); |
||
| 18 | $contentData = $request->getContent(); |
||
| 19 | error_log('UpdateResourceNodeFileAction __invoke'); |
||
| 20 | |||
| 21 | if (!empty($contentData)) { |
||
| 22 | error_log('contentData'); |
||
| 23 | $contentData = json_decode($contentData, true); |
||
| 24 | $title = $contentData['title']; |
||
| 25 | $content = $contentData['contentFile']; |
||
| 26 | $comment = $contentData['comment']; |
||
| 27 | $resourceLinkList = $contentData['resourceLinkList']; |
||
| 28 | } else { |
||
| 29 | $title = $request->get('title'); |
||
| 30 | $content = $request->request->get('contentFile'); |
||
| 31 | $comment = $request->request->get('comment'); |
||
| 32 | } |
||
| 33 | |||
| 34 | $document->setTitle($title); |
||
| 35 | if ('file' === $fileType && !empty($content)) { |
||
| 36 | $resourceNode = $document->getResourceNode(); |
||
| 37 | if ($resourceNode->hasResourceFile()) { |
||
| 38 | $resourceNode->setContent($content); |
||
| 39 | $resourceNode->getResourceFile()->setSize(strlen($content)); |
||
| 40 | } |
||
| 41 | $resourceNode->setUpdatedAt(new \DateTime()); |
||
| 42 | $resourceNode->getResourceFile()->setUpdatedAt(new \DateTime()); |
||
| 43 | $document->setResourceNode($resourceNode); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!empty($resourceLinkList)) { |
||
| 47 | foreach ($resourceLinkList as $linkArray) { |
||
| 48 | $linkId = $linkArray['id']; |
||
| 49 | /** @var ResourceLink $link */ |
||
| 50 | $link = $document->getResourceNode()->getResourceLinks()->filter( |
||
| 51 | function ($link) use ($linkId) { |
||
| 52 | return $link->getId() === $linkId; |
||
| 53 | } |
||
| 54 | )->first(); |
||
| 55 | |||
| 56 | if (null !== $link) { |
||
| 57 | $link->setVisibility((int) $linkArray['visibility']); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | /*if ($request->request->has('resourceLinkList')) { |
||
| 63 | $links = $request->get('resourceLinkList'); |
||
| 64 | if (false === strpos($links, '[')) { |
||
| 65 | $links = json_decode('['.$links.']', true); |
||
| 66 | } else { |
||
| 67 | $links = json_decode($links, true); |
||
| 68 | } |
||
| 69 | if (empty($links)) { |
||
| 70 | throw new \InvalidArgumentException( |
||
| 71 | 'resourceLinkList is not a valid json. Example: [{"c_id":1:"visibility":1}]' |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | $document->setResourceLinkList($links); |
||
| 75 | }*/ |
||
| 76 | |||
| 77 | $repo->setResourceTitle($document, $title); |
||
| 78 | $document->setComment($comment); |
||
| 79 | |||
| 80 | error_log('Finish update resource node file action'); |
||
| 81 | |||
| 82 | return $document; |
||
| 83 | } |
||
| 85 |