Skip to content

Commit 7a46d37

Browse files
committed
Generator/Text: bug fix/PHP warning
If an individual line of the code sample in the code comparison would be longer than 47/48 characters, a `Warning: str_repeat(): Second argument has to be greater than or equal to 0` would be thrown. This fixes the error. Note: this fix does not introduce code-wrapping as that would probably reduce the readability of the code too much. Instead, the line will just be longer than other lines. Idea: should this class respect a `report_width` if set by the user either in their `CodeSniffer.conf` or via the command-line ?
1 parent 07ccaf2 commit 7a46d37

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Generators/Text.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ protected function printCodeComparisonBlock(\DOMNode $node)
231231
}
232232

233233
echo '| ';
234-
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
234+
echo $firstLineText.str_repeat(' ', max(0, (47 - strlen($firstLineText))));
235235
echo '| ';
236-
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
236+
echo $secondLineText.str_repeat(' ', max(0, (48 - strlen($secondLineText))));
237237
echo '|'.PHP_EOL;
238238
}//end for
239239

0 commit comments

Comments
 (0)