Completed
Push — master ( 751a3d...b7ca33 )
by Sebastian
17:18 queued 15:56
created

Line::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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