ReferencedEntityIdLookupException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 23
rs 9.9
1
<?php
2
3
namespace Wikibase\DataModel\Services\Lookup;
4
5
use Exception;
6
use RuntimeException;
7
use Wikibase\DataModel\Entity\EntityId;
8
use Wikibase\DataModel\Entity\PropertyId;
9
10
/**
11
 * @since 3.10
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Marius Hoch
15
 */
16
class ReferencedEntityIdLookupException extends RuntimeException {
17
18
	/**
19
	 * @var EntityId
20
	 */
21
	private $fromId;
22
23
	/**
24
	 * @var PropertyId
25
	 */
26
	private $propertyId;
27
28
	/**
29
	 * @var EntityId[]
30
	 */
31
	private $toIds;
32
33
	/**
34
	 * @param EntityId $fromId
35
	 * @param PropertyId $propertyId
36
	 * @param EntityId[] $toIds
37
	 * @param string|null $message
38
	 * @param Exception|null $previous
39
	 */
40
	public function __construct(
41
		EntityId $fromId,
42
		PropertyId $propertyId,
43
		array $toIds,
44
		$message = null,
45
		?Exception $previous = null
46
	) {
47
		$this->fromId = $fromId;
48
		$this->propertyId = $propertyId;
49
		$this->toIds = $toIds;
50
51
		$targets = array_map(
52
			static function ( EntityId $entityId ) {
53
				return $entityId->getSerialization();
54
			},
55
			$toIds
56
		);
57
		$targets = implode( ', ', $targets );
58
59
		$message = $message ?: 'Referenced entity id lookup failed. Tried to find a referenced entity out of ' .
60
			$targets . ' linked from ' . $fromId->getSerialization() . ' via ' . $propertyId->getSerialization();
61
62
		parent::__construct( $message, 0, $previous );
63
	}
64
65
}
66