Skip to content

Commit

Permalink
Generator/Text: bug fix/PHP warning
Browse files Browse the repository at this point in the history
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 ?
  • Loading branch information
jrfnl committed May 31, 2019
1 parent 07ccaf2 commit 7a46d37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Generators/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ protected function printCodeComparisonBlock(\DOMNode $node)
}

echo '| ';
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
echo $firstLineText.str_repeat(' ', max(0, (47 - strlen($firstLineText))));
echo '| ';
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
echo $secondLineText.str_repeat(' ', max(0, (48 - strlen($secondLineText))));
echo '|'.PHP_EOL;
}//end for

Expand Down

0 comments on commit 7a46d37

Please sign in to comment.