| Conditions | 12 |
| Paths | 48 |
| Total Lines | 68 |
| Code Lines | 38 |
| 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 |
||
| 53 | protected function getMenu(BlockContextInterface $blockContext) |
||
| 54 | { |
||
| 55 | $menu = $this->getRootMenu($blockContext); |
||
| 56 | |||
| 57 | $menu->addChild('Home', ['route' => 'home']); |
||
| 58 | $sessionId = 0; |
||
| 59 | if ($blockContext->getBlock()->getSetting('session_id')) { |
||
| 60 | $sessionId = $blockContext->getBlock()->getSetting('session_id'); |
||
| 61 | } |
||
| 62 | |||
| 63 | // Add course |
||
| 64 | /** @var Course $course */ |
||
| 65 | if ($course = $blockContext->getBlock()->getSetting('course')) { |
||
| 66 | if (is_array($course)) { |
||
| 67 | $title = $course['title']; |
||
| 68 | $code = $course['code']; |
||
| 69 | } else { |
||
| 70 | $title = $course->getTitle(); |
||
| 71 | $code = $course->getCode(); |
||
| 72 | } |
||
| 73 | |||
| 74 | $menu->addChild( |
||
| 75 | $title, |
||
| 76 | [ |
||
| 77 | 'route' => 'course_home', |
||
| 78 | 'routeParameters' => [ |
||
| 79 | 'course' => $code, |
||
| 80 | 'id_session' => $sessionId, |
||
| 81 | ], |
||
| 82 | ] |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | |||
| 86 | if (!empty($this->extraChildren)) { |
||
| 87 | foreach ($this->extraChildren as $item) { |
||
| 88 | $params = isset($item['params']) ? $item['params'] : []; |
||
| 89 | $menu->addChild( |
||
| 90 | $item['title'], |
||
| 91 | $params |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | // Load legacy breadcrumbs |
||
| 97 | $oldBreadCrumb = $blockContext->getBlock()->getSetting('legacy_breadcrumb'); |
||
| 98 | |||
| 99 | if ($oldBreadCrumb) { |
||
| 100 | foreach ($oldBreadCrumb as $data) { |
||
| 101 | if (empty($data['name'])) { |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | $url = $data['url']; |
||
| 105 | if ($url === '#') { |
||
| 106 | $menu->addChild($data['name']); |
||
| 107 | } else { |
||
| 108 | $menu->addChild($data['name'], ['uri' => $url]); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | // Set CSS classes for the items |
||
| 114 | foreach ($menu->getChildren() as $child) { |
||
| 115 | $child |
||
| 116 | //->setLinkAttribute('class', 'nav-link') |
||
| 117 | ->setAttribute('class', 'breadcrumb-item'); |
||
| 118 | } |
||
| 119 | |||
| 120 | return $menu; |
||
| 121 | } |
||
| 123 |