| Conditions | 10 |
| Paths | 14 |
| Total Lines | 66 |
| Code Lines | 41 |
| 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 |
||
| 109 | private function setBreadCrumb(Request $request) |
||
| 110 | { |
||
| 111 | $tool = $request->get('tool'); |
||
| 112 | $type = $request->get('type'); |
||
| 113 | $resourceNodeId = $request->get('id'); |
||
| 114 | $routeParams = $this->getResourceParams($request); |
||
| 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 === $originalResource) { |
||
| 135 | return; |
||
| 136 | } |
||
| 137 | $parent = $originalParent = $originalResource->getResourceNode(); |
||
| 138 | |||
| 139 | $parentList = []; |
||
| 140 | while (null !== $parent) { |
||
| 141 | if ($type !== $parent->getResourceType()->getName()) { |
||
| 142 | break; |
||
| 143 | } |
||
| 144 | $parent = $parent->getParent(); |
||
| 145 | if ($parent) { |
||
| 146 | $resource = $repo->findOneBy(['resourceNode' => $parent->getId()]); |
||
| 147 | if ($resource) { |
||
| 148 | $parentList[] = $resource; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $parentList = array_reverse($parentList); |
||
| 154 | /** @var ResourceInterface $item */ |
||
| 155 | foreach ($parentList as $item) { |
||
| 156 | $params = $routeParams; |
||
| 157 | $params['id'] = $item->getResourceNode()->getId(); |
||
| 158 | $breadcrumb->addChild( |
||
| 159 | $item->getResourceName(), |
||
| 160 | [ |
||
| 161 | 'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
||
| 162 | ] |
||
| 163 | ); |
||
| 164 | } |
||
| 165 | |||
| 166 | $params = $routeParams; |
||
| 167 | $params['id'] = $originalParent->getId(); |
||
| 168 | if (false === $settings->isAllowNodeCreation() || $originalResource->getResourceNode()->hasResourceFile()) { |
||
| 169 | $breadcrumb->addChild($originalResource->getResourceName()); |
||
| 170 | } else { |
||
| 171 | $breadcrumb->addChild( |
||
| 172 | $originalResource->getResourceName(), |
||
| 173 | [ |
||
| 174 | 'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
||
| 175 | ] |
||
| 181 |