| Conditions | 6 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 102 | private function setBreadCrumb(Request $request, ResourceNode $resourceNode) |
||
| 103 | { |
||
| 104 | return false; |
||
| 105 | $tool = $request->get('tool'); |
||
| 106 | $resourceNodeId = $request->get('id'); |
||
| 107 | $routeParams = $this->getResourceParams($request); |
||
| 108 | $baseNodeId = $this->getCourse()->getResourceNode()->getId(); |
||
| 109 | |||
| 110 | if (!empty($resourceNodeId)) { |
||
| 111 | $breadcrumb = $this->getBreadCrumb(); |
||
| 112 | $toolParams = $routeParams; |
||
| 113 | $toolParams['id'] = null; |
||
| 114 | |||
| 115 | // Root tool link |
||
| 116 | $breadcrumb->addChild( |
||
| 117 | $this->trans($tool), |
||
| 118 | [ |
||
| 119 | 'uri' => $this->generateUrl('chamilo_core_resource_index', $toolParams), |
||
| 120 | ] |
||
| 121 | ); |
||
| 122 | |||
| 123 | $repo = $this->getRepositoryFromRequest($request); |
||
| 124 | $settings = $repo->getResourceSettings(); |
||
| 125 | |||
| 126 | /** @var ResourceInterface $originalResource */ |
||
| 127 | //$originalResource = $repo->findOneBy(['resourceNode' => $resourceNodeId]); |
||
| 128 | if (null === $resourceNode) { |
||
| 129 | return; |
||
| 130 | } |
||
| 131 | //var_dump($resourceNode->getTitle()); throw new \Exception('22'); |
||
| 132 | $parentList = $resourceNode->getPathForDisplayToArray($baseNodeId); |
||
| 133 | |||
| 134 | // var_dump($originalParent->getPath(), $originalParent->getPathForDisplay()); |
||
| 135 | |||
| 136 | // $parentList = []; |
||
| 137 | /* while (null !== $parent) { |
||
| 138 | if ($type !== $parent->getResourceType()->getName()) { |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | $parent = $parent->getParent(); |
||
| 142 | if ($parent) { |
||
| 143 | $resource = $repo->findOneBy(['resourceNode' => $parent->getId()]); |
||
| 144 | if ($resource) { |
||
| 145 | $parentList[] = $resource; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | $parentList = array_reverse($parentList); |
||
| 150 | foreach ($parentList as $item) { |
||
| 151 | $params = $routeParams; |
||
| 152 | $params['id'] = $item->getResourceNode()->getId(); |
||
| 153 | $breadcrumb->addChild( |
||
| 154 | $item->getResourceName(), |
||
| 155 | [ |
||
| 156 | 'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
||
| 157 | ] |
||
| 158 | ); |
||
| 159 | }*/ |
||
| 160 | |||
| 161 | foreach ($parentList as $id => $title) { |
||
| 162 | $params = $routeParams; |
||
| 163 | $params['id'] = $id; |
||
| 164 | $breadcrumb->addChild( |
||
| 165 | $title, |
||
| 166 | [ |
||
| 167 | 'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
||
| 168 | ] |
||
| 169 | ); |
||
| 170 | } |
||
| 171 | |||
| 172 | $params = $routeParams; |
||
| 173 | $params['id'] = $resourceNode->getId(); |
||
| 174 | if (false === $settings->isAllowNodeCreation() || $resourceNode->hasResourceFile()) { |
||
| 175 | $breadcrumb->addChild($resourceNode->getTitle()); |
||
| 176 | } else { |
||
| 177 | $breadcrumb->addChild( |
||
| 178 | $resourceNode->getTitle(), |
||
| 179 | [ |
||
| 180 | 'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
||
| 181 | ] |
||
| 187 |