EntityIriParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PPP\Wikidata\ValueFormatters\JsonLd\Entity;
4
5
use Wikibase\DataModel\Entity\EntityIdParser;
6
use Wikibase\DataModel\Entity\EntityIdParsingException;
7
8
/**
9
 * @licence AGPLv3+
10
 * @author Thomas Pellissier Tanon
11
 */
12
class EntityIriParser implements EntityIdParser {
13
14
	const IRI_PATTERN = '/^https?:\/\/www.wikidata.org\/entity\/(.*)$/';
15
16
	/**
17
	 * @var EntityIdParser
18
	 */
19
	private $entityIdParser;
20
21 4
	public function __construct(EntityIdParser $entityIdParser) {
22 4
		$this->entityIdParser = $entityIdParser;
23 4
	}
24
25
	/**
26
	 * @see EntityIdParser::parse
27
	 */
28 4
	public function parse($entityIri) {
29 4
		if(preg_match(self::IRI_PATTERN, $entityIri, $m)) {
30 3
			return $this->entityIdParser->parse($m[1]);
31
		} else {
32 1
			throw new EntityIdParsingException('Invalid entity IRI');
33
		}
34
	}
35
}
36