Skip to content

Commit e6cc504

Browse files
committed
refactor(FullyQualifiedNamespace): Replace sniff in favor of a sniff from Slevomat
1 parent a40711d commit e6cc504

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

coder_sniffer/Drupal/ruleset.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@
122122

123123
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
124124
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
125+
<!-- Allow global names with backslash like \Drupal. -->
126+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
127+
<properties>
128+
<property name="allowFullyQualifiedGlobalClasses" value="true" />
129+
<property name="allowFullyQualifiedGlobalFunctions" value="true" />
130+
<property name="allowFullyQualifiedGlobalConstants" value="true" />
131+
<property name="allowFallbackGlobalFunctions" value="true" />
132+
<property name="allowFallbackGlobalConstants" value="true" />
133+
</properties>
134+
</rule>
135+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
136+
<exclude-pattern>*.api.php</exclude-pattern>
137+
</rule>
138+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedNameWithoutNamespace">
139+
<severity>0</severity>
140+
</rule>
125141
<rule ref="SlevomatCodingStandard.PHP.ShortList" />
126142

127143
<rule ref="Squiz.Arrays.ArrayDeclaration" />
@@ -298,7 +314,7 @@
298314
<exclude-pattern>*/\.svn/*</exclude-pattern>
299315
<exclude-pattern>*/\.hg/*</exclude-pattern>
300316
<exclude-pattern>*/\.bzr/*</exclude-pattern>
301-
317+
302318
<!-- Ignore minified CSS files.-->
303319
<exclude-pattern>*\.min\.css$</exclude-pattern>
304320
</ruleset>

tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.1.inc.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* without them.
99
* phpcs:disable Drupal.Commenting
1010
*/
11-
1211
use Foo\Bar;
1312

1413
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Drupal\mymodule;
4+
5+
/**
6+
* Some fluffy comment about the class.
7+
*/
8+
class GoodNamespace {
9+
10+
/**
11+
* Using \Drupal without a use statement is fine.
12+
*/
13+
public static function version(): string {
14+
return \Drupal::VERSION . phpversion() . \phpversion();
15+
}
16+
17+
}

tests/Drupal/good/good.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,17 +1397,6 @@ public function test() {
13971397

13981398
}
13991399

1400-
// Namespaced function call is allowed because PHP 5.5 and lower do not support
1401-
// use statements for functions.
1402-
$default_config = [
1403-
'verify' => TRUE,
1404-
'timeout' => 30,
1405-
'headers' => [
1406-
'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
1407-
],
1408-
'handler' => $stack,
1409-
];
1410-
14111400
// camelCase and snake_case variables are allowed.
14121401
$snake_case = 1;
14131402
$camelCase = 1;
@@ -1819,3 +1808,5 @@ public function attributes(): void {
18191808
}
18201809

18211810
}
1811+
1812+
$version = \Drupal::VERSION;

0 commit comments

Comments
 (0)