Skip to content

Commit ac330fb

Browse files
gsherwoodjrfnl
authored andcommitted
Added properties for Generic.Formatting.SpaceAfterCast
1 parent 7c0f75f commit ac330fb

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

wiki/Customisable-Sniff-Properties.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For more information about changing sniff behaviour by customising your ruleset,
1111
* [Generic.Files.LineEndings](#genericfileslineendings)
1212
* [Generic.Files.LineLength](#genericfileslinelength)
1313
* [Generic.Formatting.MultipleStatementAlignment](#genericformattingmultiplestatementalignment)
14+
* [Generic.Formatting.SpaceAfterCast](#genericformattingspaceaftercast)
1415
* [Generic.Formatting.SpaceAfterNot](#genericformattingspaceafternot)
1516
* [Generic.Functions.OpeningFunctionBraceBsdAllman](#genericfunctionsopeningfunctionbracebsdallman)
1617
* [Generic.Functions.OpeningFunctionBraceKernighanRitchie](#genericfunctionsopeningfunctionbracekernighanritchie)
@@ -229,6 +230,45 @@ If the `error` property is set to `true`, an error will be thrown for violations
229230
</rule>
230231
```
231232

233+
### Generic.Formatting.SpaceAfterCast
234+
235+
Property Name | Type | Default | Available Since
236+
-------------- | ---- | ------- | ---------------
237+
spacing | int | 1 | 3.4.0
238+
ignoreNewlines | bool | false | 3.4.0
239+
240+
This sniff checks the spacing after a type cast. By default, the sniff ensures there is one space after the cast, as shown in the following code snippet:
241+
242+
```php
243+
$var = (int) $foo;
244+
```
245+
246+
Another common way of type casting is to follow the cast with no space, as shown in the following code snippet:
247+
248+
```php
249+
$var = (int)$foo;
250+
```
251+
252+
If you prefer to write your code like this, you can set the `spacing` property to `0`, or whatever padding you prefer.
253+
254+
```xml
255+
<rule ref="Generic.Formatting.SpaceAfterCast">
256+
<properties>
257+
<property name="spacing" value="0" />
258+
</properties>
259+
</rule>
260+
```
261+
262+
Sometimes complex statements are broken over multiple lines for readability. By default, this sniff will generate an error if the type cast is followed by a newline. Setting the `ignoreNewlines` property to `true` will allow newline characters after a type cast.
263+
264+
```xml
265+
<rule ref="Generic.Formatting.SpaceAfterCast">
266+
<properties>
267+
<property name="ignoreNewlines" value="true" />
268+
</properties>
269+
</rule>
270+
```
271+
232272
### Generic.Formatting.SpaceAfterNot
233273

234274
Property Name | Type | Default | Available Since

0 commit comments

Comments
 (0)