Skip to content

Commit 56a4c19

Browse files
committed
Better, still needs more cleanup
1 parent 4da902a commit 56a4c19

File tree

2 files changed

+86
-24
lines changed

2 files changed

+86
-24
lines changed

src/Files/File.php

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,62 @@ class File
153153
protected $warningCount = 0;
154154

155155
/**
156-
* The total number of errors that can be fixed.
156+
* The original total number of errors that can be fixed (first run on a file).
157+
*
158+
* @readonly This should be regarded as an immutable property.
159+
*
160+
* @var integer
161+
*/
162+
private $fixableErrorCountFirstRun;
163+
164+
/**
165+
* The original total number of warnings that can be fixed (first run on a file).
166+
*
167+
* @readonly This should be regarded as an immutable property.
168+
*
169+
* @var integer
170+
*/
171+
private $fixableWarningCountFirstRun;
172+
173+
/**
174+
* The current total number of errors that can be fixed.
157175
*
158176
* @var integer
159177
*/
160178
protected $fixableErrorCount = 0;
161179

162180
/**
163-
* The total number of warnings that can be fixed.
181+
* The current total number of warnings that can be fixed.
164182
*
165183
* @var integer
166184
*/
167185
protected $fixableWarningCount = 0;
168186

169187
/**
170-
* The total number of errors that were fixed.
188+
* The actual number of errors and warnings that were fixed.
189+
*
190+
* I.e. how many fixes were applied. This may be higher than the originally found
191+
* issues if the fixer from one sniff causes other sniffs to come into play in follow-up loops.
192+
* Example: if a brace is moved to a new line, the `ScopeIndent` sniff may need to ensure
193+
* the brace is indented correctly in the next loop.
194+
*
195+
* @var integer
196+
*/
197+
protected $fixedCount = 0;
198+
199+
/**
200+
* The effective number of errors that were fixed.
201+
*
202+
* I.e. how many of the originally found errors were fixed.
171203
*
172204
* @var integer
173205
*/
174206
protected $fixedErrorCount = 0;
175207

176208
/**
177-
* The total number of warnings that were fixed.
209+
* The effective number of warnings that were fixed.
210+
*
211+
* I.e. how many of the originally found warnings were fixed.
178212
*
179213
* @var integer
180214
*/
@@ -521,9 +555,18 @@ public function process()
521555
StatusWriter::write('*** END SNIFF PROCESSING REPORT ***', 1);
522556
}
523557

524-
//$this->fixedCount += $this->fixer->getFixCount();
525-
$this->fixedErrorCount += $this->fixer->getFixedErrorCount();
526-
$this->fixedWarningCount += $this->fixer->getFixedWarningCount();
558+
if (isset($this->fixableErrorCountFirstRun, $this->fixableWarningCountFirstRun) === false) {
559+
$this->fixableErrorCountFirstRun = $this->fixableErrorCount;
560+
$this->fixableWarningCountFirstRun = $this->fixableWarningCount;
561+
}
562+
563+
// This is still needed for the progress reporting ?
564+
// Only if the error/warning counts don't work, as otherwise, it can be calculated in the getter method.
565+
// Then again, maybe we should still leave it in as-is and not have the calculation to have actual vs effective fixes in File too.
566+
$this->fixedCount += $this->fixer->getFixCount();
567+
// THIS IS WHAT I NEED TO LOOK AT/FIX
568+
$this->fixedErrorCount = ($this->fixableErrorCountFirstRun - $this->fixableErrorCount);
569+
$this->fixedWarningCount = ($this->fixableWarningCountFirstRun - $this->fixableWarningCount);
527570

528571
}//end process()
529572

@@ -1166,37 +1209,52 @@ public function getFixableWarningCount()
11661209

11671210

11681211
/**
1169-
* Returns the number of fixed errors/warnings.
1212+
* Returns the actual number of fixed errors/warnings.
11701213
*
11711214
* @return int
11721215
*/
11731216
public function getFixedCount()
11741217
{
1175-
return ($this->fixedErrorCount + $this->fixedWarningCount);
1218+
return $this->fixedCount;
1219+
//return ($this->fixedErrorCount + $this->fixedWarningCount);
11761220

11771221
}//end getFixedCount()
11781222

11791223

11801224
/**
1181-
* Returns the number of fixed errors.
1225+
* Returns the effective number of fixed errors.
11821226
*
11831227
* @return int
11841228
*/
11851229
public function getFixedErrorCount()
11861230
{
1187-
return $this->fixedErrorCount;
1231+
/*
1232+
if ($this->fixedErrorCount === 0 && PHP_CODESNIFFER_CBF === true) {
1233+
return $this->fixer->getFixedErrorCount();
1234+
} else {
1235+
*/
1236+
// Using value retrieved from cache/child process.
1237+
return $this->fixedErrorCount;
1238+
// }
11881239

11891240
}//end getFixedErrorCount()
11901241

11911242

11921243
/**
1193-
* Returns the number of fixed warnings.
1244+
* Returns the effective number of fixed warnings.
11941245
*
11951246
* @return int
11961247
*/
11971248
public function getFixedWarningCount()
11981249
{
1199-
return $this->fixedWarningCount;
1250+
/*
1251+
if ($this->fixedWarningCount === 0 && PHP_CODESNIFFER_CBF === true) {
1252+
return $this->fixer->getFixedWarningCount();
1253+
} else {
1254+
*/
1255+
// Using value retrieved from cache/child process.
1256+
return $this->fixedWarningCount;
1257+
// }
12001258

12011259
}//end getFixedWarningCount()
12021260

src/Fixer.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Fixer
120120
*
121121
* @var integer
122122
*/
123-
private $errorFixes = 0;
123+
// private $errorFixes = 0;
124124

125125
/**
126126
* The effective number of warning fixes that have been performed.
@@ -129,7 +129,7 @@ class Fixer
129129
*
130130
* @var integer
131131
*/
132-
private $warningFixes = 0;
132+
// private $warningFixes = 0;
133133

134134

135135
/**
@@ -143,8 +143,8 @@ public function startFile(File $phpcsFile)
143143
{
144144
$this->currentFile = $phpcsFile;
145145
$this->numFixes = 0;
146-
$this->errorFixes = 0;
147-
$this->warningFixes = 0;
146+
// $this->errorFixes = 0;
147+
// $this->warningFixes = 0;
148148
$this->fixedTokens = [];
149149

150150
$tokens = $phpcsFile->getTokens();
@@ -179,8 +179,8 @@ public function fixFile()
179179
StatusWriter::pause();
180180

181181
$this->loops = 0;
182-
$errorsBefore = $this->currentFile->getFixableErrorCount();
183-
$warningsBefore = $this->currentFile->getFixableWarningCount();
182+
// $errorsBefore = $this->currentFile->getFixableErrorCount();
183+
// $warningsBefore = $this->currentFile->getFixableWarningCount();
184184

185185
while ($this->loops < 50) {
186186
// Only needed once file content has changed.
@@ -233,8 +233,12 @@ public function fixFile()
233233

234234
StatusWriter::resume();
235235

236-
$this->errorFixes = ($errorsBefore - $this->currentFile->getFixableErrorCount());
237-
$this->warningFixes = ($warningsBefore - $this->currentFile->getFixableWarningCount());
236+
// MAYBE THIS SHOULD SET THE PROPERTY VALUES ON THE FILE CLASS ?
237+
// BUT IT CAN'T, as those are protected.
238+
// BUT THIS IS THE REAL PROBLEM, these values MUST be calculated, but won't be available until File::process() has finished,
239+
// while File::process() sets these to the File class....
240+
// $this->errorFixes = ($errorsBefore - $this->currentFile->getFixableErrorCount());
241+
// $this->warningFixes = ($warningsBefore - $this->currentFile->getFixableWarningCount());
238242

239243
if ($this->numFixes > 0 || $this->inConflict === true) {
240244
if (PHP_CODESNIFFER_VERBOSITY > 1) {
@@ -367,7 +371,7 @@ public function generateDiff($filePath=null, $colors=true)
367371

368372

369373
/**
370-
* Get a count of fixes that have been performed on the file.
374+
* Get a count of the actual number of fixes that have been performed on the file.
371375
*
372376
* This value is reset every time a new file is started, or an existing
373377
* file is restarted.
@@ -382,7 +386,7 @@ public function getFixCount()
382386

383387

384388
/**
385-
* Get a count of error fixes that have been performed on the file.
389+
* Get a count of the effective number of error fixes that have been performed on the file.
386390
*
387391
* This value is reset every time a new file is started, or an existing
388392
* file is restarted.
@@ -397,7 +401,7 @@ public function getFixedErrorCount()
397401

398402

399403
/**
400-
* Get a count of warning fixes that have been performed on the file.
404+
* Get a count of the effective number of warning fixes that have been performed on the file.
401405
*
402406
* This value is reset every time a new file is started, or an existing
403407
* file is restarted.

0 commit comments

Comments
 (0)