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

HtmlCard   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 96
Duplicated Lines 20.83 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 21
c 2
b 0
f 0
lcom 1
cbo 7
dl 20
loc 96
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createContent() 6 6 1
A addElementInContent() 0 7 2
A addHeader() 0 6 2
A addImage() 0 7 2
A addReveal() 7 7 2
A addRevealImage() 7 7 2
A addExtraContent() 0 3 1
A addContent() 0 6 2
A addCardHeaderContent() 0 4 1
A addCardContent() 0 4 1
A getCardContent() 0 3 1
A compile() 0 4 1
A asLink() 0 7 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\views;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\elements\HtmlHeader;
7
use Ajax\JsUtils;
8
use Ajax\service\JArray;
9
use Phalcon\Mvc\View;
10
use Ajax\semantic\html\elements\HtmlImage;
11
use Ajax\semantic\html\content\card\HtmlCardContent;
12
use Ajax\semantic\html\content\card\HtmlCardHeaderContent;
13
use Ajax\semantic\html\elements\HtmlReveal;
14
use Ajax\semantic\html\base\constants\RevealType;
15
16
class HtmlCard extends HtmlSemDoubleElement {
17
18
	public function __construct($identifier) {
19
		parent::__construct($identifier, "div", "ui card", array ());
20
	}
21
22 View Code Duplication
	private function createContent($content, $baseClass="content") {
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...
23
		$count=\sizeof($this->content);
24
		$result=new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content);
25
		$result->setClass($baseClass);
26
		return $result;
27
	}
28
29
	private function addElementInContent($key, $element) {
30
		if (\array_key_exists($key, $this->content) === false) {
31
			$this->content[$key]=array ();
32
		}
33
		$this->content[$key][]=$element;
34
		return $element;
35
	}
36
37
	public function addHeader($header, $niveau=4, $type="page") {
38
		if (!$header instanceof HtmlHeader) {
39
			$header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type);
40
		}
41
		$this->content["header"]=$this->createContent($header);
42
	}
43
44
	public function addImage($image, $title="") {
45
		if (!$image instanceof HtmlImage) {
46
			$image=new HtmlImage("image-" . $this->identifier, $image, $title);
47
		}
48
		$image->setClass("image");
49
		return $this->addElementInContent("content", $image);
50
	}
51
52 View Code Duplication
	public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
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...
53
		$reveal=$visibleContent;
54
		if (!$visibleContent instanceof HtmlReveal) {
55
			$reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType);
56
		}
57
		return $this->addElementInContent("content", $reveal);
58
	}
59
60 View Code Duplication
	public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
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...
61
		$reveal=$visibleContent;
62
		if (!$visibleContent instanceof HtmlReveal) {
63
			return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType);
64
		}
65
		return $this->addElementInContent("content", $reveal);
66
	}
67
68
	public function addExtraContent($content=array()) {
69
		return $this->addElementInContent("extra-content", $this->createContent($content, "extra content"));
70
	}
71
72
	public function addContent($content=array(), $before=false) {
73
		if (!$content instanceof HtmlCardContent) {
74
			$content=$this->createContent($content);
75
		}
76
		return $this->addElementInContent("content", $content);
77
	}
78
79
	public function addCardHeaderContent($header, $metas=array(), $description=NULL) {
80
		$count=\sizeof($this->content);
81
		return $this->addElementInContent("content", new HtmlCardHeaderContent("content-" . $count . "-" . $this->identifier, $header, $metas, $description));
82
	}
83
84
	public function addCardContent($content=array()) {
85
		$count=\sizeof($this->content);
86
		return $this->addElementInContent("content", new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content));
87
	}
88
89
	public function getCardContent($index){
90
		return $this->content["content"][$index];
91
	}
92
93
	/**
94
	 *
95
	 * {@inheritDoc}
96
	 *
97
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
98
	 */
99
	public function compile(JsUtils $js=NULL, View $view=NULL) {
100
		$this->content=JArray::sortAssociative($this->content, [ "header","image","content","extra-content" ]);
101
		return parent::compile($js, $view);
102
	}
103
104
	public function asLink($href="") {
105
		$this->addToProperty("class", "link");
106
		if ($href !== "") {
107
			$this->setProperty("href", $href);
108
		}
109
		return $this;
110
	}
111
}