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