Passed
Pull Request — master (#211)
by
unknown
03:18
created

FingerprintPatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 53
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 1.0
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
	 * @since 1.0
36
	 *
37
	 * @param Fingerprint $fingerprint
38
	 * @param Diff $patch typically an {@link EntityDiff}
39
	 *
40
	 * @throws PatcherException
41
	 */
42
	public function patchFingerprint( Fingerprint $fingerprint, Diff $patch ) {
43
		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...
44
			throw new PatcherException( '$patch must be associative' );
45
		}
46
47
		if ( isset( $patch['label'] ) ) {
48
			$this->termListPatcher->patchTermList(
49
				$fingerprint->getLabels(),
50
				$patch['label']
51
			);
52
		}
53
54
		if ( isset( $patch['description'] ) ) {
55
			$this->termListPatcher->patchTermList(
56
				$fingerprint->getDescriptions(),
57
				$patch['description']
58
			);
59
		}
60
61
		if ( isset( $patch['aliases'] ) ) {
62
			$this->aliasGroupListPatcher->patchAliasGroupList(
63
				$fingerprint->getAliasGroups(),
64
				$patch['aliases']
65
			);
66
		}
67
	}
68
69
}
70