Completed
Push — master ( 803d3c...9ccb75 )
by Josh
12:51
created

MapFilter::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 3
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 MapFilter
11
{
12
	/**
13
	* Filter a mapped value
14
	*
15
	* NOTE: if there's no match, the original value is returned
16
	*
17
	* @param  string $attrValue Original value
18
	* @param  array  $map       List in the form [[<regexp>, <value>]]
19
	* @return mixed             Filtered value, or FALSE if invalid
20
	*/
21 3
	public static function filter($attrValue, array $map)
22
	{
23 3
		foreach ($map as $pair)
24
		{
25 3
			if (preg_match($pair[0], $attrValue))
26
			{
27 3
				return $pair[1];
28
			}
29
		}
30
31 1
		return $attrValue;
32
	}
33
}