Passed
Push — currentLimits ( 82fe71...f9050f )
by no
03:50
created

EntityRedirect::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Entity;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Represents a redirect from one EntityId to another.
9
 *
10
 * @since 4.2
11
 *
12
 * @license GPL-2.0+
13
 * @author Daniel Kinzler
14
 */
15
class EntityRedirect {
16
17
	/**
18
	 * @var EntityId
19
	 */
20
	private $entityId;
21
22
	/**
23
	 * @var EntityId
24
	 */
25
	private $targetId;
26
27
	/**
28
	 * @param EntityId $entityId
29
	 * @param EntityId $targetId
30
	 *
31
	 * @throws InvalidArgumentException
32
	 */
33
	public function __construct( EntityId $entityId, EntityId $targetId ) {
34
		if ( $entityId->getEntityType() !== $targetId->getEntityType() ) {
35
			throw new InvalidArgumentException(
36
				'$entityId and $targetId must refer to the same kind of entity.'
37
			);
38
		}
39
40
		$this->entityId = $entityId;
41
		$this->targetId = $targetId;
42
	}
43
44
	/**
45
	 * @return EntityId
46
	 */
47
	public function getEntityId() {
48
		return $this->entityId;
49
	}
50
51
	/**
52
	 * @return EntityId
53
	 */
54
	public function getTargetId() {
55
		return $this->targetId;
56
	}
57
58
	/**
59
	 * @param mixed $that
60
	 *
61
	 * @return bool
62
	 */
63
	public function equals( $that ) {
64
		if ( $that === $this ) {
65
			return true;
66
		}
67
68
		return is_object( $that )
69
			&& get_class( $that ) === get_called_class()
70
			&& $this->entityId->equals( $that->entityId )
71
			&& $this->targetId->equals( $that->targetId );
72
	}
73
74
	/**
75
	 * @since 4.4
76
	 *
77
	 * @return string
78
	 */
79
	public function __toString() {
80
		return $this->entityId . '->' . $this->targetId;
81
	}
82
83
}
84