Completed
Push — master ( 2a57e9...d915e7 )
by Marius
10s
created

TrimmingStringNormalizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 7 2
1
<?php
2
3
namespace ValueParsers\Normalizers;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Most simple implementation of a StringNormalizer that does nothing but trimming whitespace, by
9
 * using the definition of "whitespace" in Unicode-enabled Perl regular expressions.
10
 *
11
 * @since 0.3.2
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Thiemo Kreuz
15
 */
16
class TrimmingStringNormalizer implements StringNormalizer {
17
18
	/**
19
	 * @param string $value
20
	 *
21
	 * @throws InvalidArgumentException if $value is not a string
22
	 * @return string the trimmed string
23
	 */
24 9
	public function normalize( $value ) {
25 9
		if ( !is_string( $value ) ) {
26 4
			throw new InvalidArgumentException( '$value must be a string' );
27
		}
28
29 5
		return preg_replace( '/^\s+|\s+$/u', '', $value );
30
	}
31
32
}
33