Passed
Push — developer ( 5a7d78...6a35f4 )
by Radosław
17:06
created

Vtiger_ItemNumber_InventoryField   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 6
eloc 9
dl 0
loc 25
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDBValue() 0 3 1
A validate() 0 4 4
A compare() 0 3 1
1
<?php
2
3
/**
4
 * Inventory Item Number 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_ItemNumber_InventoryField extends Vtiger_Basic_InventoryField
14
{
15
	protected $type = 'ItemNumber';
16
	protected $defaultLabel = 'LBL_ITEM_NUMBER';
17
	protected $columnName = 'seq';
18
	protected $purifyType = \App\Purifier::INTEGER;
19
20
	/** {@inheritdoc} */
21
	public function getDBValue($value, ?string $name = '')
22
	{
23
		return (int) $value;
24
	}
25
26
	/** {@inheritdoc} */
27
	public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null)
28
	{
29
		if ($value && (!is_numeric($value) || (string) $value !== (string) filter_var($value, FILTER_VALIDATE_INT))) {
30
			throw new \App\Exceptions\Security('ERR_ILLEGAL_FIELD_VALUE||' . $columnName . '||' . $this->getModuleName() . '||' . $value, 406);
31 1
		}
32
	}
33 1
34
	/** {@inheritdoc} */
35
	public function compare($value, $prevValue, string $column): bool
36
	{
37
		return (int) $value === (int) $prevValue;
38
	}
39
}
40