PropertySetStatementFilter::statementMatches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Wikibase\DataModel\Services\Statement\Filter;
4
5
use Wikibase\DataModel\Statement\Statement;
6
use Wikibase\DataModel\Statement\StatementFilter;
7
8
/**
9
 * A filter that only accepts statements with specific property ids, and rejects all other
10
 * properties.
11
 *
12
 * @since 3.2
13
 *
14
 * @license GPL-2.0-or-later
15
 * @author Thiemo Kreuz
16
 */
17
class PropertySetStatementFilter implements StatementFilter {
18
19
	/**
20
	 * @since 3.3
21
	 */
22
	public const FILTER_TYPE = 'propertySet';
23
24 9
	/**
25 9
	 * @var string[]
26 9
	 */
27
	private $propertyIds;
28
29
	/**
30
	 * @param string[]|string $propertyIds One or more property id serializations.
31
	 */
32
	public function __construct( $propertyIds ) {
33
		$this->propertyIds = (array)$propertyIds;
34
	}
35 9
36 9
	/**
37 9
	 * @see StatementFilter::statementMatches
38
	 *
39
	 * @param Statement $statement
40
	 *
41
	 * @return bool
42
	 */
43
	public function statementMatches( Statement $statement ) {
44
		$id = $statement->getPropertyId()->getSerialization();
45
		return in_array( $id, $this->propertyIds );
46
	}
47
48
}
49