SlotRenderer::renderSlot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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