EntityIriParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 7 2
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