-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathParallelLintError.php
71 lines (61 loc) · 1.54 KB
/
ParallelLintError.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Errors;
use ReturnTypeWillChange;
class ParallelLintError implements \JsonSerializable
{
/** @var string */
protected $filePath;
/** @var string */
protected $message;
/**
* @param string $filePath
* @param string $message
*/
public function __construct($filePath, $message)
{
$this->filePath = $filePath;
$this->message = rtrim($message);
}
/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* @return string
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* @return string
*/
public function getShortFilePath()
{
$cwd = getcwd();
if ($cwd === '/') {
// For root directory in unix, do not modify path
return $this->filePath;
}
return preg_replace('/' . preg_quote($cwd, '/') . '/', '', $this->filePath, 1);
}
/**
* (PHP 5 >= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return array(
'type' => 'error',
'file' => $this->getFilePath(),
'message' => $this->getMessage(),
);
}
}