Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
UnifiedDiffFormatter
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 lines
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 added
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 deleted
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 changed
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 blockHeader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Portions taken from phpwiki-1.3.3.
4 *
5 * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
6 * You may copy this code freely under the conditions of the GPL.
7 *
8 * @license GPL-2.0-or-later
9 * @file
10 * @ingroup DifferenceEngine
11 */
12
13namespace Wikimedia\Diff;
14
15/**
16 * A formatter that outputs unified diffs
17 * @newable
18 * @stable to extend
19 * @ingroup DifferenceEngine
20 */
21class UnifiedDiffFormatter extends DiffFormatter {
22
23    /** @var int */
24    protected $leadingContextLines = 2;
25
26    /** @var int */
27    protected $trailingContextLines = 2;
28
29    /**
30     * @param string[] $lines
31     * @param string $prefix
32     */
33    protected function lines( $lines, $prefix = ' ' ) {
34        foreach ( $lines as $line ) {
35            $this->writeOutput( "{$prefix}{$line}\n" );
36        }
37    }
38
39    /**
40     * @param string[] $lines
41     */
42    protected function added( $lines ) {
43        $this->lines( $lines, '+' );
44    }
45
46    /**
47     * @param string[] $lines
48     */
49    protected function deleted( $lines ) {
50        $this->lines( $lines, '-' );
51    }
52
53    /**
54     * @param string[] $orig
55     * @param string[] $closing
56     */
57    protected function changed( $orig, $closing ) {
58        $this->deleted( $orig );
59        $this->added( $closing );
60    }
61
62    /**
63     * @param int $xbeg
64     * @param int $xlen
65     * @param int $ybeg
66     * @param int $ylen
67     *
68     * @return string
69     */
70    protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
71        return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
72    }
73
74}
75
76/** @deprecated class alias since 1.41 */
77class_alias( UnifiedDiffFormatter::class, 'UnifiedDiffFormatter' );