| Conditions | 9 |
| Paths | 40 |
| Total Lines | 62 |
| Code Lines | 34 |
| 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 |
||
| 40 | public function normalize($object, ?string $format = null, array $context = []): array | string | int | float | bool | ArrayObject | null |
||
| 41 | { |
||
| 42 | $context[self::ALREADY_CALLED] = true; |
||
| 43 | |||
| 44 | $request = $this->requestStack->getCurrentRequest(); |
||
| 45 | |||
| 46 | $getFile = $request->get('getFile'); |
||
| 47 | |||
| 48 | $courseId = (int) $request->get('cid'); |
||
| 49 | if (empty($courseId)) { |
||
| 50 | // Try with cid from session |
||
| 51 | $courseId = (int) $request->getSession()->get('cid'); |
||
| 52 | } |
||
| 53 | |||
| 54 | $sessionId = (int) $request->get('sid'); |
||
| 55 | if (empty($sessionId)) { |
||
| 56 | $sessionId = (int) $request->getSession()->get('sid'); |
||
| 57 | } |
||
| 58 | |||
| 59 | $groupId = (int) $request->get('gid'); |
||
| 60 | if (empty($groupId)) { |
||
| 61 | $groupId = (int) $request->getSession()->get('gid'); |
||
| 62 | } |
||
| 63 | |||
| 64 | if ($object->hasResourceNode()) { |
||
| 65 | $resourceNode = $object->getResourceNode(); |
||
| 66 | |||
| 67 | $params = [ |
||
| 68 | 'id' => $resourceNode->getId(), |
||
| 69 | 'cid' => $courseId, |
||
| 70 | 'sid' => $sessionId, |
||
| 71 | 'gid' => $groupId, |
||
| 72 | 'tool' => $resourceNode->getResourceType()->getTool()->getName(), |
||
| 73 | 'type' => $resourceNode->getResourceType()->getName(), |
||
| 74 | ]; |
||
| 75 | |||
| 76 | //if ($getFile) { |
||
| 77 | // Get all links from resource. |
||
| 78 | $object->setResourceLinkListFromEntity(); |
||
| 79 | //} |
||
| 80 | |||
| 81 | $object->contentUrl = $this->generator->generate('chamilo_core_resource_view', $params); |
||
| 82 | $object->downloadUrl = $this->generator->generate('chamilo_core_resource_download', $params); |
||
| 83 | error_log($object->getResourceName()); |
||
| 84 | // Get illustration of a resource, instead of looking for the node children to get the illustration. |
||
| 85 | if ($object instanceof ResourceIllustrationInterface) { |
||
| 86 | error_log('check illustration'); |
||
| 87 | $object->illustrationUrl = $this->illustrationRepository->getIllustrationUrl($object); |
||
| 88 | } |
||
| 89 | |||
| 90 | // This gets the file contents, usually use to get HTML/Text data to be edited. |
||
| 91 | if ($getFile && |
||
| 92 | $resourceNode->hasResourceFile() && |
||
| 93 | $resourceNode->hasEditableTextContent() |
||
| 94 | ) { |
||
| 95 | $object->contentFile = $this->resourceNodeRepository->getResourceNodeFileContent( |
||
| 96 | $resourceNode |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $this->normalizer->normalize($object, $format, $context); |
||
| 102 | } |
||
| 113 |