SimpleTable   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 102
Duplicated Lines 15.69 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 9
c 3
b 0
f 1
lcom 1
cbo 5
dl 16
loc 102
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A container() 0 14 1
A row() 0 8 1
A cell() 8 8 1
A addAttributes() 0 9 2
A footerCell() 0 4 1
A footerRow() 0 4 1
A headerCell() 8 8 1
A headerRow() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Render;
12
13
use Fuel\Common\Table\Render;
14
use Fuel\Common\Table\Cell;
15
use Fuel\Common\Table\Row;
16
use Fuel\Common\Table;
17
use Fuel\Common\Html;
18
19
/**
20
 * Uses a table structure built with Table to create a HTML table tag and
21
 * content.
22
 *
23
 * @package Fuel\Common
24
 *
25
 * @since 2.0
26
 */
27
class SimpleTable extends Render
28
{
29
	/**
30
	 * Generates a "correct" table tag to contain the rendered rows
31
	 *
32
	 * @param Table $table
33
	 * @param array $rows
34
	 * @param array $headers
35
	 * @param array $footers
36
	 *
37
	 * @return string
38
	 */
39
	protected function container(Table $table, array $rows, array $headers, array $footers)
40
	{
41
		$html = '<table';
42
		$this->addAttributes($html, $table->getAttributes());
43
		$html .= '><thead>';
44
		$html .= implode("\n", $headers);
45
		$html .= '</thead><tbody>';
46
		$html .= implode("\n", $rows);
47
		$html .= '</tbody><tfoot>';
48
		$html .= implode("\n", $footers);
49
		$html .= '</tfoot></table>';
50
51
		return $html;
52
	}
53
54
	/**
55
	 * Generates a tr with the given rendered cells
56
	 *
57
	 * @param Row   $row
58
	 * @param array $cells
59
	 *
60
	 * @return string
61
	 */
62
	protected function row(Row $row, array $cells)
63
	{
64
		$html = '<tr';
65
		$this->addAttributes($html, $row->getAttributes());
66
		$html .= '>' . implode('', $cells) . '</tr>';
67
68
		return $html;
69
	}
70
71
	/**
72
	 * Creates a td tag using the given Cell
73
	 *
74
	 * @param Cell $cell
75
	 *
76
	 * @return string
77
	 */
78 View Code Duplication
	protected function cell(Cell $cell)
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
		$html = '<td';
81
		$this->addAttributes($html, $cell->getAttributes());
82
		$html .= '>' . $cell->getContent() . '</td>';
83
84
		return $html;
85
	}
86
87
	/**
88
	 * Helper function to convert an array into a list of attributes and append
89
	 * them to a string
90
	 *
91
	 * @param string $html
92
	 * @param array  $attributes
93
	 */
94
	protected function addAttributes(&$html, array $attributes)
95
	{
96
		if ( count($attributes) > 0 )
97
		{
98
			$attributes = Html::arrayToAttributes($attributes);
99
100
			$html .= ' ' . $attributes;
101
		}
102
	}
103
104
	protected function footerCell(Table\Cell $cell)
105
	{
106
		return $this->cell($cell);
107
	}
108
109
	protected function footerRow(Table\Row $row, array $cells)
110
	{
111
		return $this->row($row, $cells);
112
	}
113
114 View Code Duplication
	protected function headerCell(Table\Cell $cell)
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...
115
	{
116
		$html = '<th';
117
		$this->addAttributes($html, $cell->getAttributes());
118
		$html .= '>' . $cell->getContent() . '</th>';
119
120
		return $html;
121
	}
122
123
	protected function headerRow(Table\Row $row, array $cells)
124
	{
125
		return $this->row($row, $cells);
126
	}
127
128
}
129