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\Contract\File\FileInterface; |
12
|
|
|
use Symplify\PHP7_CodeSniffer\Exception\File\NotImplementedException; |
13
|
|
|
use Symplify\PHP7_CodeSniffer\Fixer; |
14
|
|
|
use Symplify\PHP7_CodeSniffer\Report\ErrorDataCollector; |
15
|
|
|
|
16
|
|
|
final class File extends BaseFile implements FileInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
public $tokenizerType = 'PHP'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Fixer |
25
|
|
|
*/ |
26
|
|
|
public $fixer; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ErrorDataCollector |
30
|
|
|
*/ |
31
|
|
|
private $errorDataCollector; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
private $isFixer; |
37
|
|
|
|
38
|
6 |
|
public function __construct( |
39
|
|
|
string $path, |
40
|
|
|
array $tokens, |
41
|
|
|
Fixer $fixer, |
42
|
|
|
ErrorDataCollector $errorDataCollector, |
43
|
|
|
bool $isFixer, |
44
|
|
|
string $eolChar |
45
|
|
|
) { |
46
|
6 |
|
$this->path = $path; |
47
|
6 |
|
$this->tokens = $tokens; |
48
|
6 |
|
$this->fixer = $fixer; |
49
|
6 |
|
$this->errorDataCollector = $errorDataCollector; |
50
|
6 |
|
$this->eolChar = $eolChar; |
51
|
|
|
|
52
|
6 |
|
$this->numTokens = count($this->tokens); |
53
|
6 |
|
$this->content = file_get_contents($path); |
54
|
6 |
|
$this->isFixer = $isFixer; |
55
|
6 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
1 |
|
public function parse() |
61
|
|
|
{ |
62
|
1 |
|
throw new NotImplementedException( |
63
|
1 |
|
'This is not needed to be public. File is already parsed on __construct.' |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function process() |
71
|
|
|
{ |
72
|
1 |
|
throw new NotImplementedException( |
73
|
1 |
|
'This is not needed to be public. Use external processing.' |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function getErrorCount() |
81
|
|
|
{ |
82
|
1 |
|
throw new NotImplementedException(sprintf( |
83
|
1 |
|
'This is not needed to be public. Use "%s" service.', |
84
|
1 |
|
ErrorDataCollector::class |
85
|
|
|
)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
1 |
|
public function getErrors() |
92
|
|
|
{ |
93
|
1 |
|
throw new NotImplementedException(sprintf( |
94
|
1 |
|
'This is not needed to be public. Use "%s" service.', |
95
|
1 |
|
ErrorDataCollector::class |
96
|
|
|
)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
1 |
|
public function addFixableError($error, $stackPtr, $code, $data=[], $severity=0) |
103
|
|
|
{ |
104
|
1 |
|
$this->addError($error, $stackPtr, $code, $data, $severity, true); |
105
|
1 |
|
return $this->isFixer; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
1 |
|
protected function addMessage( |
112
|
|
|
$error, |
113
|
|
|
$message, |
114
|
|
|
$line, |
115
|
|
|
$column, |
116
|
|
|
$code, |
117
|
|
|
$data, |
118
|
|
|
$severity, |
119
|
|
|
$isFixable=false |
120
|
|
|
) : bool { |
121
|
1 |
|
if (!$error) { // skip warnings |
122
|
|
|
return false; |
123
|
|
|
} |
124
|
|
|
|
125
|
1 |
|
$this->errorDataCollector->addErrorMessage( |
126
|
1 |
|
$this->path, |
127
|
|
|
$message, |
128
|
|
|
$line, |
129
|
|
|
$code, |
130
|
|
|
$data, |
131
|
|
|
$isFixable |
132
|
|
|
); |
133
|
|
|
|
134
|
1 |
|
return true; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|