SlotRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 2
Metric Value
eloc 10
c 7
b 0
f 2
dl 0
loc 50
rs 10
wmc 5
ccs 13
cts 13
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A startSlot() 0 4 2
A renderSlot() 0 3 1
A hasSlots() 0 3 1
A getSlots() 0 7 1
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
trait SlotRenderer
6
{
7
    protected $slotName;
8
9
    protected $slots = [];
10
11
    /**
12
     * Start output buffer to get content of slot and set slot name.
13
     *
14
     * @param  string  $name
15
     */
16 5
    public function startSlot($name)
17
    {
18 5
        if (ob_start()) {
19 5
            $this->slotName = $name;
20
        }
21 5
    }
22
23
    /**
24
     * get slot content from widget block.
25
     *
26
     * @param  string  $data
27
     */
28 5
    public function renderSlot($data = '')
29
    {
30 5
        $this->slots[$this->slotName] = $data;
31 5
    }
32
33
    /**
34
     * check if widget has any slots.
35
     *
36
     * @return bool
37
     */
38 21
    public function hasSlots()
39
    {
40 21
        return ! empty($this->slots);
41
    }
42
43
    /**
44
     * get and clean current slots.
45
     *
46
     * @return array $slots
47
     */
48 4
    public function getSlots()
49
    {
50 4
        $slots = $this->slots;
51
52 4
        $this->slots = [];
53
54 4
        return $slots;
55
    }
56
}
57