These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | private $message; |
||
23 | private $path; |
||
24 | private $line; |
||
25 | private $context; |
||
26 | |||
27 | 31 | public function __construct(string $message, string $path, int $line, array $context = []) |
|
28 | { |
||
29 | 31 | $this->message = $message; |
|
30 | 31 | $this->path = (string) $path; |
|
31 | 31 | $this->line = $line; |
|
32 | 31 | $this->context = $context; |
|
33 | 31 | } |
|
34 | |||
35 | /** |
||
36 | * Create a source location from your current location. |
||
37 | */ |
||
38 | 4 | public static function createHere(string $message, array $context = []): self |
|
39 | { |
||
40 | 4 | foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2) as $trace) { |
|
41 | // File is not set if we call from an anonymous context like an array_map function. |
||
42 | 4 | if (isset($trace['file'])) { |
|
43 | 4 | break; |
|
44 | } |
||
45 | } |
||
46 | |||
47 | 4 | return new self($message, $trace['file'], $trace['line'], $context); |
|
0 ignored issues
–
show
|
|||
48 | } |
||
49 | |||
50 | 30 | public function getMessage(): string |
|
51 | { |
||
52 | 30 | return $this->message; |
|
53 | } |
||
54 | |||
55 | 3 | public function getPath(): string |
|
56 | { |
||
57 | 3 | return $this->path; |
|
58 | } |
||
59 | |||
60 | 6 | public function getLine(): int |
|
61 | { |
||
62 | 6 | return $this->line; |
|
63 | } |
||
64 | |||
65 | 10 | public function getContext(): array |
|
66 | { |
||
67 | 10 | return $this->context; |
|
68 | } |
||
69 | } |
||
70 |
It seems like you are relying on a variable being defined by an iteration: