Completed
Push — master ( 5a4306...e82f42 )
by Tobias
02:36
created

SourceLocation::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Extractor\Model;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
final class SourceLocation
18
{
19
    /**
20
     * Translation key.
21
     *
22
     * @var string
23
     */
24
    private $message;
25
26
    /**
27
     * @var string
28
     */
29
    private $path;
30
31
    /**
32
     * @var int
33
     */
34
    private $line;
35
36
    /**
37
     * @var array
38
     */
39
    private $context;
40
41
    /**
42
     * @param string $message
43
     * @param string $path
44
     * @param int    $line
45
     * @param array  $context
46
     */
47 16
    public function __construct($message, $path, $line, array $context = [])
48
    {
49 16
        $this->message = $message;
50 16
        $this->path = (string) $path;
51 16
        $this->line = $line;
52 16
        $this->context = $context;
53 16
    }
54
55
    /**
56
     * Create a source location from your current location.
57
     *
58
     * @param string $message
59
     * @param array  $context
60
     *
61
     * @return SourceLocation
62
     */
63 1
    public static function createHere($message, array $context = [])
64
    {
65 1
        $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
66
67 1
        return new self($message, $trace[0]['file'], $trace[0]['line'], $context);
68
    }
69
70
    /**
71
     * @return string
72
     */
73 15
    public function getMessage()
74
    {
75 15
        return $this->message;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 1
    public function getPath()
82
    {
83 1
        return $this->path;
84
    }
85
86
    /**
87
     * @return int
88
     */
89 4
    public function getLine()
90
    {
91 4
        return $this->line;
92
    }
93
94
    /**
95
     * @return array
96
     */
97 2
    public function getContext()
98
    {
99 2
        return $this->context;
100
    }
101
}
102