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

MapFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 12 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
}