Passed
Pull Request — master (#211)
by
unknown
02:26
created

FingerprintPatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A patchFingerprint() 0 26 5
1
<?php
2
3
namespace Wikibase\DataModel\Services\Diff;
4
5
use Diff\DiffOp\Diff\Diff;
6
use Diff\Patcher\PatcherException;
7
use Wikibase\DataModel\Services\Diff\Internal\AliasGroupListPatcher;
8
use Wikibase\DataModel\Term\Fingerprint;
9
10
/**
11
 * @since 3.13
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Jeroen De Dauw < [email protected] >
15
 * @author Thiemo Kreuz
16
 */
17
class FingerprintPatcher {
18
19
	/**
20
	 * @var TermListPatcher
21
	 */
22
	private $termListPatcher;
23
24
	/**
25
	 * @var AliasGroupListPatcher
26
	 */
27
	private $aliasGroupListPatcher;
28
29
	public function __construct() {
30
		$this->termListPatcher = new TermListPatcher();
31
		$this->aliasGroupListPatcher = new AliasGroupListPatcher();
32
	}
33
34
	/**
35
	 * @param Fingerprint $fingerprint
36
	 * @param Diff $patch typically an {@link EntityDiff}
37
	 *
38
	 * @throws PatcherException
39
	 */
40
	public function patchFingerprint( Fingerprint $fingerprint, Diff $patch ) {
41
		if ( !$patch->isAssociative() ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $patch->isAssociative() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
42
			throw new PatcherException( '$patch must be associative' );
43
		}
44
45
		if ( isset( $patch['label'] ) ) {
46
			$this->termListPatcher->patchTermList(
47
				$fingerprint->getLabels(),
48
				$patch['label']
49
			);
50
		}
51
52
		if ( isset( $patch['description'] ) ) {
53
			$this->termListPatcher->patchTermList(
54
				$fingerprint->getDescriptions(),
55
				$patch['description']
56
			);
57
		}
58
59
		if ( isset( $patch['aliases'] ) ) {
60
			$this->aliasGroupListPatcher->patchAliasGroupList(
61
				$fingerprint->getAliasGroups(),
62
				$patch['aliases']
63
			);
64
		}
65
	}
66
67
}
68