| Conditions | 15 |
| Paths | 65 |
| Total Lines | 58 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 20 | ||
| Bugs | 13 | 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 |
||
| 23 | public static function display($elements) |
||
| 24 | { |
||
| 25 | if (!Arr::in($elements['type'], ['ul', 'ol']) || count($elements['items']) < 1) { |
||
| 26 | return null; |
||
| 27 | } |
||
| 28 | |||
| 29 | $orderActiveLink = false; |
||
| 30 | if ($elements['activeOrder'] !== null) { |
||
| 31 | $orderActiveLink = $elements['activeOrder']; |
||
| 32 | } |
||
| 33 | |||
| 34 | $items = null; |
||
| 35 | // foreach elements and build schema |
||
| 36 | foreach ($elements['items'] as $item) { |
||
| 37 | // type is undefined, skip |
||
| 38 | if (!Arr::in($item['type'], ['text', 'link'])) { |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | // sounds like a link, try detect active element |
||
| 42 | if ($item['type'] === 'link') { |
||
| 43 | if (!Obj::isArray($item['link']) && !Str::startsWith('http', $item['link']) && !Str::startsWith('#', |
||
| 44 | $item['link']) |
||
| 45 | ) { |
||
| 46 | $item['link'] = [$item['link']]; // just controller/action sended, to array |
||
| 47 | } |
||
| 48 | |||
| 49 | // check if current element is link and is active |
||
| 50 | if (Obj::isArray($item['link'])) { |
||
| 51 | if (!isset($item['activeClass'])) { |
||
| 52 | $item['activeClass'] = 'active'; |
||
| 53 | } |
||
| 54 | |||
| 55 | $activeItem = self::isCurrentLink($item['link'], $item['activeOn'], $orderActiveLink); |
||
| 56 | |||
| 57 | // check if it active link for current pathway |
||
| 58 | if ($activeItem) { |
||
| 59 | $item['property']['class'] = Str::length($item['property']['class']) > 0 |
||
| 60 | ? $item['activeClass'] . ' ' . $item['property']['class'] |
||
| 61 | : $item['activeClass']; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | $innerItem = self::applyEscape($item['text'], $item['html'], $item['!secure']); |
||
| 67 | // sounds like a hyperlink? |
||
| 68 | if ($item['type'] === 'link') { |
||
| 69 | // parse uri-link type to classic link |
||
| 70 | $item['linkProperty']['href'] = self::convertLink($item['link']); |
||
| 71 | // make classic tag inside with text value |
||
| 72 | $innerItem = self::buildContainerTag('a', $item['linkProperty'], $innerItem, $item['html']); |
||
|
|
|||
| 73 | } |
||
| 74 | // store item |
||
| 75 | $items .= self::buildContainerTag('li', $item['property'], $innerItem, true); |
||
| 76 | } |
||
| 77 | |||
| 78 | // return <ul/> or <ol/> full container |
||
| 79 | return self::buildContainerTag($elements['type'], $elements['property'], $items, true); |
||
| 80 | } |
||
| 81 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.