Differ::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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