Skip to content

Commit 43f861e

Browse files
authored
Improve README example configuration
1 parent 338cec2 commit 43f861e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Car {
1919
public function drive() {
2020
startCar(); // this is fine because `startCar` is imported
2121
Registry\registerCar($this); // this is fine because `Registry` is imported
22+
\DrivingTracker\registerDrive($this); // this is fine because it's fully-qualified
2223
goFaster(); // this will be a warning because `goFaster` was not imported
2324
}
2425
}
@@ -47,14 +48,23 @@ When installing sniff standards in a project, you edit a `phpcs.xml` file with t
4748

4849
## Ignoring Symbols
4950

50-
You can ignore certain patterns by using the `ignoreUnimportedSymbols` config option. It is a regular expression. Here is an example:
51+
Oftentimes there might be global symbols that you want to use without importing or using a fully-qualified path.
52+
53+
(Remember that function call resolution first searches the current namespace, then the global namespace, but constant and class resolution only searches the current namespace! You still have to import things like `Exception` or use the fully-qualified `\Exception`.)
54+
55+
You can ignore certain patterns by using the `ignoreUnimportedSymbols` config option. It is a regular expression. Here is an example for some common WordPress symbols:
5156

5257
```xml
53-
<rule ref="ImportDetection.Imports.RequireImports">
54-
<properties>
55-
<property name="ignoreUnimportedSymbols" value="/^(wp_parse_args|OBJECT\S*|ARRAY_\S+|is_wp_error|__|esc_html__|get_blog_\S+)$/"/>
56-
</properties>
57-
</rule>
58+
<?xml version="1.0"?>
59+
<ruleset name="MyStandard">
60+
<description>My library.</description>
61+
<rule ref="ImportDetection"/>
62+
<rule ref="ImportDetection.Imports.RequireImports">
63+
<properties>
64+
<property name="ignoreUnimportedSymbols" value="/^(wp_parse_args|OBJECT\S*|ARRAY_\S+|is_wp_error|__|esc_html__|get_blog_\S+)$/"/>
65+
</properties>
66+
</rule>
67+
</ruleset>
5868
```
5969

6070
## Usage

0 commit comments

Comments
 (0)