Line::getContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of SebastianFeldmann\Git.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SebastianFeldmann\Git\Diff;
13
14
/**
15
 * Class Line.
16
 *
17
 * @author  Sebastian Feldmann <[email protected]>
18
 * @link    https://github.com/sebastianfeldmann/git
19
 * @since   Class available since Release 1.2.0
20
 */
21
class Line
22
{
23
    /**
24
     * Possible line operations
25
     */
26
    public const ADDED   = 'added';
27
    public const REMOVED = 'removed';
28
    public const EXISTED = 'existed';
29
30
    /**
31
     * Map diff output to file operation
32
     * @var array
33
     */
34
    public static $opsMap = [
35
        '+' => self::ADDED,
36
        '-' => self::REMOVED,
37
        ' ' => self::EXISTED
38
    ];
39
40
    /**
41
     * @var string
42
     */
43
    private $operation;
44
45
    /**
46
     * @var string
47
     */
48
    private $content;
49
50
    /**
51
     * Line constructor.
52
     *
53
     * @param string $operation
54 11
     * @param string $content
55
     */
56 11
    public function __construct(string $operation, string $content)
57 1
    {
58
        if (!in_array($operation, self::$opsMap)) {
59 10
            throw new \RuntimeException('invalid line operation: ' . $operation);
60 10
        }
61 10
        $this->operation = $operation;
62
        $this->content   = $content;
63
    }
64
65
    /**
66
     * Operation getter.
67
     *
68 4
     * @return string
69
     */
70 4
    public function getOperation(): string
71
    {
72
        return $this->operation;
73
    }
74
75
    /**
76
     * Content getter.
77
     *
78 2
     * @return string
79
     */
80 2
    public function getContent(): string
81
    {
82
        return $this->content;
83
    }
84
}
85