Skip to content

Commit a4a0ba4

Browse files
authored
Merge pull request #1052 from PHPCSStandards/phpcs-4.0/remove-output-buffering-from-fixer
Fixer: remove output buffering
2 parents d12e243 + 1df4347 commit a4a0ba4

File tree

4 files changed

+0
-43
lines changed

4 files changed

+0
-43
lines changed

src/Files/File.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
10471047
&& $this->fixer->enabled === true
10481048
&& $fixable === true
10491049
) {
1050-
@ob_end_clean();
10511050
StatusWriter::forceWrite("E: [Line $line] $message ($sniffCode)", 1);
1052-
ob_start();
10531051
}
10541052

10551053
return true;

src/Fixer.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ public function fixFile()
155155

156156
$this->loops = 0;
157157
while ($this->loops < 50) {
158-
ob_start();
159-
160158
// Only needed once file content has changed.
161159
$contents = $this->getContents();
162160

163161
if (PHP_CODESNIFFER_VERBOSITY > 2) {
164-
@ob_end_clean();
165162
StatusWriter::forceWrite('---START FILE CONTENT---');
166163
$lines = explode($this->currentFile->eolChar, $contents);
167164
$max = strlen(count($lines));
@@ -171,14 +168,12 @@ public function fixFile()
171168
}
172169

173170
StatusWriter::forceWrite('--- END FILE CONTENT ---');
174-
ob_start();
175171
}
176172

177173
$this->inConflict = false;
178174
$this->currentFile->ruleset->populateTokenListeners();
179175
$this->currentFile->setContent($contents);
180176
$this->currentFile->process();
181-
ob_end_clean();
182177

183178
$this->loops++;
184179

@@ -212,12 +207,7 @@ public function fixFile()
212207

213208
if ($this->numFixes > 0 || $this->inConflict === true) {
214209
if (PHP_CODESNIFFER_VERBOSITY > 1) {
215-
if (ob_get_level() > 0) {
216-
ob_end_clean();
217-
}
218-
219210
StatusWriter::write("*** Reached maximum number of loops with $this->numFixes violations left unfixed ***", 1);
220-
ob_start();
221211
}
222212

223213
return false;
@@ -417,9 +407,7 @@ public function beginChangeset()
417407

418408
$line = $bt[0]['line'];
419409

420-
@ob_end_clean();
421410
StatusWriter::forceWrite("=> Changeset started by $sniff:$line", 1);
422-
ob_start();
423411
}
424412

425413
$this->changeset = [];
@@ -459,15 +447,11 @@ public function endChangeset()
459447
}
460448

461449
if (PHP_CODESNIFFER_VERBOSITY > 1) {
462-
@ob_end_clean();
463450
StatusWriter::forceWrite('=> Changeset failed to apply', 1);
464-
ob_start();
465451
}
466452
} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
467453
$fixes = count($this->changeset);
468-
@ob_end_clean();
469454
StatusWriter::forceWrite("=> Changeset ended: $fixes changes applied", 1);
470-
ob_start();
471455
}
472456

473457
$this->changeset = [];
@@ -501,10 +485,8 @@ public function rollbackChangeset()
501485

502486
$numChanges = count($this->changeset);
503487

504-
@ob_end_clean();
505488
StatusWriter::forceWrite("R: $sniff:$line rolled back the changeset ($numChanges changes)", 2);
506489
StatusWriter::forceWrite('=> Changeset rolled back', 1);
507-
ob_start();
508490
}
509491

510492
$this->changeset = [];
@@ -536,9 +518,7 @@ public function replaceToken($stackPtr, $content)
536518
}
537519

538520
if (PHP_CODESNIFFER_VERBOSITY > 1) {
539-
@ob_end_clean();
540521
StatusWriter::forceWrite("* token $stackPtr has already been modified, skipping *", $depth);
541-
ob_start();
542522
}
543523

544524
return false;
@@ -573,9 +553,7 @@ public function replaceToken($stackPtr, $content)
573553
$this->changeset[$stackPtr] = $content;
574554

575555
if (PHP_CODESNIFFER_VERBOSITY > 1) {
576-
@ob_end_clean();
577556
StatusWriter::forceWrite("Q: $sniff:$line replaced token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\"", 2);
578-
ob_start();
579557
}
580558

581559
return true;
@@ -599,7 +577,6 @@ public function replaceToken($stackPtr, $content)
599577

600578
$loop = $this->oldTokenValues[$stackPtr]['loop'];
601579

602-
@ob_end_clean();
603580
StatusWriter::forceWrite("**** $sniff:$line has possible conflict with another sniff on loop $loop; caused by the following change ****", $depth);
604581
StatusWriter::forceWrite("**** replaced token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\" ****", $depth);
605582
}
@@ -611,10 +588,6 @@ public function replaceToken($stackPtr, $content)
611588
}
612589
}
613590

614-
if (PHP_CODESNIFFER_VERBOSITY > 1) {
615-
ob_start();
616-
}
617-
618591
return false;
619592
}//end if
620593

@@ -635,12 +608,7 @@ public function replaceToken($stackPtr, $content)
635608
$depth = 2;
636609
}
637610

638-
if (ob_get_level() > 0) {
639-
ob_end_clean();
640-
}
641-
642611
StatusWriter::forceWrite($statusMessage, $depth);
643-
ob_start();
644612
}
645613

646614
return true;
@@ -698,9 +666,7 @@ public function revertToken($stackPtr)
698666
$depth = 2;
699667
}
700668

701-
@ob_end_clean();
702669
StatusWriter::forceWrite($statusMessage, $depth);
703-
ob_start();
704670
}
705671

706672
return true;

src/Reports/Cbf.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
4242
$errors = $phpcsFile->getFixableCount();
4343
if ($errors !== 0) {
4444
if (PHP_CODESNIFFER_VERBOSITY > 0) {
45-
ob_end_clean();
4645
$startTime = microtime(true);
4746
$newlines = 0;
4847
if (PHP_CODESNIFFER_VERBOSITY > 1) {
@@ -105,10 +104,6 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
105104
}
106105
}
107106

108-
if (PHP_CODESNIFFER_VERBOSITY > 0) {
109-
ob_start();
110-
}
111-
112107
$errorCount = $phpcsFile->getErrorCount();
113108
$warningCount = $phpcsFile->getWarningCount();
114109
$fixableCount = $phpcsFile->getFixableCount();

src/Reports/Diff.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
6565
}//end if
6666

6767
if (PHP_CODESNIFFER_VERBOSITY > 1) {
68-
ob_end_clean();
6968
StatusWriter::write('*** START FILE FIXING ***', 1);
7069
}
7170

7271
$fixed = $phpcsFile->fixer->fixFile();
7372

7473
if (PHP_CODESNIFFER_VERBOSITY > 1) {
7574
StatusWriter::write('*** END FILE FIXING ***', 1);
76-
ob_start();
7775
}
7876

7977
if ($fixed === false) {

0 commit comments

Comments
 (0)