Completed
Push — master ( 379b27...5b49bb )
by
unknown
12s
created

PropertyPatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 54
ccs 21
cts 21
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A canPatchEntityType() 0 3 1
A patchEntity() 0 5 1
A assertIsProperty() 0 5 2
A patchProperty() 0 8 1
1
<?php
2
3
namespace Wikibase\DataModel\Services\Diff;
4
5
use InvalidArgumentException;
6
use Wikibase\DataModel\Entity\EntityDocument;
7
use Wikibase\DataModel\Entity\Property;
8
use Wikibase\DataModel\Services\Diff\Internal\FingerprintPatcher;
9
10
/**
11
 * @since 1.0
12
 *
13
 * @license GPL-2.0+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class PropertyPatcher implements EntityPatcherStrategy {
17
18
	/**
19
	 * @var FingerprintPatcher
20
	 */
21
	private $fingerprintPatcher;
22
23
	/**
24
	 * @var StatementListPatcher
25
	 */
26
	private $statementListPatcher;
27
28
	public function __construct() {
29 4
		$this->fingerprintPatcher = new FingerprintPatcher();
30 4
		$this->statementListPatcher = new StatementListPatcher();
31 4
	}
32 4
33
	/**
34
	 * @param string $entityType
35
	 *
36
	 * @return boolean
37
	 */
38
	public function canPatchEntityType( $entityType ) {
39 1
		return $entityType === 'property';
40 1
	}
41
42
	/**
43
	 * @param EntityDocument $entity
44
	 * @param EntityDiff $patch
45
	 *
46
	 * @throws InvalidArgumentException
47
	 */
48
	public function patchEntity( EntityDocument $entity, EntityDiff $patch ) {
49
		$this->assertIsProperty( $entity );
50 3
51 3
		$this->patchProperty( $entity, $patch );
0 ignored issues
show
Compatibility introduced by
$entity of type object<Wikibase\DataModel\Entity\EntityDocument> is not a sub-type of object<Wikibase\DataModel\Entity\Property>. It seems like you assume a concrete implementation of the interface Wikibase\DataModel\Entity\EntityDocument to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
52
	}
53 2
54 2
	private function assertIsProperty( EntityDocument $property ) {
55
		if ( !( $property instanceof Property ) ) {
56 3
			throw new InvalidArgumentException( '$property must be an instance of Property' );
57 3
		}
58 1
	}
59
60 2
	private function patchProperty( Property $property, EntityDiff $patch ) {
61
		$this->fingerprintPatcher->patchFingerprint( $property->getFingerprint(), $patch );
62 2
63 2
		$this->statementListPatcher->patchStatementList(
64
			$property->getStatements(),
65 2
			$patch->getClaimsDiff()
66 2
		);
67 2
	}
68 2
69
}
70