TitleParser::stringParse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace ParamProcessor;
4
5
use ValueParsers\ParseException;
6
use ValueParsers\StringValueParser;
7
8
/**
9
 * ValueParser that parses the string representation of a MediaWiki Title object.
10
 *
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class TitleParser extends StringValueParser {
15
16
	/**
17
	 * @see StringValueParser::stringParse
18
	 *
19
	 * @since 0.1
20
	 *
21
	 * @param string $value
22
	 *
23
	 * @return MediaWikiTitleValue
24
	 * @throws ParseException
25
	 */
26 8
	protected function stringParse( $value ) {
27 8
		$value = \Title::newFromText( $value );
28
29 8
		if ( is_null( $value ) ) {
30 2
			throw new ParseException( 'Not a title' );
31
		}
32
33 8
		return new MediaWikiTitleValue( $value );
34
	}
35
36
}