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

Vtiger_ItemNumber_InventoryField::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 4
crap 20
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