InterwikiLanguageLink   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 86
rs 10
c 0
b 0
f 0
ccs 21
cts 21
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A getLanguageCode() 0 3 1
A getInterwikiReference() 0 3 1
A getContainerId() 0 3 1
A getHash() 0 3 1
A newContainerProperty() 0 3 1
A newLanguageDataValue() 0 6 1
A newInterwikiReferenceDataValue() 0 6 1
1
<?php
2
3
namespace SIL;
4
5
use SMW\DataValueFactory;
6
use SMW\DIProperty;
7
use SMW\DIWikiPage;
8
9
use SMWDIBlob as DIBlob;
10
11
use Title;
12
13
/**
14
 * Represents an object for a manual annotation such as [[en:Foo]] where
15
 * en: is being specified as interwiki
16
 *
17
 * @license GNU GPL v2+
18
 * @since 1.0
19
 *
20
 * @author mwjames
21
 */
22
class InterwikiLanguageLink {
23
24
	/**
25
	 * @var Title
26
	 */
27
	private $interwikiLink;
28
29
	/**
30
	 * @since 1.0
31
	 *
32
	 * @param string $interwikiLink
33
	 */
34 6
	public function __construct( $interwikiLink ) {
35 6
		$this->interwikiLink = $interwikiLink instanceOf Title ? $interwikiLink : Title::newFromText( $interwikiLink );
36 6
	}
37
38
	/**
39
	 * @since 1.0
40
	 *
41
	 * @return string
42
	 */
43 4
	public function getLanguageCode() {
44 4
		return $this->interwikiLink->getInterwiki();
45
	}
46
47
	/**
48
	 * @since 1.0
49
	 *
50
	 * @return Title
51
	 */
52 4
	public function getInterwikiReference() {
53 4
		return $this->interwikiLink;
54
	}
55
56
	/**
57
	 * @since 1.0
58
	 *
59
	 * @return string
60
	 */
61 1
	public function getContainerId() {
62 1
		return 'iwl.'. $this->getLanguageCode();
63
	}
64
65
	/**
66
	 * @since 1.0
67
	 *
68
	 * @return string
69
	 */
70 1
	public function getHash() {
71 1
		return $this->getLanguageCode() . '#' . $this->getInterwikiReference()->getPrefixedText();
72
	}
73
74
	/**
75
	 * @since 1.0
76
	 *
77
	 * @return DataValue
78
	 */
79 1
	public function newLanguageDataValue() {
80 1
		return DataValueFactory::getInstance()->newDataItemValue(
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DataValueFactory::newDataItemValue() has been deprecated with message: since 2.4, use DataValueFactory::newDataValueByItem

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
81 1
			new DIBlob( $this->getLanguageCode() ),
82 1
			new DIProperty( PropertyRegistry::SIL_IWL_LANG )
83
		);
84
	}
85
86
	/**
87
	 * @since 1.0
88
	 *
89
	 * @return DataValue
90
	 */
91 1
	public function newInterwikiReferenceDataValue() {
92 1
		return DataValueFactory::getInstance()->newDataItemValue(
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DataValueFactory::newDataItemValue() has been deprecated with message: since 2.4, use DataValueFactory::newDataValueByItem

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
93 1
			DIWikiPage::newFromTitle( $this->getInterwikiReference() ),
94 1
			new DIProperty( PropertyRegistry::SIL_IWL_REF )
95
		);
96
	}
97
98
	/**
99
	 * @since 1.0
100
	 *
101
	 * @return DIProperty
102
	 */
103 1
	public function newContainerProperty() {
104 1
		return new DIProperty( PropertyRegistry::SIL_CONTAINER );
105
	}
106
107
}
108