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

LinkFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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
}