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\Application\Fixer; |
12
|
|
|
use Symplify\PHP7_CodeSniffer\Contract\File\FileInterface; |
13
|
|
|
use Symplify\PHP7_CodeSniffer\Exception\File\NotImplementedException; |
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
|
14 |
|
public function __construct(string $path, array $tokens, Fixer $fixer, ErrorDataCollector $errorDataCollector, bool $isFixer, string $eolChar) |
39
|
|
|
{ |
40
|
14 |
|
$this->path = $path; |
41
|
14 |
|
$this->tokens = $tokens; |
42
|
14 |
|
$this->fixer = $fixer; |
43
|
14 |
|
$this->errorDataCollector = $errorDataCollector; |
44
|
14 |
|
$this->eolChar = $eolChar; |
45
|
|
|
|
46
|
14 |
|
$this->numTokens = count($this->tokens); |
47
|
14 |
|
$this->content = file_get_contents($path); |
48
|
14 |
|
$this->isFixer = $isFixer; |
49
|
14 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
1 |
|
public function parse() |
55
|
|
|
{ |
56
|
1 |
|
throw new NotImplementedException(sprintf( |
57
|
1 |
|
'Method %s not needed to be public. File is already parsed on __construct.', |
58
|
1 |
|
__METHOD__ |
59
|
|
|
)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
1 |
|
public function process() |
66
|
|
|
{ |
67
|
1 |
|
throw new NotImplementedException(sprintf( |
68
|
1 |
|
'Method "%s" is not needed to be public. Use external processing.', |
69
|
1 |
|
__METHOD__ |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
1 |
|
public function getErrorCount() |
77
|
|
|
{ |
78
|
1 |
|
throw new NotImplementedException(sprintf( |
79
|
1 |
|
'Method "%s" is not needed to be public. Use "%s" service.', |
80
|
1 |
|
__METHOD__, |
81
|
1 |
|
ErrorDataCollector::class |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
1 |
|
public function getErrors() |
89
|
|
|
{ |
90
|
1 |
|
throw new NotImplementedException(sprintf( |
91
|
1 |
|
'Method "%s" is not needed to be public. Use "%s" service.', |
92
|
1 |
|
__METHOD__, |
93
|
1 |
|
ErrorDataCollector::class |
94
|
|
|
)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
1 |
|
public function addFixableError($error, $stackPtr, $code, $data = [], $severity = 0) |
101
|
|
|
{ |
102
|
1 |
|
$this->addError($error, $stackPtr, $code, $data, $severity, true); |
103
|
1 |
|
return $this->isFixer; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
1 |
|
protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $isFixable = false) : bool |
110
|
|
|
{ |
111
|
1 |
|
if (!$error) { // skip warnings |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
$this->errorDataCollector->addErrorMessage($this->path, $message, $line, $code, $data, $isFixable); |
116
|
|
|
|
117
|
1 |
|
return true; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|