MessagesTrait::_showConfMessage()   A
last analyzed

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
c 0
b 0
f 0
dl 0
loc 11
ccs 11
cts 11
cp 1
rs 9.9332
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 protected function _getModelViewer();
26
27
	abstract public function _getFiles();
28
29 3
	protected function showSimpleMessage_(CRUDMessage $message, $staticName = null, $toast = false): HtmlMessage {
30 3
		return $this->_showSimpleMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $message->getTimeout (), $staticName, null, $toast );
31
	}
32
33 17
	public function _showSimpleMessage($content, $type, $title = null, $icon = "info", $timeout = NULL, $staticName = null, $closeAction = null, $toast = false): HtmlMessage {
34 17
		$semantic = $this->jquery->semantic ();
35 17
		if (! isset ( $staticName ))
36 11
			$staticName = "msg-" . rand ( 0, 50 );
37 17
			if(isset($this->style)){
38 14
				$type.=' '.$this->style;
39
			}
40 17
		$message = $semantic->htmlMessage ( $staticName, $content, $type );
41 17
		if (isset ( $title )) {
42 17
			$message->addHeader ( $title );
43
		}
44 17
		if (isset ( $icon )) {
45 16
			$message->setIcon ( $icon );
46
		}
47 17
		if ($timeout !== '') {
48 17
			$message->setDismissable ();
49
		}
50 17
		if ($timeout != null) {
51 4
			$message->setTimeout ( 3000 );
52
		} elseif (isset ( $closeAction )) {
53 4
			$message->getOnClose ( $this->_getFiles ()->getAdminBaseRoute () . "/_closeMessage/" . $closeAction );
54
		}
55 17
		if ($toast) {
56
			$message->asToast ($toast);
57
		}
58 17
		return $message;
59
	}
60
61 3
	protected function showConfMessage_(CRUDMessage $message, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
62 3
		return $this->_showConfMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $url, $responseElement, $data, $attributes );
63
	}
64
65 3
	protected function _showConfMessage($content, $type, $title, $icon, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
66 3
		$messageDlg = $this->_showSimpleMessage ( $content, $type, $title, $icon );
67 3
		$btOkay = new HtmlButton ( "bt-okay", "Confirm", "negative" );
68 3
		$btOkay->addIcon ( "check circle" );
69 3
		$btOkay->postOnClick ( $url, "{data:'" . $data . "'}", $responseElement, $attributes );
70 3
		$btCancel = new HtmlButton ( "bt-cancel-" . UString::cleanAttribute ( $url ), "Cancel" );
71 3
		$btCancel->addIcon ( "remove circle outline" );
72 3
		$btCancel->onClick ( $messageDlg->jsHide () );
73 3
		$messageDlg->addContent ( [ new HtmlDivider ( "" ),new HtmlSemDoubleElement ( "", "div", "", [ $btOkay->floatRight (),$btCancel->floatRight () ] ) ] );
74 3
		$this->_getModelViewer ()->onConfirmButtons ( $btOkay, $btCancel );
75 3
		return $messageDlg;
76
	}
77
}
78
79