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

HashmapFilter::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 3
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 HashmapFilter
11
{
12
	/**
13
	* Filter a value through a hash map
14
	*
15
	* @param  string $attrValue Original value
16
	* @param  array  $map       Associative array
17
	* @param  bool   $strict    Whether this map is strict (values with no match are invalid)
18
	* @return mixed             Filtered value, or FALSE if invalid
19
	*/
20 4
	public static function filter($attrValue, array $map, $strict)
21
	{
22 4
		if (isset($map[$attrValue]))
23
		{
24 1
			return $map[$attrValue];
25
		}
26
27 3
		return ($strict) ? false : $attrValue;
28
	}
29
}