Differ   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A patch() 0 6 1
A diff() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
namespace Bavix\Diff;
4
5
use DiffMatchPatch\DiffMatchPatch;
6
7
class Differ implements Driver
8
{
9
10
    /**
11
     * @var DiffMatchPatch
12
     */
13
    protected $dmp;
14
15
    /**
16
     * Diff constructor.
17
     */
18
    public function __construct()
19
    {
20
        $this->dmp = new DiffMatchPatch();
21
    }
22
23
    /**
24
     * @param string $oldData
25
     * @param string $newData
26
     *
27
     * @return string
28
     */
29
    public function diff($oldData, $newData)
30
    {
31
        return $this->dmp->patch_toText(
32
            $this->dmp->patch_make($oldData, $newData)
33
        );
34
    }
35
36
    /**
37
     * @param string $data
38
     * @param string $patch
39
     *
40
     * @return string
41
     */
42
    public function patch($data, $patch)
43
    {
44
        return $this->dmp->patch_apply(
45
            $this->dmp->patch_fromText($patch),
46
            $data
47
        )[0] ?? '';
48
    }
49
50
}
51