Passed
Push — developer ( 2a0d9f...47d6ff )
by Radosław
18:29
created

Vtiger_TaxMode_InventoryField::getDisplayValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 3
nc 4
nop 3
crap 12
1
<?php
2
3
/**
4
 * Inventory TaxMode Field Class.
5
 *
6
 * @package   InventoryField
7
 *
8
 * @copyright YetiForce S.A.
9
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 * @author    Radosław Skrzypczak <[email protected]>
12
 */
13
class Vtiger_TaxMode_InventoryField extends Vtiger_Basic_InventoryField
14
{
15
	protected $type = 'TaxMode';
16
	protected $defaultLabel = 'LBL_TAX_MODE';
17
	protected $defaultValue = '0';
18
	protected $columnName = 'taxmode';
19
	protected $dbType = 'smallint(1) DEFAULT 0';
20
	protected $modes = [0 => 'LBL_INV_TAX_MODE_GLOBAL', 1 => 'LBL_INDIVIDUAL'];
21
	protected $blocks = [0];
22
	protected $maximumLength = '-32768,32767';
23
	protected $purifyType = \App\Purifier::INTEGER;
24
25
	/** {@inheritdoc} */
26
	public function getDisplayValue($value, array $rowData = [], bool $rawText = false)
27
	{
28
		return '' !== $value && null !== $value ? \App\Language::translate($this->modes[$value], $this->getModuleName()) : '';
29
	}
30
31
	/** {@inheritdoc} */
32
	public function getDBValue($value, ?string $name = '')
33
	{
34
		return (int) $value;
35
	}
36 2
37
	/** {@inheritdoc} */
38 2
	public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null)
39
	{
40
		if (!is_numeric($value) || !isset($this->modes[$value])) {
41
			throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||$value", 406);
42
		}
43
	}
44 2
45
	/** {@inheritdoc} */
46 2
	public function getEditValue(array $itemData, string $column = '')
47
	{
48
		$value = parent::getEditValue($itemData, $column);
49 2
		return is_numeric($value) ? $value : Vtiger_Inventory_Model::getTaxesConfig('default_mode');
0 ignored issues
show
Unused Code introduced by
The call to Vtiger_Inventory_Model::getTaxesConfig() has too many arguments starting with 'default_mode'. ( Ignorable by Annotation )

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

49
		return is_numeric($value) ? $value : Vtiger_Inventory_Model::/** @scrutinizer ignore-call */ getTaxesConfig('default_mode');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
50
	}
51
52
	/** {@inheritdoc} */
53
	public function compare($value, $prevValue, string $column): bool
54
	{
55
		return (int) $value === (int) $prevValue;
56
	}
57
58
	/**
59
	 * Get available modes.
60
	 *
61
	 * @return array
62
	 */
63
	public function getModes(): array
64
	{
65
		return $this->modes;
66
	}
67
}
68