mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-06 08:37:30 +02:00
Created String concatenation (markdown)
40
String-concatenation.md
Normal file
40
String-concatenation.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
The concatenation operator should have one space on both sides in order to improve readability.
|
||||||
|
|
||||||
|
<details><summary>Example</summary><div><br>
|
||||||
|
|
||||||
|
**Bad**
|
||||||
|
|
||||||
|
```PHP
|
||||||
|
$text = $greeting.' '.$name.'!';
|
||||||
|
```
|
||||||
|
|
||||||
|
**Good** (add spaces)
|
||||||
|
|
||||||
|
```PHP
|
||||||
|
$text = $greeting . ' ' . $name . '!';
|
||||||
|
```
|
||||||
|
|
||||||
|
</div></details><br>
|
||||||
|
|
||||||
|
You may break long lines into multiple lines using the concatenation operator. That way readability can improve considerable when combining lots of variables.
|
||||||
|
|
||||||
|
<details><summary>Example</summary><div><br>
|
||||||
|
|
||||||
|
**Bad**
|
||||||
|
|
||||||
|
```PHP
|
||||||
|
$text = $greeting.' '.$name.'!';
|
||||||
|
```
|
||||||
|
|
||||||
|
**Good** (split into multiple lines)
|
||||||
|
|
||||||
|
```PHP
|
||||||
|
$text = $greeting
|
||||||
|
. ' '
|
||||||
|
. $name
|
||||||
|
. '!';
|
||||||
|
```
|
||||||
|
|
||||||
|
</div></details><br>
|
||||||
|
|
||||||
|
_Reference_: [`Squiz.Strings.ConcatenationSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php)
|
Reference in New Issue
Block a user