Completed
Push — master ( fcfed5...b7a7dd )
by Jean-Christophe
03:28
created

HtmlViewContent   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 87
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 3
dl 87
loc 87
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A addElement() 6 6 1
A addMeta() 11 11 3
A addImage() 7 7 2
A addMetas() 9 9 3
A addContentIcon() 17 17 3
A addContentText() 9 9 2
A addContentIcons() 6 6 2
A addHeaderContent() 8 8 2

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\view;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\base\constants\Direction;
7
use Ajax\semantic\html\elements\HtmlIcon;
8
use Ajax\semantic\html\elements\html5\HtmlImg;
9
10 View Code Duplication
class HtmlViewContent extends HtmlSemDoubleElement {
0 ignored issues
show
Duplication introduced by
This class 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...
11
12
	public function __construct($identifier, $content=array()) {
13
		parent::__construct($identifier, "div", "content", $content);
14
	}
15
16
	private function addElement($content, $baseClass) {
17
		$count=\sizeof($this->content);
18
		$result=new HtmlSemDoubleElement("element-" . $count . "-" . $this->identifier, "div", $baseClass, $content);
19
		$this->addContent($result);
20
		return $result;
21
	}
22
23
	public function addMeta($value, $direction=Direction::LEFT) {
24
		if (\array_key_exists("meta", $this->content) === false) {
25
			$this->content["meta"]=new HtmlSemDoubleElement("meta-" . $this->identifier, "div", "meta", array ());
26
		}
27
		if ($direction === Direction::RIGHT) {
28
			$value=new HtmlSemDoubleElement("", "span", "", $value);
29
			$value->setFloated($direction);
30
		}
31
		$this->content["meta"]->addContent($value);
32
		return $this->content["meta"];
33
	}
34
35
	public function addImage($src="", $alt="", $size=NULL) {
36
		$image=new HtmlImg("img-", $src, $alt);
37
		if (isset($size))
38
			$image->setSize($size);
39
		$this->content["image"]=$image;
40
		return $image;
41
	}
42
43
	public function addMetas($metas) {
44
		if (\is_array($metas)) {
45
			foreach ( $metas as $meta ) {
46
				$this->addMeta($meta);
47
			}
48
		} else
49
			$this->addMeta($metas);
50
		return $this;
51
	}
52
53
	public function addContentIcon($icon, $caption=NULL, $direction=Direction::LEFT) {
54
		if ($direction === Direction::RIGHT) {
55
			if (isset($caption)) {
56
				$result=new HtmlSemDoubleElement("", "span", "", $caption);
57
				$result->addIcon($icon);
58
				$this->addContent($result);
59
			} else {
60
				$result=new HtmlIcon("", $icon);
61
				$this->addContent($result);
62
			}
63
			$result->setFloated($direction);
64
		} else {
65
			$this->addIcon($icon);
66
			$result=$this->addContent($caption);
67
		}
68
		return $result;
69
	}
70
71
	public function addContentText($caption, $direction=Direction::LEFT) {
72
		if ($direction === Direction::RIGHT) {
73
			$result=new HtmlSemDoubleElement("", "span", "", $caption);
74
			$this->addContent($result);
75
			$result->setFloated($direction);
76
		} else
77
			$result=$this->addContent($caption);
78
		return $result;
79
	}
80
81
	public function addContentIcons($icons, $direction=Direction::LEFT) {
82
		foreach ( $icons as $icon ) {
83
			$this->addContentIcon($icon, NULL, $direction);
84
		}
85
		return $this;
86
	}
87
88
	public function addHeaderContent($header, $metas=array(), $description=NULL) {
89
		$this->addElement($header, "header");
90
		$this->addMetas($metas);
91
		if (isset($description)) {
92
			$this->addElement($description, "description");
93
		}
94
		return $this;
95
	}
96
}