Passed
Push — master ( e48b7c...1886e0 )
by Jean-Christophe
25:18 queued 16:06
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, $toast = false): HtmlMessage {
30 3
		return $this->showSimpleMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $message->getTimeout (), $staticName, null, $toast );
31
	}
32
33 18
	public function showSimpleMessage($content, $type, $title = null, $icon = "info", $timeout = NULL, $staticName = null, $closeAction = null, $toast = false): HtmlMessage {
34 18
		$semantic = $this->jquery->semantic ();
35 18
		if (! isset ( $staticName ))
36 14
			$staticName = "msg-" . rand ( 0, 50 );
37 18
		$message = $semantic->htmlMessage ( $staticName, $content, $type );
38 18
		if (isset ( $title )) {
39 13
			$message->addHeader ( $title );
40
		}
41 18
		if (isset ( $icon )) {
42 14
			$message->setIcon ( $icon );
43
		}
44 18
		if ($timeout !== '') {
45 15
			$message->setDismissable ();
46
		}
47 18
		if ($timeout != null) {
48 4
			$message->setTimeout ( 3000 );
49
		} elseif (isset ( $closeAction )) {
50 4
			$message->getOnClose ( $this->_getFiles ()->getAdminBaseRoute () . "/_closeMessage/" . $closeAction );
51
		}
52 18
		if ($toast) {
53
			$message->asToast ();
0 ignored issues
show
Bug introduced by
The method asToast() does not exist on Ajax\semantic\html\collections\HtmlMessage. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
			$message->/** @scrutinizer ignore-call */ 
54
             asToast ();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
		}
55 18
		return $message;
56
	}
57
58 3
	protected function _showConfMessage(CRUDMessage $message, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
59 3
		return $this->showConfMessage ( $message->getMessage (), $message->getType (), $message->getTitle (), $message->getIcon (), $url, $responseElement, $data, $attributes );
60
	}
61
62 3
	public function showConfMessage($content, $type, $title, $icon, $url, $responseElement, $data, $attributes = NULL): HtmlMessage {
63 3
		$messageDlg = $this->showSimpleMessage ( $content, $type, $title, $icon );
64 3
		$btOkay = new HtmlButton ( "bt-okay", "Confirm", "negative" );
65 3
		$btOkay->addIcon ( "check circle" );
66 3
		$btOkay->postOnClick ( $url, "{data:'" . $data . "'}", $responseElement, $attributes );
67 3
		$btCancel = new HtmlButton ( "bt-cancel-" . UString::cleanAttribute ( $url ), "Cancel" );
68 3
		$btCancel->addIcon ( "remove circle outline" );
69 3
		$btCancel->onClick ( $messageDlg->jsHide () );
70 3
		$messageDlg->addContent ( [ new HtmlDivider ( "" ),new HtmlSemDoubleElement ( "", "div", "", [ $btOkay->floatRight (),$btCancel->floatRight () ] ) ] );
71 3
		$this->_getModelViewer ()->onConfirmButtons ( $btOkay, $btCancel );
72 3
		return $messageDlg;
73
	}
74
}
75
76