Passed
Push — master ( 5c767a...47de24 )
by Jean-Christophe
06:45
created

AjaxRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 14
rs 9.8333

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
namespace Ajax\semantic\components\validation;
3
4
use Ajax\JsUtils;
5
use Ajax\service\AjaxCall;
6
7
/**
8
 * Ajax\semantic\components\validation$AjaxRule
9
 * This class is part of phpmv-ui
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
class AjaxRule extends CustomRule {
16
17
	private $ajaxCall;
18
19
	public function __construct($type, $url, $params, $jsCallback = null, $method = 'post', $parameters = [], $prompt = NULL, $value = NULL) {
20
		parent::__construct($type, $prompt, $value);
21
		$parameters = \array_merge([
22
			'async' => false,
23
			'url' => $url,
24
			'params' => $params,
25
			'hasLoader' => false,
26
			'jsCallback' => $jsCallback,
27
			'dataType' => 'json',
28
			'stopPropagation' => false,
29
			'preventDefault' => false,
30
			'responseElement' => null
31
		], $parameters);
32
		$this->ajaxCall = new AjaxCall($method, $parameters);
33
	}
34
35
	public function compile(JsUtils $js) {
36
		$js->exec(Rule::custom($this->getType(), "function(value,ruleValue){var result=true;" . $this->ajaxCall->compile($js) . "return result;}"), true);
37
	}
38
}