Completed
Pull Request — master (#666)
by no
10:55 queued 07:27
created

TermFallback::getActualLanguageCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Term;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Immutable value object.
9
 *
10
 * @since 2.4.0
11
 *
12
 * @license GPL-2.0+
13
 * @author Jan Zerebecki < [email protected] >
14
 */
15
class TermFallback extends Term {
16
17
	/**
18
	 * @var string Actual language of the text.
19
	 */
20
	private $actualLanguageCode;
21
22
	/**
23
	 * @var string|null Source language if the text is a transliteration.
24
	 */
25
	private $sourceLanguageCode;
26
27
	/**
28
	 * @param string $requestedLanguageCode Requested language, not necessarily the language of the
29
	 * text.
30
	 * @param string $text
31
	 * @param string $actualLanguageCode Actual language of the text.
32
	 * @param string|null $sourceLanguageCode Source language if the text is a transliteration.
33
	 *
34
	 * @throws InvalidArgumentException
35
	 */
36
	public function __construct( $requestedLanguageCode, $text, $actualLanguageCode, $sourceLanguageCode ) {
37
		parent::__construct( $requestedLanguageCode, $text );
38
39
		if ( !is_string( $actualLanguageCode ) || $actualLanguageCode === '' ) {
40
			throw new InvalidArgumentException( '$actualLanguageCode must be a non-empty string' );
41
		}
42
43
		if ( !( $sourceLanguageCode === null
44
			|| ( is_string( $sourceLanguageCode ) && $sourceLanguageCode !== '' )
45
		) ) {
46
			throw new InvalidArgumentException( '$sourceLanguageCode must be a non-empty string or null' );
47
		}
48
49
		$this->actualLanguageCode = $actualLanguageCode;
50
		$this->sourceLanguageCode = $sourceLanguageCode;
51
	}
52
53
	/**
54
	 * @return string
55
	 */
56
	public function getActualLanguageCode() {
57
		return $this->actualLanguageCode;
58
	}
59
60
	/**
61
	 * @return string|null
62
	 */
63
	public function getSourceLanguageCode() {
64
		return $this->sourceLanguageCode;
65
	}
66
67
	/**
68
	 * @see Comparable::equals
69
	 *
70
	 * @param mixed $target
71
	 *
72
	 * @return bool
73
	 */
74
	public function equals( $target ) {
75
		if ( $this === $target ) {
76
			return true;
77
		}
78
79
		return $target instanceof self
80
			&& parent::equals( $target )
81
			&& $this->actualLanguageCode === $target->actualLanguageCode
82
			&& $this->sourceLanguageCode === $target->sourceLanguageCode;
83
	}
84
85
}
86