Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
15 / 24
80.00% covered (warning)
80.00%
8 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexemeDiff
62.50% covered (warning)
62.50%
15 / 24
80.00% covered (warning)
80.00%
8 / 10
32.24
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getLemmasDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLexicalCategoryDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLanguageDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFormsDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSensesDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isEmpty
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
8
 getNextFormIdDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNextSenseIdDiff
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3// @phan-file-suppress PhanPluginNeverReturnMethod
4
5namespace Wikibase\Lexeme\Domain\Diff;
6
7use Diff\DiffOp\Diff\Diff;
8use Diff\DiffOp\DiffOp;
9use Wikibase\DataModel\Services\Diff\EntityDiff;
10
11/**
12 * Represents a diff between two lexemes.
13 *
14 * @since 1.0
15 *
16 * @license GPL-2.0-or-later
17 * @author Amir Sarabadani <ladsgroup@gmail.com>
18 */
19class LexemeDiff extends EntityDiff {
20
21    /**
22     * @param DiffOp[] $operations
23     */
24    public function __construct( array $operations = [] ) {
25        // TODO Probably can be removed. Does it do anything useful?
26        $this->fixSubstructureDiff( $operations, 'lemmas' );
27        $this->fixSubstructureDiff( $operations, 'lexicalCategory' );
28        $this->fixSubstructureDiff( $operations, 'language' );
29        $this->fixSubstructureDiff( $operations, 'forms' );
30        $this->fixSubstructureDiff( $operations, 'senses' );
31        $this->fixSubstructureDiff( $operations, 'nextFormId' );
32        $this->fixSubstructureDiff( $operations, 'nextSenseId' );
33
34        parent::__construct( $operations );
35    }
36
37    /**
38     * Returns a Diff object with the lemma differences.
39     *
40     * @return Diff
41     */
42    public function getLemmasDiff() {
43        return $this['lemmas'] ?? new Diff( [], true );
44    }
45
46    /**
47     * Returns a Diff object with the lexical category differences.
48     *
49     * @return Diff
50     */
51    public function getLexicalCategoryDiff() {
52        return $this['lexicalCategory'] ?? new Diff( [], true );
53    }
54
55    /**
56     * Returns a Diff object with the language differences.
57     *
58     * @return Diff
59     */
60    public function getLanguageDiff() {
61        return $this['language'] ?? new Diff( [], true );
62    }
63
64    /**
65     * @return Diff
66     */
67    public function getFormsDiff() {
68        return $this['forms'] ?? new Diff( [], true );
69    }
70
71    /**
72     * @return Diff
73     */
74    public function getSensesDiff() {
75        return $this['senses'] ?? new Diff( [], true );
76    }
77
78    /**
79     * Returns if there are any changes (equivalent to: any differences between the entities).
80     *
81     * @return bool
82     */
83    public function isEmpty(): bool {
84        // FIXME: Needs to be fixed, otherwise conflict resolution may lead to unexpected results
85        return $this->getLemmasDiff()->isEmpty()
86            && $this->getLexicalCategoryDiff()->isEmpty()
87            && $this->getLanguageDiff()->isEmpty()
88            && $this->getClaimsDiff()->isEmpty()
89            && $this->getFormsDiff()->isEmpty()
90            && $this->getSensesDiff()->isEmpty()
91            && $this->getNextFormIdDiff()->isEmpty()
92            && $this->getNextSenseIdDiff()->isEmpty();
93    }
94
95    public function getNextFormIdDiff(): Diff {
96        return $this['nextFormId'] ?? new Diff( [], true );
97    }
98
99    public function getNextSenseIdDiff(): Diff {
100        return $this['nextSenseId'] ?? new Diff( [], true );
101    }
102
103    public function toArray( ?callable $valueConverter = null ): array {
104        throw new \LogicException( 'toArray() is not implemented' );
105    }
106
107}