Skip to content

Commit 46ccc96

Browse files
gsherwoodjrfnl
authored andcommitted
Updated Customisable Sniff Properties (markdown)
1 parent 89e517f commit 46ccc96

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

wiki/Customisable-Sniff-Properties.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ For more information about changing sniff behaviour by customising your ruleset,
55
## Table of contents
66
* Generic Sniffs
77
* [Generic.Arrays.ArrayIndent](#genericarraysarrayindent)
8+
* [Generic.CodeAnalysis.UnusedFunctionParameter](#genericcodeanalysisunusedfunctionparameter)
89
* [Generic.ControlStructures.InlineControlStructure](#genericcontrolstructuresinlinecontrolstructure)
910
* [Generic.Debug.ClosureLinter](#genericdebugclosurelinter)
1011
* [Generic.Debug.ESLint](#genericdebugeslint)
@@ -87,6 +88,33 @@ One of the rules that this sniff enforces is the indent of keys in a multi-line
8788
</rule>
8889
```
8990

91+
### Generic.CodeAnalysis.UnusedFunctionParameter
92+
93+
Property Name | Type | Default | Available Since
94+
--------------- | ----- | ------- | ---------------
95+
ignoreTypeHints | array | [] | 3.6.0
96+
97+
This sniff ensures that parameters passed to a function are used within that function, and warns if they are not. Sometimes, parameters can be left unused when doing something like implementing an interface, such as with the following code:
98+
99+
```php
100+
public function execute(InputInterface $input, OutputInterface $output): int
101+
{
102+
$output->writeln('Hello World!');
103+
}
104+
```
105+
106+
If the `InputInterface` parameter does not need to be used, you can tell the sniff to ignore all variables with that type hint by setting the `ignoreTypeHints` property.
107+
108+
```xml
109+
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
110+
<properties>
111+
<property name="ignoreTypeHints" type="array">
112+
<element value="InputInterface"/>
113+
</property>
114+
</properties>
115+
</rule>
116+
```
117+
90118
### Generic.ControlStructures.InlineControlStructure
91119

92120
Property Name | Type | Default | Available Since
@@ -107,8 +135,8 @@ If the `error` property is set to `false`, a warning will be thrown for violatio
107135

108136
Property Name | Type | Default | Available Since
109137
------------- | ----- | ------- | ---------------
110-
errorCodes | array | - | -
111-
ignoreCodes | array | - | -
138+
errorCodes | array | [] | -
139+
ignoreCodes | array | [] | -
112140

113141
The `Generic.Debug.ClosureLinter` sniff runs the [Google Closure Linter](https://github.com/google/closure-linter) tool over JavaScript files and reports errors that the tool finds. All found errors are reported as PHP_CodeSniffer warnings by default.
114142

@@ -458,10 +486,10 @@ Strictly speaking, a name cannot have two capital letters next to each other in
458486

459487
### Generic.PHP.ForbiddenFunctions
460488

461-
Property Name | Type | Default | Available Since
462-
-------------------| ----- | --------------------------- | ---------------
463-
forbiddenFunctions | array | sizeof=>count,delete=>unset | 2.0.0
464-
error | bool | true | -
489+
Property Name | Type | Default | Available Since
490+
-------------------| ----- | ----------------------------- | ---------------
491+
forbiddenFunctions | array | [sizeof=>count,delete=>unset] | 2.0.0
492+
error | bool | true | -
465493

466494
This sniff discourages the use of alias functions that are kept in PHP for compatibility with older versions. The sniff can be used to forbid the use of any function by setting the `forbiddenFunctions` property. The property is defined as an array, with the keys being the names of the functions to forbid and the values being the names of suggested alternative functions to use instead. If no alternative function exists (i.e., the function should never be used) specify `null` as the value.
467495

@@ -575,7 +603,7 @@ Property Name | Type | Default | Available Since
575603
indent | int | 4 | -
576604
exact | bool | false | -
577605
tabIndent | bool | false | 2.0.0
578-
ignoreIndentationTokens | array | - | 1.4.8
606+
ignoreIndentationTokens | array | [] | 1.4.8
579607

580608
This sniff checks that code blocks are indented correctly. By default, this sniff ensures that code blocks are indented 4 spaces, but you can change the size of the indent by setting the `indent` property.
581609

@@ -880,7 +908,7 @@ Property Name | Type | Default | Available Since
880908
indent | int | 4 | -
881909
exact | bool | false | -
882910
tabIndent | bool | false | 2.0.0
883-
ignoreIndentationTokens | array | - | 1.4.8
911+
ignoreIndentationTokens | array | [] | 1.4.8
884912

885913
> Note: All properties are inherited from the [Generic.WhiteSpace.ScopeIndent](#genericwhitespacescopeindent) sniff.
886914

0 commit comments

Comments
 (0)