PlainText   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSeparator() 0 5 1
A render() 0 21 5
A getSeparator() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mistrals\Diff\Renderer;
6
7
use Mistralys\Diff\Diff;
8
use Mistralys\Diff\DiffException;
9
10
class PlainText extends Renderer
11
{
12
    private string $separator = "\n";
13
    
14
    public function setSeparator(string $separator) : PlainText
15
    {
16
        $this->separator = $separator;
17
        
18
        return $this;
19
    }
20
    
21
    public function getSeparator() : string
22
    {
23
        return $this->separator;
24
    }
25
26
    /**
27
     * @return string
28
     * @throws DiffException
29
     */
30
    public function render() : string
31
    {
32
        $string = '';
33
        $diff = $this->diff->toArray();
34
        
35
        // loop over the lines in the diff
36
        foreach ($diff as $line)
37
        {
38
            // extend the string with the line
39
            switch ($line[1])
40
            {
41
                case Diff::UNMODIFIED : $string .= '  ' . $line[0];break;
42
                case Diff::DELETED    : $string .= '- ' . $line[0];break;
43
                case Diff::INSERTED   : $string .= '+ ' . $line[0];break;
44
            }
45
            
46
            // extend the string with the separator
47
            $string .= $this->separator;
48
        }
49
        
50
        return $string;
51
    }
52
}
53