Passed
Push — master ( b3f41c...50a57e )
by Josh
01:14
created

demo/index.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Caxy\HtmlDiff\HtmlDiff;
4
5
ini_set('display_errors', 1);
6
error_reporting(E_ALL);
7
8
require __DIR__.'/../vendor/autoload.php';
9
10
$debugOutput = array();
11
12
function addDebugOutput($value, $key = 'general')
13
{
14
    global $debugOutput;
15
16
    if (!is_string($value)) {
17
        $value = var_export($value, true);
18
    }
19
20
    if (!array_key_exists($key, $debugOutput)) {
21
        $debugOutput[$key] = array();
22
    }
23
24
    $debugOutput[$key][] = $value;
25
}
26
27
$input = file_get_contents('php://input');
28
29
if ($input) {
30
    header('Content-Type: application/json');
31
32
    $data = json_decode($input, true);
33
34
    $oldText = $data['oldText'];
35
    $newText = $data['newText'];
36
    $useTableDiffing = isset($data['tableDiffing']) ? $data['tableDiffing'] : true;
37
38
    $diff = new HtmlDiff($oldText, $newText, 'UTF-8', array());
39
    if (array_key_exists('matchThreshold', $data)) {
40
        $diff->setMatchThreshold($data['matchThreshold']);
0 ignored issues
show
Deprecated Code introduced by
The method Caxy\HtmlDiff\AbstractDiff::setMatchThreshold() has been deprecated with message: since 0.1.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
41
    }
42
    $diff->setUseTableDiffing($useTableDiffing);
0 ignored issues
show
Deprecated Code introduced by
The method Caxy\HtmlDiff\HtmlDiff::setUseTableDiffing() has been deprecated with message: since 0.1.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
    $diffOutput = $diff->build();
44
    $diffOutput = mb_convert_encoding($diffOutput, 'UTF-8');
45
46
    $jsonOutput = json_encode(array('diff' => $diffOutput, 'debug' => $debugOutput));
47
48
    if (false === $jsonOutput) {
49
        throw new \Exception('Failed to encode JSON: '.json_last_error_msg());
50
    }
51
52
    echo $jsonOutput;
53
} else {
54
    header('Content-Type: text/html');
55
    echo file_get_contents('demo.html');
56
}
57