forked from vimeo/psalm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseErrorLocation.php
38 lines (32 loc) · 1.08 KB
/
ParseErrorLocation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Psalm\CodeLocation;
use PhpParser;
use Psalm\CodeLocation;
use function substr;
use function substr_count;
/** @psalm-immutable */
final class ParseErrorLocation extends CodeLocation
{
public function __construct(
PhpParser\Error $error,
string $file_contents,
string $file_path,
string $file_name,
) {
/** @psalm-suppress PossiblyUndefinedStringArrayOffset, ImpureMethodCall */
$this->file_start = (int)$error->getAttributes()['startFilePos'];
/** @psalm-suppress PossiblyUndefinedStringArrayOffset, ImpureMethodCall */
$this->file_end = (int)$error->getAttributes()['endFilePos'];
$this->raw_file_start = $this->file_start;
$this->raw_file_end = $this->file_end;
$this->file_path = $file_path;
$this->file_name = $file_name;
$this->single_line = false;
$this->preview_start = $this->file_start;
$this->raw_line_number = substr_count(
substr($file_contents, 0, $this->file_start),
"\n",
) + 1;
}
}