Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
62 / 62 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
LexemeDiffVisualizer | |
100.00% |
62 / 62 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
visualizeEntityContentDiff | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
visualizeEntityDiff | |
100.00% |
54 / 54 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\Presentation\Diff; |
4 | |
5 | use Diff\DiffOp\Diff\Diff; |
6 | use MessageLocalizer; |
7 | use Wikibase\Repo\Content\EntityContentDiff; |
8 | use Wikibase\Repo\Diff\BasicDiffView; |
9 | use Wikibase\Repo\Diff\BasicEntityDiffVisualizer; |
10 | use Wikibase\Repo\Diff\ClaimDiffer; |
11 | use Wikibase\Repo\Diff\ClaimDifferenceVisualizer; |
12 | use Wikibase\Repo\Diff\EntityDiffVisualizer; |
13 | |
14 | /** |
15 | * @license GPL-2.0-or-later |
16 | * @author Amir Sarabadani |
17 | */ |
18 | class LexemeDiffVisualizer implements EntityDiffVisualizer { |
19 | |
20 | /** |
21 | * @var MessageLocalizer |
22 | */ |
23 | private $messageLocalizer; |
24 | |
25 | /** |
26 | * @var BasicEntityDiffVisualizer |
27 | */ |
28 | private $basicEntityDiffVisualizer; |
29 | |
30 | /** |
31 | * @var ClaimDiffer |
32 | */ |
33 | private $claimDiffer; |
34 | |
35 | /** |
36 | * @var ClaimDifferenceVisualizer |
37 | */ |
38 | private $claimDiffVisualizer; |
39 | |
40 | /** |
41 | * @var ItemReferenceDifferenceVisualizer |
42 | */ |
43 | private $itemReferenceDifferenceVisualizer; |
44 | |
45 | public function __construct( |
46 | MessageLocalizer $messageLocalizer, |
47 | EntityDiffVisualizer $basicEntityDiffVisualizer, |
48 | ClaimDiffer $claimDiffer, |
49 | ClaimDifferenceVisualizer $claimDiffView, |
50 | ItemReferenceDifferenceVisualizer $itemReferenceDifferenceVisualizer |
51 | ) { |
52 | $this->messageLocalizer = $messageLocalizer; |
53 | $this->basicEntityDiffVisualizer = $basicEntityDiffVisualizer; |
54 | $this->claimDiffer = $claimDiffer; |
55 | $this->claimDiffVisualizer = $claimDiffView; |
56 | $this->itemReferenceDifferenceVisualizer = $itemReferenceDifferenceVisualizer; |
57 | } |
58 | |
59 | /** |
60 | * @param EntityContentDiff $diff |
61 | * |
62 | * @return string HTML |
63 | */ |
64 | public function visualizeEntityContentDiff( EntityContentDiff $diff ) { |
65 | if ( $diff->isEmpty() ) { |
66 | return ''; |
67 | } |
68 | |
69 | return $this->visualizeEntityDiff( $diff ); |
70 | } |
71 | |
72 | /** |
73 | * @return string HTML |
74 | * @suppress PhanUndeclaredMethod |
75 | */ |
76 | private function visualizeEntityDiff( EntityContentDiff $entityContentDiff ) { |
77 | $lexemeDiff = $entityContentDiff->getEntityDiff(); |
78 | |
79 | $lemmaDiffView = new BasicDiffView( |
80 | [], |
81 | new Diff( |
82 | [ |
83 | $this->messageLocalizer->msg( 'wikibaselexeme-diffview-lemma' )->text() => |
84 | $lexemeDiff->getLemmasDiff(), |
85 | ], |
86 | true |
87 | ) |
88 | ); |
89 | |
90 | $lexicalCategoryDiffHTML = $this->itemReferenceDifferenceVisualizer->visualize( |
91 | $this->messageLocalizer->msg( 'wikibaselexeme-diffview-lexical-category' )->text(), |
92 | $lexemeDiff->getLexicalCategoryDiff() |
93 | ); |
94 | |
95 | $languageDiffHTML = $this->itemReferenceDifferenceVisualizer->visualize( |
96 | $this->messageLocalizer->msg( 'wikibaselexeme-diffview-language' )->text(), |
97 | $lexemeDiff->getLanguageDiff() |
98 | ); |
99 | |
100 | $lexemeStatementDiffHTML = $this->basicEntityDiffVisualizer |
101 | ->visualizeEntityContentDiff( $entityContentDiff ); |
102 | |
103 | $formDiffView = new FormDiffView( |
104 | [], |
105 | new Diff( |
106 | [ |
107 | $this->messageLocalizer->msg( 'wikibaselexeme-diffview-form' )->text() => |
108 | $lexemeDiff->getFormsDiff(), |
109 | ], |
110 | true |
111 | ), |
112 | $this->claimDiffer, |
113 | $this->claimDiffVisualizer, |
114 | $this->itemReferenceDifferenceVisualizer, |
115 | $this->messageLocalizer |
116 | ); |
117 | |
118 | $senseDiffView = new SenseDiffView( |
119 | [], |
120 | new Diff( |
121 | [ |
122 | $this->messageLocalizer->msg( 'wikibaselexeme-diffview-sense' )->text() => |
123 | $lexemeDiff->getSensesDiff(), |
124 | ], |
125 | true |
126 | ), |
127 | $this->claimDiffer, |
128 | $this->claimDiffVisualizer, |
129 | $this->messageLocalizer |
130 | ); |
131 | |
132 | return $lemmaDiffView->getHtml() . |
133 | $lexicalCategoryDiffHTML . |
134 | $languageDiffHTML . |
135 | $lexemeStatementDiffHTML . |
136 | $senseDiffView->getHtml() . |
137 | $formDiffView->getHtml(); |
138 | } |
139 | |
140 | } |