diff --git a/Maximum-line-length.md b/Maximum-line-length.md new file mode 100644 index 0000000..0841436 --- /dev/null +++ b/Maximum-line-length.md @@ -0,0 +1,53 @@ +One line of code should have no more than **80 characters** (soft limit) and must never exceed **120 characters** (hard limit). + +_Notice_: Travis-CI enforces the hard limit of 120 characters. Maintainers may ask you to indent lines longer than 80 characters before merging. This is generally done to keep the code as readable and maintainable as possible. + +For long conditional statements, consider indenting the statement into multiple lines. + +
Example

+ +**Bad** (the total length of the line is **94** characters) + +```PHP +if($time !== false && (time() - $duration < $time) && (!defined('DEBUG') || DEBUG !== true)) { + +} +``` + +**Good** (add line breaks) + +```PHP +if($time !== false +&& (time() - $duration < $time) +&& (!defined('DEBUG') || DEBUG !== true)) { + +} +``` + +

+ +For long text, either add line feeds, or make use of the [`heredoc`](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) syntax. + +
Example

+ +**Bad** (the total length of the line is **340** characters - from [Lorem Ipsum](https://www.lipsum.com/feed/html)) + +```PHP +$longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse condimentum nec est eget posuere. Proin at sagittis risus. Fusce faucibus lectus leo, eu ornare velit tristique eu. Curabitur elementum facilisis ultricies. Praesent dictum fermentum lectus a rhoncus. Donec vitae justo metus. Sed molestie faucibus egestas.'; +``` + +**Good** (use `heredoc` syntax - this will add line-breaks) + +```PHP +$longtext = <<

+ +_Reference_: [`Generic.Files.LineLength`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Files/LineLengthSniff.php) \ No newline at end of file