Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
DiffFormatterUtils
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 createHeader
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 createAddedLine
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 createDeletedLine
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 createLineWrapper
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace ProofreadPage;
4
5use MediaWiki\Html\Html;
6
7/**
8 * @license GPL-2.0-or-later
9 *
10 * Utility functions to format diffs
11 */
12class DiffFormatterUtils {
13
14    /**
15     * Create an header in the two columns
16     *
17     * @param string $text the header HTML
18     * @return string
19     */
20    public function createHeader( $text ) {
21        return Html::openElement( 'tr' ) .
22            Html::rawElement( 'td', [ 'colspan' => '2', 'class' => 'diff-lineno' ], $text ) .
23            Html::rawElement( 'td', [ 'colspan' => '2', 'class' => 'diff-lineno' ], $text ) .
24            Html::closeElement( 'tr' );
25    }
26
27    /**
28     * Output an added line
29     *
30     * @param string $content the content of the line
31     * @return string
32     */
33    public function createAddedLine( $content ) {
34        return $this->createLineWrapper(
35            Html::element( 'ins', [ 'class' => 'diffchange diffchange-inline' ], $content ),
36            'diff-addedline',
37            '+'
38        );
39    }
40
41    /**
42     * Output a deleted line
43     *
44     * @param string $content the content of the line
45     * @return string
46     */
47    public function createDeletedLine( $content ) {
48        return $this->createLineWrapper(
49            Html::element( 'del', [ 'class' => 'diffchange diffchange-inline' ], $content ),
50            'diff-deletedline',
51            '-'
52        );
53    }
54
55    /**
56     * Create the container for a line
57     *
58     * @param string $line
59     * @param string $class the container class (diff-deletedline or diff-addedline)
60     * @param string $marker the diff marker (+ or -)
61     * @return string
62     */
63    protected function createLineWrapper( $line, $class, $marker ) {
64        return Html::element( 'td', [ 'class' => 'diff-marker' ], $marker ) .
65            Html::openElement( 'td', [ 'class' => $class ] ) .
66            Html::rawElement( 'div', [], $line ) .
67            Html::closeElement( 'td' );
68    }
69}