Completed
Pull Request — master (#583)
by no
66:41 queued 57:56
created

EntityRedirect   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 10
c 2
b 0
f 2
lcom 1
cbo 1
dl 0
loc 64
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getEntityId() 0 3 1
A getTargetId() 0 3 1
B equals() 0 10 5
A __toString() 0 3 1
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
 * @licence GNU GPL v2+
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 2
	public function __construct( EntityId $entityId, EntityId $targetId ) {
34 2
		if ( $entityId->getEntityType() !== $targetId->getEntityType() ) {
35 1
			throw new InvalidArgumentException(
36
				'$entityId and $targetId must refer to the same kind of entity.'
37 1
			);
38
		}
39
40 1
		$this->entityId = $entityId;
41 1
		$this->targetId = $targetId;
42 1
	}
43
44
	/**
45
	 * @return EntityId
46
	 */
47 1
	public function getEntityId() {
48 1
		return $this->entityId;
49
	}
50
51
	/**
52
	 * @return EntityId
53
	 */
54 1
	public function getTargetId() {
55 1
		return $this->targetId;
56
	}
57
58
	/**
59
	 * @param EntityRedirect $that
60
	 *
61
	 * @return bool
62
	 */
63 9
	public function equals( $that ) {
64 9
		if ( $that === $this ) {
65 1
			return true;
66
		}
67
68 8
		return is_object( $that )
69 8
			&& get_class( $that ) === get_called_class()
70 8
			&& $this->entityId->equals( $that->entityId )
71 8
			&& $this->targetId->equals( $that->targetId );
72
	}
73
74
	function __toString() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __toString.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
75
		return $this->entityId . '->' . $this->targetId;
76
	}
77
78
}
79