Passed
Push — master ( f2b4ae...a14f49 )
by Iman
55s queued 11s
created

SlotRenderer::startSlot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 2
Metric Value
cc 2
eloc 2
c 4
b 0
f 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
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 5
    }
21
22
    /**
23
     * get slot content from widget block
24
     * 
25
     * @param String $data
26
     */
27 5
    public function renderSlot($data = "")
28
    {
29 5
        $this->slots[$this->slotName] = $data;
30 5
    }
31
32
    /**
33
     * check if widget has any slots
34
     * 
35
     * @return Boolean
36
     */
37 21
    public function hasSlots()
38
    {
39 21
        return !empty($this->slots);
40
    }
41
42
    /**
43
     * get and clean current slots
44
     * 
45
     * @return Array $slots
46
     */
47 4
    public function getSlots()
48
    {
49 4
        $slots = $this->slots;
50
51 4
        $this->slots = [];
52
53 4
        return $slots;
54
    }
55
}
56