Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// Skip names in PHP attributes, no standards defined yet.
if (isset($tokens[$stackPtr]['attribute_closer']) === true) {
return $tokens[$stackPtr]['attribute_closer'];
}

// Check if this is a use statement and ignore those.
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], $stackPtr, null, true);
if ($tokens[$before]['code'] === T_USE || $tokens[$before]['code'] === T_NAMESPACE) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.4.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;

/**
* Test action which is always usable.
* Fully qualified names are allowed, there is no standard yet.
*/
#[\Drupal\action_link\Attribute\StateAction(
id: 'test_always',
Expand Down
13 changes: 7 additions & 6 deletions tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.4.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace Drupal\action_link_test_plugins\Plugin\StateAction;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\action_link\Attribute\StateAction;
use Drupal\action_link\Entity\ActionLinkInterface;
use Drupal\action_link\Plugin\StateAction\StateActionBase;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;

/**
* Test action which is always usable.
* Fully qualified names are allowed, there is no standard yet.
*/
#[StateAction(
#[\Drupal\action_link\Attribute\StateAction(
id: 'test_always',
label: new TranslatableMarkup('Test Always'),
description: new TranslatableMarkup('Test Always'),
label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
description: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
directions: [
'change' => 'change',
]
Expand Down
6 changes: 1 addition & 5 deletions tests/Drupal/Classes/FullyQualifiedNamespaceUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ protected function getErrorList(string $testFile): array
case 'FullyQualifiedNamespaceUnitTest.3.inc':
return [10 => 2];
case 'FullyQualifiedNamespaceUnitTest.4.inc':
return [
13 => 1,
15 => 1,
16 => 1,
];
return [];
}//end switch

return [];
Expand Down
4 changes: 1 addition & 3 deletions tests/Drupal/Commenting/ClassCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Testing class/trait comments.
*/

use Some\Attribute;

/**
*
*/
Expand Down Expand Up @@ -62,7 +60,7 @@ class WrongSpacing {
/**
* This is correct.
*/
#[Attribute(foo: 'bar')]
#[Some\Attribute(foo: 'bar')]
#[Other\Attribute(baz: 'qux')]
class DoubleAttribute {

Expand Down
4 changes: 1 addition & 3 deletions tests/Drupal/Commenting/FunctionCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Some function comment tests.
*/

use Some\Attribute;

/**
* Test.
*
Expand Down Expand Up @@ -581,7 +579,7 @@ class Test41 {
/**
* Method docblock.
*/
#[Attribute(foo: 'bar')]
#[Some\Attribute(foo: 'bar')]
#[Other\Attribute(baz: 'qux')]
public function method() {
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Drupal/good/good.php
Original file line number Diff line number Diff line change
Expand Up @@ -1914,3 +1914,35 @@ enum PUROSELY_WRONG_BUT_OK: int {
case One = 1;
case Two = 2;
}

/**
* Fully qualified class name is allowed in PHP attributes for now.
*/
#[\Drupal\action_link\Attribute\StateAction(
id: 'test_always',
label: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
description: new \Drupal\Core\StringTranslation\TranslatableMarkup('Test Always'),
directions: [
'change' => 'change',
]
)]
class TestAlways extends StateActionBase {

/**
* Partial names are ok in attributes for now.
*/
#[Assert\NotBlank]
private bool $bar;

/**
* Partially qualified names are ok in attributes for now.
*/
#[CLI\Command(
name: 'example',
aliases: ['example-foo']
)]
#[CLI\Option(name: 'pretty_format', description: 'Display the count in pretty format.')]
public function test(array $options = ['pretty-format' => TRUE]): void {
}

}
Loading