Completed
Push — master ( 8466ff...9e5b24 )
by Jean-Christophe
03:04
created

HtmlGridRow   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 11.86 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 3
dl 7
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
A setWidth() 7 7 2
A getCol() 0 3 1
A setStretched() 0 3 1
A createItem() 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
namespace Ajax\semantic\html\content;
4
5
use Ajax\common\html\HtmlCollection;
6
use Ajax\semantic\html\base\Wide;
7
/**
8
 * A row for the Semantic Grid component
9
 * @see http://semantic-ui.com/collections/grid.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlGridRow extends HtmlCollection{
14
15
	private $_colSize;
16
	public function __construct( $identifier,$numCols=NULL,$colSizing=false){
17
		parent::__construct( $identifier,"div");
18
		$this->setClass("row");
19
		$width=null;
20
		if(isset($numCols)){
21
			$numCols=min(16,$numCols);
22
			$numCols=max(1,$numCols);
23
			if($colSizing)
24
				$width=(int)(16/$numCols);
25
			else
26
				$this->_colSize=16/$numCols;
27
			for ($i=0;$i<$numCols;$i++){
28
				$this->addItem($width);
29
			}
30
		}
31
	}
32
33
	/**
34
	 * Defines the row width
35
	 * @param int $width
36
	 * @return \Ajax\semantic\html\content\HtmlGridRow
37
	 */
38 View Code Duplication
	public function setWidth($width){
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...
39
		if(\is_int($width)){
40
			$width=Wide::getConstants()["W".$width];
41
		}
42
		$this->addToPropertyCtrl("class", $width, Wide::getConstants());
43
		return $this->addToPropertyCtrl("class", "column",array("column"));
44
	}
45
46
	/**
47
	 * return the col at $index
48
	 * @param int $index
49
	 * @return \Ajax\semantic\html\collections\HtmlGridCol
50
	 */
51
	public function getCol($index){
52
		return $this->getItem($index);
53
	}
54
55
	/**
56
	 * stretch the row contents to take up the entire column height
57
	 * @return \Ajax\semantic\html\content\HtmlGridRow
58
	 */
59
	public function setStretched(){
60
		return $this->addToProperty("class", "stretched");
61
	}
62
63
	/**
64
	 * {@inheritDoc}
65
	 * @see \Ajax\common\html\HtmlCollection::createItem()
66
	 */
67
	protected function createItem($value){
68
		$col=new HtmlGridCol($this->identifier."-col-".($this->count()+1),$value);
69
		return $col;
70
	}
71
}