addAnnotationForInterwikiLanguageLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
ccs 13
cts 13
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SIL;
4
5
use SMW\ParserData;
6
use SMW\Subobject;
7
use SMW\DIProperty;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
class LanguageLinkAnnotator {
16
17
	/**
18
	 * @var ParserData
19
	 */
20
	private $parserData;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param ParserData $parserData
26
	 */
27 8
	public function __construct( ParserData $parserData ) {
28 8
		$this->parserData = $parserData;
29 8
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * @param InterlanguageLink $interlanguageLink
35
	 *
36
	 * @return boolean
37
	 */
38 4
	public function hasDifferentLanguageAnnotation( InterlanguageLink $interlanguageLink ) {
39
40 4
		$propertyValues = $this->parserData->getSemanticData()->getPropertyValues(
41 4
			new DIProperty( PropertyRegistry::SIL_CONTAINER )
42
		);
43
44 4
		foreach ( $propertyValues as $value ) {
45 1
			if ( $value->getSubobjectname() !== $interlanguageLink->getContainerId() ) {
46 1
				return true;
47
			}
48
		}
49
50 3
		return false;
51
	}
52
53
	/**
54
	 * @since 1.3
55
	 *
56
	 * @return boolean
57
	 */
58 3
	public function canAddAnnotation() {
59
60 3
		if ( method_exists( $this->parserData, 'canModifySemanticData' ) ) {
61
			return $this->parserData->canModifySemanticData();
0 ignored issues
show
Bug introduced by
The method canModifySemanticData() does not seem to exist on object<SMW\ParserData>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
		}
63
64
		// SMW 3.0
65 3
		if ( method_exists( $this->parserData, 'canUse' ) ) {
66 3
			return $this->parserData->canUse();
67
		}
68
69
		return true;
70
	}
71
72
	/**
73
	 * @since 1.0
74
	 *
75
	 * @param InterlanguageLink $interlanguageLink
76
	 */
77 3
	public function addAnnotationForInterlanguageLink( InterlanguageLink $interlanguageLink ) {
78
79 3
		$subobject = new Subobject( $this->parserData->getTitle() );
80 3
		$subobject->setEmptyContainerForId( $interlanguageLink->getContainerId() );
81
82 3
		$subobject->getSemanticData()->addDataValue(
83 3
			$interlanguageLink->newLanguageDataValue()
84
		);
85
86 3
		$subobject->getSemanticData()->addDataValue(
87 3
			$interlanguageLink->newLinkReferenceDataValue()
88
		);
89
90 3
		$this->parserData->getSemanticData()->addPropertyObjectValue(
91 3
			$interlanguageLink->newContainerProperty(),
92 3
			$subobject->getContainer()
93
		);
94
95 3
		$this->parserData->pushSemanticDataToParserOutput();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\ParserData::pushSemanticDataToParserOutput() has been deprecated with message: since 3.0, use copyToParserOutput

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...
96 3
		$this->parserData->setSemanticDataStateToParserOutputProperty();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\ParserData::setSeman...oParserOutputProperty() has been deprecated with message: since 3.0, use pushSemanticDataToParserOutput

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...
97 3
	}
98
99
	/**
100
	 * @since 1.0
101
	 *
102
	 * @param InterwikiLanguageLink $interwikiLanguageLink
103
	 */
104 1
	public function addAnnotationForInterwikiLanguageLink( InterwikiLanguageLink $interwikiLanguageLink ) {
105
106 1
		$subobject = new Subobject( $this->parserData->getTitle() );
107 1
		$subobject->setEmptyContainerForId( $interwikiLanguageLink->getContainerId() );
108
109 1
		$subobject->getSemanticData()->addDataValue(
110 1
			$interwikiLanguageLink->newLanguageDataValue()
111
		);
112
113 1
		$subobject->getSemanticData()->addDataValue(
114 1
			$interwikiLanguageLink->newInterwikiReferenceDataValue()
115
		);
116
117 1
		$this->parserData->getSemanticData()->addPropertyObjectValue(
118 1
			$interwikiLanguageLink->newContainerProperty(),
119 1
			$subobject->getContainer()
120
		);
121
122 1
		$this->parserData->pushSemanticDataToParserOutput();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\ParserData::pushSemanticDataToParserOutput() has been deprecated with message: since 3.0, use copyToParserOutput

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...
123 1
		$this->parserData->setSemanticDataStateToParserOutputProperty();
0 ignored issues
show
Deprecated Code introduced by
The method SMW\ParserData::setSeman...oParserOutputProperty() has been deprecated with message: since 3.0, use pushSemanticDataToParserOutput

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...
124 1
	}
125
126
}
127