Skip to content

Commit 248d8bb

Browse files
committed
chore: add PHPCS rule to enforce namespace use statements
- Install slevomat/coding-standard package - Add ReferenceUsedNamesOnly rule to require use statements - Prevents fully qualified class names in code - Enforces cleaner, more maintainable code style
1 parent 4f2adce commit 248d8bb

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"szepeviktor/phpstan-wordpress": "^1.3",
1717
"php-stubs/wordpress-stubs": "^6.6",
1818
"php-stubs/woocommerce-stubs": "^9.0",
19-
"phpstan/extension-installer": "*"
19+
"phpstan/extension-installer": "*",
20+
"slevomat/coding-standard": "^8.22"
2021
},
2122
"scripts": {
2223
"phpcs": "phpcs -n",

composer.lock

Lines changed: 113 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@
2121
<exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound" />
2222
<exclude name="Generic.Commenting.DocComment" />
2323
</rule>
24+
25+
<!-- Require use statements instead of fully qualified names -->
26+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
27+
<properties>
28+
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
29+
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
30+
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
31+
<property name="allowFallbackGlobalFunctions" value="true"/>
32+
<property name="allowFallbackGlobalConstants" value="true"/>
33+
</properties>
34+
</rule>
2435
</ruleset>

0 commit comments

Comments
 (0)