SubMenu::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 9
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace Malezha\Menu\Element;
3
4
use Malezha\Menu\Contracts\Attributes;
5
use Malezha\Menu\Contracts\Builder;
6
use Malezha\Menu\Contracts\ComparativeUrl;
7
use Malezha\Menu\Contracts\HasBuilder;
8
use Malezha\Menu\Contracts\MenuRender;
9
10
/**
11
 * Class SubMenu
12
 * @package Malezha\Menu\Element
13
 * 
14
 * @property-read Attributes $activeAttributes
15
 * @property-read Builder $builder
16
 * @inheritdoc
17
 */
18
class SubMenu extends Link implements HasBuilder
19
{
20
    /**
21
     * @var Builder
22
     */
23
    protected $builder;
24
25
    /**
26
     * SubMenu constructor.
27
     * @param string $title
28
     * @param string $url
29
     * @param Attributes $attributes
30
     * @param Attributes $activeAttributes
31
     * @param Attributes $linkAttributes
32
     * @param string $view
33
     * @param ComparativeUrl $comparativeUrl
34
     * @param MenuRender $render
35
     * @param Builder $builder
36
     */
37 6
    public function __construct($title, $url, Attributes $attributes, Attributes $activeAttributes,
38
                                Attributes $linkAttributes, $view, ComparativeUrl $comparativeUrl, 
39
                                MenuRender $render, Builder $builder)
40
    {
41 6
        parent::__construct($title, $url, $attributes, $activeAttributes, $linkAttributes, $view, $comparativeUrl, $render);
42
        
43 6
        $this->builder = $builder;
44 6
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49 1
    public function getBuilder()
50
    {
51 1
        return $this->builder;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 6
    public function renderWith()
58
    {
59 6
        $renderView = func_get_arg(0);
60
61 6
        return array_merge(parent::renderWith(), [
62 6
            'builder' => $this->builder,
63 6
            'renderView' => $renderView,
64
        ]);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 6
    public function render($view = null)
71
    {
72 6
        return $this->render->make($this->view)
73 6
            ->with($this->renderWith($view))
74 6
            ->render();
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80 2
    public function toArray()
81
    {
82 2
        return array_merge(parent::toArray(), [
83 2
            'builder' => $this->builder->toArray(),
84
        ]);
85
    }
86
}