1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Symplify |
5
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Symplify\PHP7_CodeSniffer\File; |
9
|
|
|
|
10
|
|
|
use PHP_CodeSniffer\Files\File as BaseFile; |
11
|
|
|
use Symplify\PHP7_CodeSniffer\Fixer; |
12
|
|
|
use Symplify\PHP7_CodeSniffer\ErrorDataCollector; |
13
|
|
|
|
14
|
|
|
final class File extends BaseFile |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
public $tokenizerType = 'PHP'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Fixer |
23
|
|
|
*/ |
24
|
|
|
public $fixer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ErrorDataCollector |
28
|
|
|
*/ |
29
|
|
|
private $reportCollector; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $isFixer; |
35
|
|
|
|
36
|
|
|
public function __construct( |
37
|
|
|
string $path, |
38
|
|
|
array $tokens, |
39
|
|
|
Fixer $fixer, |
40
|
|
|
ErrorDataCollector $reportCollector, |
41
|
|
|
bool $isFixer, |
42
|
|
|
string $eolChar |
43
|
|
|
) { |
44
|
|
|
$this->path = $path; |
45
|
|
|
$this->tokens = $tokens; |
46
|
|
|
$this->fixer = $fixer; |
47
|
|
|
$this->reportCollector = $reportCollector; |
48
|
|
|
$this->eolChar = $eolChar; |
49
|
|
|
|
50
|
|
|
$this->numTokens = count($this->tokens); |
51
|
|
|
$this->content = file_get_contents($path); |
52
|
|
|
$this->isFixer = $isFixer; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function parse() |
59
|
|
|
{ |
60
|
|
|
throw new \Exception('Not implemented, nor needed to be public. File is already parsed on __construct.'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function process() |
67
|
|
|
{ |
68
|
|
|
throw new \Exception('Not implemented, nor needed to be public. Use external processing.'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function addFixableError($error, $stackPtr, $code, $data = [], $severity = 0) |
75
|
|
|
{ |
76
|
|
|
$this->addError($error, $stackPtr, $code, $data, $severity, true); |
77
|
|
|
return $this->isFixer; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $isFixable = false) : bool |
84
|
|
|
{ |
85
|
|
|
if (!$error) { // skip warnings |
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->reportCollector->addErrorMessage($this->path, $message, $line, $code, $data, $isFixable); |
90
|
|
|
|
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getContent() : string |
95
|
|
|
{ |
96
|
|
|
return $this->getTokensAsString(0, count($this->tokens)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|