Completed
Push — master ( e04e71...98392d )
by Jean-Christophe
03:50
created

HtmlCardContent   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 77
Duplicated Lines 7.79 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 17
c 2
b 0
f 0
lcom 1
cbo 3
dl 6
loc 77
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addElement() 6 6 1
A addMeta() 0 11 3
A addImage() 0 7 2
A addMetas() 0 9 3
A addContentIcon() 0 17 3
A addContentIcons() 0 6 2
A addHeaderContent() 0 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\card;
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
class HtmlCardContent extends HtmlSemDoubleElement {
11
12
	public function __construct($identifier, $content=array()) {
13
		parent::__construct($identifier, "div", "content", $content);
14
	}
15
16 View Code Duplication
	private function addElement($content, $baseClass) {
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...
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 addContentIcons($icons, $direction=Direction::LEFT) {
72
		foreach ( $icons as $icon ) {
73
			$this->addContentIcon($icon, NULL, $direction);
74
		}
75
		return $this;
76
	}
77
78
	public function addHeaderContent($header, $metas=array(), $description=NULL) {
79
		$this->addElement($header, "header");
80
		$this->addMetas($metas);
81
		if (isset($description)) {
82
			$this->addElement($description, "description");
83
		}
84
		return $this;
85
	}
86
}