JsonLdPropertyFormatterTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validProvider() 0 16 1
A getInstance() 0 6 1
1
<?php
2
3
namespace PPP\Wikidata\ValueFormatters\JsonLd\Entity;
4
5
use PPP\Wikidata\ValueFormatters\JsonLd\JsonLdFormatterTestBase;
6
use ValueFormatters\FormatterOptions;
7
use ValueFormatters\ValueFormatter;
8
use Wikibase\DataModel\Entity\Property;
9
use Wikibase\DataModel\Entity\PropertyId;
10
11
/**
12
 * @covers PPP\Wikidata\ValueFormatters\JsonLd\Entity\JsonLdPropertyFormatter
13
 *
14
 * @licence AGPLv3+
15
 * @author Thomas Pellissier Tanon
16
 */
17
class JsonLdPropertyFormatterTest extends JsonLdFormatterTestBase {
18
19
	/**
20
	 * @see JsonLdFormatterTestBase::validProvider
21
	 */
22
	public function validProvider() {
23
		return array(
24
			array(
25
				new Property(new PropertyId('P214'), null, 'string'),
26
				(object) array(
27
					'@type' => 'Property',
28
					'@id' => 'http://www.wikidata.org/entity/P214',
29
					'name' => 'P214'
30
				),
31
				new FormatterOptions(array(
32
					ValueFormatter::OPT_LANG => 'en',
33
					JsonLdEntityFormatter::OPT_ENTITY_BASE_URI => 'http://www.wikidata.org/entity/'
34
				))
35
			)
36
		);
37
	}
38
39
	/**
40
	 * @see JsonLdFormatterTestBase::getInstance
41
	 */
42
	protected function getInstance(FormatterOptions $options = null) {
43
		return new JsonLdPropertyFormatter(
44
			new JsonLdEntityFormatter($options),
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 42 can be null; however, PPP\Wikidata\ValueFormat...ormatter::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
45
			$options
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 42 can be null; however, PPP\Wikidata\ValueFormat...ormatter::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
46
		);
47
	}
48
}
49