Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
63.64% |
7 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
HtmlReport | |
63.64% |
7 / 11 |
|
0.00% |
0 / 1 |
4.77 | |
0.00% |
0 / 1 |
report | |
63.64% |
7 / 11 |
|
0.00% |
0 / 1 |
4.77 |
1 | <?php |
2 | /** |
3 | * Copyright (C) 2018 Kunal Mehta <legoktm@debian.org> |
4 | * |
5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation, either version 3 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | namespace MediaWiki\Tool\PatchCoverage; |
20 | |
21 | use Phalcon\Diff as PhalconDiff; |
22 | use Phalcon\Diff\Renderer\Html\SideBySide; |
23 | use Symfony\Component\Console\Output\BufferedOutput; |
24 | use Wikimedia\CloverDiff\Diff; |
25 | use Wikimedia\CloverDiff\DiffPrinter; |
26 | |
27 | /** |
28 | * Build an HTML report that's helpfully nice for humans to use |
29 | */ |
30 | class HtmlReport { |
31 | |
32 | /** |
33 | * @param Diff $diff |
34 | * @param array $oldFiles |
35 | * @param array $newFiles |
36 | * |
37 | * @return string |
38 | */ |
39 | public function report( Diff $diff, array $oldFiles, array $newFiles ) { |
40 | $html = <<<HTML |
41 | <!DOCTYPE html> |
42 | <html> |
43 | <head> |
44 | <title>Coverage difference report</title> |
45 | <meta charset="utf-8"/> |
46 | <style> |
47 | .Differences { |
48 | font-family: monospace; |
49 | } |
50 | </style> |
51 | </head> |
52 | <body> |
53 | <h2>Summary</h2> |
54 | HTML; |
55 | $output = new BufferedOutput(); |
56 | ( new DiffPrinter( $output ) )->show( $diff ); |
57 | $html .= "<pre>{$output->fetch()}</pre>"; |
58 | foreach ( array_keys( $diff->getChanged() ) as $fname ) { |
59 | if ( isset( $newFiles[$fname] ) && isset( $oldFiles[$fname] ) ) { |
60 | $pdiff = new PhalconDiff( $oldFiles[$fname], $newFiles[$fname] ); |
61 | $html .= "<h2>$fname</h2>\n"; |
62 | $html .= $pdiff->render( new SideBySide() ); |
63 | } |
64 | } |
65 | |
66 | return $html . '</body></html>'; |
67 | } |
68 | } |