Render::buildRows()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 8

Duplication

Lines 20
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 20
loc 20
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
/**
3
 * @package    Fuel\Common
4
 * @version    2.0
5
 * @author     Fuel Development Team
6
 * @license    MIT License
7
 * @copyright  2010 - 2015 Fuel Development Team
8
 * @link       http://fuelphp.com
9
 */
10
11
namespace Fuel\Common\Table;
12
13
use Fuel\Common\Table;
14
15
/**
16
 * Uses a table structure built with Table to create HTML
17
 *
18
 * @package Fuel\Common
19
 *
20
 * @since 2.0
21
 */
22
abstract class Render
23
{
24
	/**
25
	 * Renders the given table into a string. Output depends on the subclass
26
	 *
27
	 * @param Table $table
28
	 *
29
	 * @return string
30
	 */
31
	public function renderTable(Table $table)
32
	{
33
		//Generate each row
34
		$rows = $this->buildRows($table);
35
36
		$headerRows = $this->buildHeaders($table);
37
38
		$footerRows = $this->buildFooters($table);
39
40
		return $this->container($table, $rows, $headerRows, $footerRows);
41
	}
42
43
	/**
44
	 * Renders the main body rows for the table
45
	 *
46
	 * @param Table $table
47
	 *
48
	 * @return array
49
	 */
50 View Code Duplication
	protected function buildRows(Table $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		//Generate each row
53
		$rows = array();
54
55
		foreach ( $table->getRows() as $row )
56
		{
57
			//Build the cells for each row
58
			$cells = array();
59
60
			foreach ( $row as $cell )
61
			{
62
				$cells[] = $this->cell($cell);
63
			}
64
65
			$rows[] = $this->row($row, $cells);
66
		}
67
68
		return $rows;
69
	}
70
71
	/**
72
	 * Renders the header rows for the table
73
	 *
74
	 * @param Table $table
75
	 *
76
	 * @return array
77
	 */
78 View Code Duplication
	protected function buildHeaders(Table $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
	{
80
		//Generate each row
81
		$rows = array();
82
83
		foreach ( $table->getHeaderRows() as $row )
84
		{
85
			//Build the cells for each row
86
			$cells = array();
87
88
			foreach ( $row as $cell )
89
			{
90
				$cells[] = $this->headerCell($cell);
91
			}
92
93
			$rows[] = $this->headerRow($row, $cells);
94
		}
95
96
		return $rows;
97
	}
98
99
	/**
100
	 * Renders the footer rows for the table
101
	 *
102
	 * @param Table $table
103
	 *
104
	 * @return array
105
	 */
106 View Code Duplication
	protected function buildFooters(Table $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
	{
108
		//Generate each row
109
		$rows = array();
110
111
		foreach ( $table->getFooterRows() as $row )
112
		{
113
			//Build the cells for each row
114
			$cells = array();
115
116
			foreach ( $row as $cell )
117
			{
118
				$cells[] = $this->footerCell($cell);
119
			}
120
121
			$rows[] = $this->footerRow($row, $cells);
122
		}
123
124
		return $rows;
125
	}
126
127
	/**
128
	 * Should generate the container tag, eg: &lt;table&gt;
129
	 *
130
	 * @param Table $table
131
	 * @param array $rows
132
	 * @param array $headerRows
133
	 * @param array $footerRows
134
	 *
135
	 * @return mixed Should Ideally be a string that can be printed later
136
	 */
137
	protected abstract function container(
138
		Table $table,
139
		array $rows,
140
		array $headerRows,
141
		array $footerRows
142
	);
143
144
	/**
145
	 * Renders a normal Row
146
	 *
147
	 * @param Row   $row
148
	 * @param array $cells
149
	 *
150
	 * @return mixed Should ideally be a string that can be printed by container()
151
	 */
152
	protected abstract function row(Row $row, array $cells);
153
154
	/**
155
	 * Renders a header Row
156
	 *
157
	 * @param Row   $row
158
	 * @param array $cells
159
	 *
160
	 * @return mixed Should ideally be a string that can be printed by container()
161
	 */
162
	protected abstract function headerRow(Row $row, array $cells);
163
164
	/**
165
	 * Renders a footer Row
166
	 *
167
	 * @param Row   $row
168
	 * @param array $cells
169
	 *
170
	 * @return mixed Should ideally be a string that can be printed by
171
	 * container()
172
	 */
173
	protected abstract function footerRow(Row $row, array $cells);
174
175
	/**
176
	 * Renders a normal cell
177
	 *
178
	 * @param Cell
179
	 */
180
	protected abstract function cell(Cell $cell);
181
182
	/**
183
	 * Renders a header cell
184
	 *
185
	 * @param Cell
186
	 */
187
	protected abstract function headerCell(Cell $cell);
188
189
	/**
190
	 * Renders a footer cell
191
	 *
192
	 * @param Cell
193
	 */
194
	protected abstract function footerCell(Cell $cell);
195
}
196