Passed
Push — master ( 83996b...17a193 )
by Jean-Christophe
09:22
created

MessagesTrait::showConfMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 11
ccs 11
cts 11
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Ubiquity\controllers\semantic;
4
5
use Ajax\semantic\html\elements\HtmlButton;
6
use Ubiquity\utils\base\UString;
7
use Ajax\semantic\html\elements\HtmlDivider;
8
use Ajax\semantic\html\base\HtmlSemDoubleElement;
9
use Ajax\semantic\html\collections\HtmlMessage;
10
use Ubiquity\controllers\crud\CRUDMessage;
11
use Ubiquity\controllers\crud\viewers\ModelViewer;
12
13
/**
14
 *
15
 * @author jc
16
 * @property \Ajax\php\ubiquity\JsUtils $jquery
17
 *
18
 */
19
trait MessagesTrait {
20
21
	/**
22
	 *
23
	 * @return ModelViewer
24
	 */
25
	abstract public function _getModelViewer();
26
27
	abstract public function _getFiles();
28
29 3
	protected function _showSimpleMessage(CRUDMessage $message, $staticName = null): HtmlMessage {
30 3
		return $this->showSimpleMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $message->getTimeout (), $staticName );
31
	}
32
33 17
	public function showSimpleMessage($content, $type, $title = null, $icon = "info", $timeout = NULL, $staticName = null, $closeAction = null): HtmlMessage {
34 17
		$semantic = $this->jquery->semantic ();
35 17
		if (! isset ( $staticName ))
36 13
			$staticName = "msg-" . rand ( 0, 50 );
37 17
		$message = $semantic->htmlMessage ( $staticName, $content, $type );
38 17
		if (isset ( $title )) {
39 12
			$message->addHeader ( $title );
40
		}
41 17
		if (isset ( $icon )) {
42 13
			$message->setIcon ( $icon );
43
		}
44 17
		if ($timeout !== '') {
45 14
			$message->setDismissable ();
46
		}
47 17
		if ($timeout != null) {
48 4
			$message->setTimeout ( 3000 );
49
		} elseif (isset ( $closeAction )) {
50 4
			$message->getOnClose ( $this->_getFiles ()->getAdminBaseRoute () . "/_closeMessage/" . $closeAction );
51
		}
52 17
		return $message;
53
	}
54
55 3
	protected function _showConfMessage(CRUDMessage $message, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
56 3
		return $this->showConfMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $url, $responseElement, $data, $attributes );
57
	}
58
59 3
	public function showConfMessage($content, $type, $title, $icon, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
60 3
		$messageDlg = $this->showSimpleMessage ( $content, $type, $title, $icon );
61 3
		$btOkay = new HtmlButton ( "bt-okay", "Confirm", "negative" );
62 3
		$btOkay->addIcon ( "check circle" );
63 3
		$btOkay->postOnClick ( $url, "{data:'" . $data . "'}", $responseElement, $attributes );
64 3
		$btCancel = new HtmlButton ( "bt-cancel-" . UString::cleanAttribute ( $url ), "Cancel" );
65 3
		$btCancel->addIcon ( "remove circle outline" );
66 3
		$btCancel->onClick ( $messageDlg->jsHide () );
67 3
		$messageDlg->addContent ( [ new HtmlDivider ( "" ),new HtmlSemDoubleElement ( "", "div", "", [ $btOkay->floatRight (),$btCancel->floatRight () ] ) ] );
68 3
		$this->_getModelViewer ()->onConfirmButtons ( $btOkay, $btCancel );
69 3
		return $messageDlg;
70
	}
71
}
72
73