From ed8d5c556f4c7a93ea7943771e1c669e33519495 Mon Sep 17 00:00:00 2001 From: LogMANOriginal Date: Mon, 5 Nov 2018 13:10:19 +0100 Subject: [PATCH] Created Maximum line length (markdown) --- Maximum-line-length.md | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Maximum-line-length.md 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