Skip to content

Commit d18eeb1

Browse files
authored
fix(FullyQualifiedNamespace): Do not check names in PHP attributes for now (#3483583)
1 parent ba30df5 commit d18eeb1

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function process(File $phpcsFile, $stackPtr)
6565
return;
6666
}
6767

68+
// Skip names in PHP attributes, no standards defined yet.
69+
if (isset($tokens[$stackPtr]['attribute_closer']) === true) {
70+
return $tokens[$stackPtr]['attribute_closer'];
71+
}
72+
6873
// Check if this is a use statement and ignore those.
6974
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], $stackPtr, null, true);
7075
if ($tokens[$before]['code'] === T_USE || $tokens[$before]['code'] === T_NAMESPACE) {

tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.4.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Drupal\Core\Access\AccessResult;
88
use Drupal\Core\Session\AccountInterface;
99

1010
/**
11-
* Test action which is always usable.
11+
* Fully qualified names are allowed, there is no standard yet.
1212
*/
1313
#[\Drupal\action_link\Attribute\StateAction(
1414
id: 'test_always',

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
namespace Drupal\action_link_test_plugins\Plugin\StateAction;
44

5-
use Drupal\Core\StringTranslation\TranslatableMarkup;
6-
use Drupal\action_link\Attribute\StateAction;
5+
use Drupal\action_link\Entity\ActionLinkInterface;
76
use Drupal\action_link\Plugin\StateAction\StateActionBase;
7+
use Drupal\Core\Access\AccessResult;
8+
use Drupal\Core\Session\AccountInterface;
89

910
/**
10-
* Test action which is always usable.
11+
* Fully qualified names are allowed, there is no standard yet.
1112
*/
12-
#[StateAction(
13+
#[\Drupal\action_link\Attribute\StateAction(
1314
id: 'test_always',
14-
label: new TranslatableMarkup('Test Always'),
15-
description: new TranslatableMarkup('Test Always'),
15+
label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
16+
description: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
1617
directions: [
1718
'change' => 'change',
1819
]

tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ protected function getErrorList(string $testFile): array
3838
case 'FullyQualifiedNamespaceUnitTest.3.inc':
3939
return [10 => 2];
4040
case 'FullyQualifiedNamespaceUnitTest.4.inc':
41-
return [
42-
13 => 1,
43-
15 => 1,
44-
16 => 1,
45-
];
41+
return [];
4642
}//end switch
4743

4844
return [];

tests/Drupal/Commenting/ClassCommentUnitTest.inc.fixed

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Testing class/trait comments.
66
*/
77

8-
use Some\Attribute;
9-
108
/**
119
*
1210
*/
@@ -62,7 +60,7 @@ class WrongSpacing {
6260
/**
6361
* This is correct.
6462
*/
65-
#[Attribute(foo: 'bar')]
63+
#[Some\Attribute(foo: 'bar')]
6664
#[Other\Attribute(baz: 'qux')]
6765
class DoubleAttribute {
6866

tests/Drupal/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* Some function comment tests.
66
*/
77

8-
use Some\Attribute;
9-
108
/**
119
* Test.
1210
*
@@ -581,7 +579,7 @@ class Test41 {
581579
/**
582580
* Method docblock.
583581
*/
584-
#[Attribute(foo: 'bar')]
582+
#[Some\Attribute(foo: 'bar')]
585583
#[Other\Attribute(baz: 'qux')]
586584
public function method() {
587585
}

tests/Drupal/good/good.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,3 +1914,35 @@ enum PUROSELY_WRONG_BUT_OK: int {
19141914
case One = 1;
19151915
case Two = 2;
19161916
}
1917+
1918+
/**
1919+
* Fully qualified class name is allowed in PHP attributes for now.
1920+
*/
1921+
#[\Drupal\action_link\Attribute\StateAction(
1922+
id: 'test_always',
1923+
label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
1924+
description: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
1925+
directions: [
1926+
'change' => 'change',
1927+
]
1928+
)]
1929+
class TestAlways extends StateActionBase {
1930+
1931+
/**
1932+
* Partial names are ok in attributes for now.
1933+
*/
1934+
#[Assert\NotBlank]
1935+
private bool $bar;
1936+
1937+
/**
1938+
* Partially qualified names are ok in attributes for now.
1939+
*/
1940+
#[CLI\Command(
1941+
name: 'example',
1942+
aliases: ['example-foo']
1943+
)]
1944+
#[CLI\Option(name: 'pretty_format', description: 'Display the count in pretty format.')]
1945+
public function test(array $options = ['pretty-format' => TRUE]): void {
1946+
}
1947+
1948+
}

0 commit comments

Comments
 (0)