Skip to content

Commit 0632c4c

Browse files
committed
Runner::printProgress(): minor refactor
Reduce the complexity of the method somewhat and improve the readability.
1 parent 5939b05 commit 0632c4c

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

src/Runner.php

+28-35
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,14 @@ public function printProgress(File $file, $numFiles, $numProcessed)
856856
return;
857857
}
858858

859+
$showColors = $this->config->colors;
860+
$colorOpen = '';
861+
$progressDot = '.';
862+
$colorClose = '';
863+
859864
// Show progress information.
860865
if ($file->ignored === true) {
861-
echo 'S';
866+
$progressDot = 'S';
862867
} else {
863868
$errors = $file->getErrorCount();
864869
$warnings = $file->getWarningCount();
@@ -870,27 +875,19 @@ public function printProgress(File $file, $numFiles, $numProcessed)
870875
// Files with unfixable errors or warnings are E (red).
871876
// Files with no errors or warnings are . (black).
872877
if ($fixable > 0) {
873-
if ($this->config->colors === true) {
874-
echo "\033[31m";
875-
}
878+
$progressDot = 'E';
876879

877-
echo 'E';
878-
879-
if ($this->config->colors === true) {
880-
echo "\033[0m";
880+
if ($showColors === true) {
881+
$colorOpen = "\033[31m";
882+
$colorClose = "\033[0m";
881883
}
882884
} else if ($fixed > 0) {
883-
if ($this->config->colors === true) {
884-
echo "\033[32m";
885-
}
885+
$progressDot = 'F';
886886

887-
echo 'F';
888-
889-
if ($this->config->colors === true) {
890-
echo "\033[0m";
887+
if ($showColors === true) {
888+
$colorOpen = "\033[32m";
889+
$colorClose = "\033[0m";
891890
}
892-
} else {
893-
echo '.';
894891
}//end if
895892
} else {
896893
// Files with errors are E (red).
@@ -899,39 +896,35 @@ public function printProgress(File $file, $numFiles, $numProcessed)
899896
// Files with fixable warnings are W (green).
900897
// Files with no errors or warnings are . (black).
901898
if ($errors > 0) {
902-
if ($this->config->colors === true) {
899+
$progressDot = 'E';
900+
901+
if ($showColors === true) {
903902
if ($fixable > 0) {
904-
echo "\033[32m";
903+
$colorOpen = "\033[32m";
905904
} else {
906-
echo "\033[31m";
905+
$colorOpen = "\033[31m";
907906
}
908-
}
909-
910-
echo 'E';
911907

912-
if ($this->config->colors === true) {
913-
echo "\033[0m";
908+
$colorClose = "\033[0m";
914909
}
915910
} else if ($warnings > 0) {
916-
if ($this->config->colors === true) {
911+
$progressDot = 'W';
912+
913+
if ($showColors === true) {
917914
if ($fixable > 0) {
918-
echo "\033[32m";
915+
$colorOpen = "\033[32m";
919916
} else {
920-
echo "\033[33m";
917+
$colorOpen = "\033[33m";
921918
}
922-
}
923919

924-
echo 'W';
925-
926-
if ($this->config->colors === true) {
927-
echo "\033[0m";
920+
$colorClose = "\033[0m";
928921
}
929-
} else {
930-
echo '.';
931922
}//end if
932923
}//end if
933924
}//end if
934925

926+
echo $colorOpen.$progressDot.$colorClose;
927+
935928
$numPerLine = 60;
936929
if ($numProcessed !== $numFiles && ($numProcessed % $numPerLine) !== 0) {
937930
return;

0 commit comments

Comments
 (0)