From c07914aaa0f5beaec07bfcf70cfaed7d415bbd02 Mon Sep 17 00:00:00 2001 From: LogMANOriginal Date: Mon, 5 Nov 2018 13:08:16 +0100 Subject: [PATCH] Created String concatenation (markdown) --- String-concatenation.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 String-concatenation.md diff --git a/String-concatenation.md b/String-concatenation.md new file mode 100644 index 0000000..e741794 --- /dev/null +++ b/String-concatenation.md @@ -0,0 +1,40 @@ +The concatenation operator should have one space on both sides in order to improve readability. + +
Example

+ +**Bad** + +```PHP +$text = $greeting.' '.$name.'!'; +``` + +**Good** (add spaces) + +```PHP +$text = $greeting . ' ' . $name . '!'; +``` + +

+ +You may break long lines into multiple lines using the concatenation operator. That way readability can improve considerable when combining lots of variables. + +
Example

+ +**Bad** + +```PHP +$text = $greeting.' '.$name.'!'; +``` + +**Good** (split into multiple lines) + +```PHP +$text = $greeting +. ' ' +. $name +. '!'; +``` + +

+ +_Reference_: [`Squiz.Strings.ConcatenationSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php) \ No newline at end of file