Completed
Push — master ( 69614a...9cb597 )
by mw
14s
created

isResourceBuilderFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SMW\Exporter\ResourceBuilders;
4
5
use SMW\Exporter\ResourceBuilder;
6
use SMW\DIProperty;
7
use SMWExporter as Exporter;
8
use SMW\DataValueFactory;
9
use SMWDataItem as DataItem;
10
use SMWExpData as ExpData;
11
use SMWExpLiteral as ExpLiteral;
12
13
/**
14
 * @private
15
 *
16
 * @license GNU GPL v2+
17
 * @since 2.5
18
 *
19
 * @author mwjames
20
 */
21
class PropertyDescriptionValueResourceBuilder extends PropertyValueResourceBuilder {
22
23
	/**
24
	 * @since 2.5
25
	 *
26
	 * {@inheritDoc}
27
	 */
28 15
	public function isResourceBuilderFor( DIProperty $property ) {
29 15
		return $property->getKey() === '_PDESC';
30
	}
31
32
	/**
33
	 * @since 2.5
34
	 *
35
	 * {@inheritDoc}
36
	 */
37 2
	public function addResourceValue( ExpData $expData, DIProperty $property, DataItem $dataItem ) {
38
39 2
		parent::addResourceValue( $expData, $property, $dataItem );
40
41 2
		$dataValue = DataValueFactory::getInstance()->newDataValueByItem(
42
			$dataItem,
43
			$property
44
		);
45
46 2
		$list = $dataValue->toArray();
47
48 2
		if ( !isset( $list['_TEXT'] ) || !isset( $list['_LCODE'] ) ) {
49
			return;
50
		}
51
52
		// Ussing `skos:scopeNote` instead of `skos:definition` since we can not
53
		// ensure that the description given by a user is complete.
54
		//
55
		// "skos:scopeNote supplies some, possibly partial, information about the
56
		// intended meaning of a concept ..."
57
		//
58
		// "skos:definition supplies a complete explanation of the intended
59
		// meaning of a concept."
60
		//
61
		// According to https://www.w3.org/TR/2009/NOTE-skos-primer-20090818/#secdocumentation
62
63 2
		$expData->addPropertyObjectValue(
64 2
			$this->exporter->getSpecialNsResource( 'skos', 'scopeNote' ),
0 ignored issues
show
Documentation introduced by
$this->exporter->getSpec...ce('skos', 'scopeNote') is of type object<SMW\Exporter\Element\ExpNsResource>, but the function expects a object<SMWExpNsResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65 2
			new ExpLiteral(
66 2
				(string)$list['_TEXT'],
67 2
				'http://www.w3.org/2001/XMLSchema#string',
68 2
				(string)$list['_LCODE'],
69
				$dataItem
70
			)
71
		);
72 2
	}
73
74
}
75