Skip to content

Commit 1856376

Browse files
authored
refactor(DataTypeNamespace): Replace sniff with Slevomat sniff (#3559490)
1 parent 702cae9 commit 1856376

16 files changed

+49
-186
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ jobs:
100100
sed -i 's/Drupal.Methods.MethodDeclaration/PSR2.Methods.MethodDeclaration/g' phpcs.xml.dist
101101
sed -i '/<rule ref="Drupal.WhiteSpace.Namespace"\/>/d' phpcs.xml.dist
102102
sed -i 's/Drupal.Classes.InterfaceName/Generic.NamingConventions.InterfaceNameSuffix/g' phpcs.xml.dist
103+
sed -i '/<rule ref="Drupal.Commenting.DataTypeNamespace"\/>/d' phpcs.xml.dist
103104
../../vendor/bin/phpcs -p -s --parallel=$(nproc) --exclude=Drupal.ControlStructures.ControlSignature --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php,modules/big_pipe/tests/modules/big_pipe_test/src/BigPipePlaceholderTestCases.php,tests/fixtures/plugins/CustomPlugin.php,modules/package_manager/tests/modules/package_manager_test_api/src/ApiController.php,modules/views/tests/src/Kernel/Plugin/StyleGridTest.php

coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

coder_sniffer/Drupal/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
</rule>
137137
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
138138
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
139+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
139140
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
140141
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
141142
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>

tests/Drupal/Commenting/DataTypeNamespaceUnitTest.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/Drupal/Commenting/DocCommentUnitTest.inc.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @return bool
1515
* Returns FALSE.
1616
*
17-
* @throws Exception
17+
* @throws \Exception
1818
* Thrown when $param is TRUE.
1919
*
2020
* @ingroup sniffer
@@ -97,7 +97,7 @@ function test12() {
9797
* | Unseen University | Mustrum Ridcully | Alberto Malich the Wise | 1281 AM | Nvnc Id Vides, Nvnc Ne Vides |
9898
* phpcs:enable
9999
*
100-
* @param TableNode $organisation_table
100+
* @param \TableNode $organisation_table
101101
* The organisation data.
102102
*
103103
* @Given (the following )organisations:

tests/Drupal/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ function test21($arg1, $arg2, $arg3) {
257257
*
258258
* @param array|bool|float|int|mixed|object|string|resource|callable $arg1
259259
* All of the above types are valid.
260-
* @param array|bool|int|string|null $arg2
260+
* @param array|bool|int|\str|null $arg2
261261
* All of the above types are invalid.
262262
* @param array|bool|int|string $arg3
263263
* All of the above types are invalid.
264-
* @param mixed $arg4
264+
* @param \type $arg4
265265
* All of the above types are invalid.
266266
* @param false|true|int $arg5
267267
* All of the above types are invalid.
@@ -536,7 +536,7 @@ function test37(array $matches, array $sub_key, $to) {
536536
/**
537537
* Yield from should be a recognised return statement.
538538
*
539-
* @return Generator
539+
* @return \Generator
540540
* Generator value.
541541
*/
542542
function test38($a, $b) {
@@ -605,7 +605,7 @@ class Test41 {
605605
* NULL.
606606
* @param float $param8
607607
* Float.
608-
* @param double $param9
608+
* @param \double $param9
609609
* Double.
610610
* @param scalar $param10
611611
* Scalar.
@@ -685,15 +685,15 @@ function test_return_void2(): void {
685685
/**
686686
* PHPStan: General arrays.
687687
*
688-
* @param Type[] $param1
688+
* @param \Type[] $param1
689689
* Parameter.
690-
* @param array<Type> $param2
690+
* @param array<\Type> $param2
691691
* Parameter.
692-
* @param array<int, Type> $param3
692+
* @param array<int, \Type> $param3
693693
* Parameter.
694-
* @param non-empty-array<Type> $param4
694+
* @param non-empty-array<\Type> $param4
695695
* Parameter.
696-
* @param non-empty-array<int, Type> $param5
696+
* @param non-empty-array<int, \Type> $param5
697697
* Parameter.
698698
*
699699
* @see https://phpstan.org/writing-php-code/phpdoc-types#general-arrays
@@ -702,39 +702,39 @@ function test_arrays(array $param1, array $param2, array $param3, array $param4,
702702
}
703703

704704
/**
705-
* @return Type[]
705+
* @return \Type[]
706706
* Square brackets.
707707
*/
708708
function test_return_type_array(): array {
709709
return [];
710710
}
711711

712712
/**
713-
* @return array<Type>
713+
* @return array<\Type>
714714
* Arrow brackets.
715715
*/
716716
function test_return_arrow_array(): array {
717717
return [];
718718
}
719719

720720
/**
721-
* @return array<int, Type>
721+
* @return array<int, \Type>
722722
* Keyed array.
723723
*/
724724
function test_return_keyed_array(): array {
725725
return [];
726726
}
727727

728728
/**
729-
* @return non-empty-array<Type>
729+
* @return non-empty-array<\Type>
730730
* Non empty array with type.
731731
*/
732732
function test_return_non_empty_array(): array {
733733
return [new Type()];
734734
}
735735

736736
/**
737-
* @return non-empty-array<int, Type>
737+
* @return non-empty-array<int, \Type>
738738
* Non empty keyed array with type.
739739
*/
740740
function test_return_non_empty_keyed_array(): array {
@@ -854,7 +854,7 @@ function test_return_integer_max(): int {
854854
*
855855
* @param class-string $param1
856856
* Parameter.
857-
* @param class-string<Foo> $param2
857+
* @param class-string<\Foo> $param2
858858
* Parameter.
859859
* @param callable-string $param3
860860
* Parameter.
@@ -883,7 +883,7 @@ function test_return_class_string(): string {
883883
}
884884

885885
/**
886-
* @return class-string<Foo>
886+
* @return class-string<\Foo>
887887
* Class string.
888888
*/
889889
function test_return_class_string_foo(): string {
@@ -933,10 +933,10 @@ function test_return_literal_string(): string {
933933
/**
934934
* PHP 8 intersection types are ok.
935935
*
936-
* @param Foo&Bar $a
936+
* @param \Foo&\Bar $a
937937
* Intersection type parameter.
938938
*
939-
* @return Foo&Bar
939+
* @return \Foo&\Bar
940940
* Intersection type return declaration.
941941
*/
942942
function test_intersection_types(Foo&Bar $a): Foo&Bar {

tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Test {
5858
/**
5959
* Property fooBar.
6060
*
61-
* @var Foo|Bar|false|null
61+
* @var \Foo|\Bar|false|null
6262
*/
6363
public Foo|Bar|FALSE|NULL $fooBar;
6464

@@ -84,7 +84,7 @@ class Test {
8484
/**
8585
* PHPStan constant wildcard.
8686
*
87-
* @var Foo::*
87+
* @var \Foo::*
8888
*/
8989
protected string $constant;
9090

tests/Drupal/bad/BadUnitTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ protected function getErrorList(string $testFile): array
309309
638 => 1,
310310
646 => 2,
311311
648 => 1,
312-
656 => 1,
312+
656 => 2,
313313
658 => 1,
314-
661 => 1,
314+
661 => 2,
315315
671 => 1,
316316
678 => 1,
317317
685 => 1,
@@ -387,6 +387,14 @@ protected function getErrorList(string $testFile): array
387387
13 => 2,
388388
14 => 2,
389389
16 => 1,
390+
26 => 1,
391+
31 => 1,
392+
];
393+
case 'DataTypeNamespaceUnitTest.inc':
394+
return [
395+
15 => 1,
396+
18 => 1,
397+
21 => 1,
390398
31 => 1,
391399
];
392400
case 'FinallySpacingUnitTest.inc':
@@ -421,8 +429,10 @@ protected function getErrorList(string $testFile): array
421429
22 => 1,
422430
23 => 1,
423431
35 => 1,
432+
42 => 1,
424433
56 => 1,
425434
85 => 1,
435+
87 => 1,
426436
98 => 1,
427437
];
428438
case 'UseLeadingBackslashUnitTest.inc':

tests/Drupal/bad/ClassCreateInstanceUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ClassCreateInstanceUnitTest {
2626
/**
2727
* Using PHP 7 return type hints is fine.
2828
*
29-
* @return ValidatorInterface[]
29+
* @return \ValidatorInterface[]
3030
* The validators.
3131
*/
3232
public function getValidators(): array {

tests/Drupal/Commenting/DataTypeNamespaceUnitTest.inc renamed to tests/Drupal/bad/DataTypeNamespaceUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Some\Namespaced\TestClass;
77
/**
88
* Test.
99
*/
10-
class Test {
10+
class DataTypeNamespaceUnitTest {
1111

1212
/**
1313
* Param and Return data types should be fully namespaced.

0 commit comments

Comments
 (0)