Completed
Push — master ( e84808...5a9d2e )
by Oleg
07:58
created

LinkFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 40
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A build() 0 7 1
A setDisplayRule() 0 6 2
1
<?php
2
namespace Malezha\Menu\Factory;
3
4
use Illuminate\Contracts\Container\Container;
5
use Illuminate\Http\Request;
6
use Malezha\Menu\Contracts\Attributes;
7
use Malezha\Menu\Element\Link;
8
9
/**
10
 * Class LinkFactory
11
 * @package Malezha\Menu\Factory
12
 *
13
 * @property string $title
14
 * @property string $url
15
 * @property Attributes $attributes
16
 * @property Attributes $activeAttributes
17
 * @property Attributes $linkAttributes
18
 * @property string $view
19
 * @property mixed $displayRule
20
 *
21
 */
22
class LinkFactory extends AbstractElementFactory
23
{
24
    /**
25
     * @inheritdoc
26
     */
27 23
    public function __construct(Container $container)
28
    {
29 23
        parent::__construct($container);
30
        
31 23
        $this->parameters = [
32 23
            'title' => '',
33 23
            'url' => '#',
34 23
            'attributes' => $this->app->make(Attributes::class, ['attributes' => []]),
35 23
            'activeAttributes' => $this->app->make(Attributes::class, ['attributes' => []]),
36 23
            'linkAttributes' => $this->app->make(Attributes::class, ['attributes' => []]),
37 23
            'view' => $this->getElementConfig(Link::class)['view'],
38 23
            'currentUrl' => $this->app->make(Request::class)->url(),
39
            'displayRule' => true,
40
        ];
41 23
    }
42
43
    /**
44
     * @param array $parameters
45
     * @return Link
46
     */
47 18
    public function build($parameters = [])
48
    {
49 18
        $link = $this->app->make(Link::class, $this->mergeParameters($parameters));
50 18
        $this->setDisplayRule($link);
51
        
52 18
        return $link;
53
    }
54
    
55 18
    protected function setDisplayRule(Link $link)
56
    {
57 18
        if (array_key_exists('displayRule', $this->parameters)) {
58 18
            $link->setDisplayRule($this->parameters['displayRule']);
59
        }
60
    }
61
}