Completed
Push — master ( 7a7fba...3207da )
by Song
14:14
created

Row::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Layout;
4
5
use Illuminate\Contracts\Support\Renderable;
6
7
class Row implements Buildable, Renderable
8
{
9
    /**
10
     * @var Column[]
11
     */
12
    protected $columns = [];
13
14
    /**
15
     * Row constructor.
16
     *
17
     * @param string $content
18
     */
19
    public function __construct($content = '')
20
    {
21
        if (!empty($content)) {
22
            $this->column(12, $content);
23
        }
24
    }
25
26
    /**
27
     * Add a column.
28
     *
29
     * @param int $width
30
     * @param $content
31
     */
32
    public function column($width, $content)
33
    {
34
        $width = $width < 1 ? round(12 * $width) : $width;
35
36
        $column = new Column($content, $width);
37
38
        $this->addColumn($column);
39
    }
40
41
    /**
42
     * @param Column $column
43
     */
44
    protected function addColumn(Column $column)
45
    {
46
        $this->columns[] = $column;
47
    }
48
49
    /**
50
     * Build row column.
51
     */
52
    public function build()
53
    {
54
        $this->startRow();
55
56
        foreach ($this->columns as $column) {
57
            $column->build();
58
        }
59
60
        $this->endRow();
61
    }
62
63
    /**
64
     * Start row.
65
     */
66
    protected function startRow()
67
    {
68
        echo '<div class="row">';
69
    }
70
71
    /**
72
     * End column.
73
     */
74
    protected function endRow()
75
    {
76
        echo '</div>';
77
    }
78
79
    /**
80
     * Render row.
81
     *
82
     * @return string
83
     */
84
    public function render()
85
    {
86
        ob_start();
87
88
        $this->build();
89
90
        $contents = ob_get_contents();
91
92
        ob_end_clean();
93
94
        return $contents;
95
    }
96
}
97