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