Skip to content

Commit 869efc3

Browse files
committed
Fix exit code when phpcbf is processing STDIN
1 parent 848b839 commit 869efc3

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/Files/File.php

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

155155
/**
156-
* The original total number of errors that can be fixed (first run on a file).
156+
* The original total number of errors and warnings (first run on a file).
157157
*
158158
* {@internal This should be regarded as an immutable property.}
159159
*
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-
* {@internal This should be regarded as an immutable property.}
168-
*
169-
* @var integer
160+
* @var array<string, int>
170161
*/
171-
private $fixableWarningCountFirstRun;
162+
private $firstRunCounts;
172163

173164
/**
174165
* The current total number of errors that can be fixed.
@@ -555,14 +546,18 @@ public function process()
555546
StatusWriter::write('*** END SNIFF PROCESSING REPORT ***', 1);
556547
}
557548

558-
if (isset($this->fixableErrorCountFirstRun, $this->fixableWarningCountFirstRun) === false) {
559-
$this->fixableErrorCountFirstRun = $this->fixableErrorCount;
560-
$this->fixableWarningCountFirstRun = $this->fixableWarningCount;
549+
if (isset($this->firstRunCounts) === false) {
550+
$this->firstRunCounts = [
551+
'error' => $this->errorCount,
552+
'warning' => $this->warningCount,
553+
'fixableError' => $this->fixableErrorCount,
554+
'fixableWarning' => $this->fixableWarningCount,
555+
];
561556
}
562557

563558
$this->fixedCount += $this->fixer->getFixCount();
564-
$this->fixedErrorCount = ($this->fixableErrorCountFirstRun - $this->fixableErrorCount);
565-
$this->fixedWarningCount = ($this->fixableWarningCountFirstRun - $this->fixableWarningCount);
559+
$this->fixedErrorCount = ($this->firstRunCounts['fixableError'] - $this->fixableErrorCount);
560+
$this->fixedWarningCount = ($this->firstRunCounts['fixableWarning'] - $this->fixableWarningCount);
566561

567562
}//end process()
568563

@@ -1217,6 +1212,22 @@ public function getFixedWarningCount()
12171212
}//end getFixedWarningCount()
12181213

12191214

1215+
/**
1216+
* Retrieve information about the first run.
1217+
*
1218+
* @param $type string
1219+
*
1220+
* @internal This method does not form part of any public API nor backwards compatibility guarantee.
1221+
*
1222+
* @return int
1223+
*/
1224+
public function getFirstRunCount(string $type):int
1225+
{
1226+
return $this->firstRunCounts[$type];
1227+
1228+
}//end getFirstRunCount()
1229+
1230+
12201231
/**
12211232
* Returns the list of ignored lines.
12221233
*

src/Reports/Cbf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ public function __construct()
276276
};
277277

278278
$reporter->totalFiles = 1;
279-
$reporter->totalErrors = $phpcsFile->getErrorCount();
280-
$reporter->totalWarnings = $phpcsFile->getWarningCount();
279+
$reporter->totalErrors = $phpcsFile->getFirstRunCount('error');
280+
$reporter->totalWarnings = $phpcsFile->getFirstRunCount('warning');
281281
$reporter->totalFixableErrors = $phpcsFile->getFixableErrorCount();
282282
$reporter->totalFixableWarnings = $phpcsFile->getFixableWarningCount();
283283
$reporter->totalFixedErrors = $phpcsFile->getFixedErrorCount();

0 commit comments

Comments
 (0)