Completed
Push — master ( 4f998c...d47164 )
by Josh
15:35
created

TimestampFilter::filter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Parser\AttributeFilters;
9
10
class TimestampFilter
11
{
12
	/**
13
	* Filter a timestamp value
14
	*
15
	* @param  string $attrValue Original value
16
	* @return mixed             Filtered value, or FALSE if invalid
17
	*/
18
	public static function filter($attrValue)
19
	{
20
		if (preg_match('/^(?=\\d)(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?$/D', $attrValue, $m))
21
		{
22
			$m += [0, 0, 0, 0];
23
24
			return intval($m[1]) * 3600 + intval($m[2]) * 60 + intval($m[3]);
25
		}
26
27
		return NumericFilter::filterUint($attrValue);
28
	}
29
}