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

HtmlGridRow::setWidth()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
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
}