| Conditions | 10 |
| Paths | 48 |
| Total Lines | 65 |
| Code Lines | 38 |
| 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 |
||
| 96 | protected function handleUpdateRequest(AbstractResource $resource, $repo, Request $request) |
||
| 97 | { |
||
| 98 | error_log('handleUpdateRequest'); |
||
| 99 | $contentData = $request->getContent(); |
||
| 100 | $resourceLinkList = []; |
||
| 101 | if (!empty($contentData)) { |
||
| 102 | error_log('contentData'); |
||
| 103 | $contentData = json_decode($contentData, true); |
||
| 104 | $title = $contentData['title']; |
||
| 105 | $content = $contentData['contentFile']; |
||
| 106 | //$comment = $contentData['comment'] ?? ''; |
||
| 107 | $resourceLinkList = $contentData['resourceLinkListFromEntity'] ?? []; |
||
| 108 | } else { |
||
| 109 | $title = $request->get('title'); |
||
| 110 | $content = $request->request->get('contentFile'); |
||
| 111 | //$comment = $request->request->get('comment'); |
||
| 112 | } |
||
| 113 | |||
| 114 | $repo->setResourceName($resource, $title); |
||
| 115 | |||
| 116 | $hasFile = $resource->getResourceNode()->hasResourceFile(); |
||
| 117 | |||
| 118 | //if ('file' === $fileType && !empty($content)) { |
||
| 119 | if ($hasFile && !empty($content)) { |
||
| 120 | $resourceNode = $resource->getResourceNode(); |
||
| 121 | if ($resourceNode->hasResourceFile()) { |
||
| 122 | $resourceNode->setContent($content); |
||
| 123 | $resourceNode->getResourceFile()->setSize(\strlen($content)); |
||
| 124 | } |
||
| 125 | $resourceNode->setUpdatedAt(new DateTime()); |
||
| 126 | $resourceNode->getResourceFile()->setUpdatedAt(new DateTime()); |
||
| 127 | $resource->setResourceNode($resourceNode); |
||
| 128 | } |
||
| 129 | |||
| 130 | $link = null; |
||
| 131 | if (!empty($resourceLinkList)) { |
||
| 132 | foreach ($resourceLinkList as $linkArray) { |
||
| 133 | // Find the exact link. |
||
| 134 | $linkId = $linkArray['id']; |
||
| 135 | /** @var ResourceLink $link */ |
||
| 136 | $link = $resource->getResourceNode()->getResourceLinks() |
||
| 137 | ->filter( |
||
| 138 | fn ($link) => $link->getId() === $linkId |
||
| 139 | )->first(); |
||
| 140 | |||
| 141 | if (null !== $link) { |
||
| 142 | $link->setVisibility((int) $linkArray['visibility']); |
||
| 143 | |||
| 144 | break; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | //$isRecursive = 'folder' === $fileType; |
||
| 150 | $isRecursive = !$hasFile; |
||
| 151 | // If it's a folder then change the visibility to the children (That have the same link). |
||
| 152 | if ($isRecursive && null !== $link) { |
||
| 153 | $repo->copyVisibilityToChildren($resource->getResourceNode(), $link); |
||
| 154 | } |
||
| 155 | |||
| 156 | //$document->setComment($comment); |
||
| 157 | |||
| 158 | error_log('Finish update resource node file action'); |
||
| 159 | |||
| 160 | return $resource; |
||
| 161 | } |
||
| 163 |