Skip to content

Commit 049f757

Browse files
committed
Merge remote-tracking branch 'origin/8.3.x' into fix-function-phpcs-ignore
2 parents 4f76f04 + d18eeb1 commit 049f757

File tree

9 files changed

+65
-20
lines changed

9 files changed

+65
-20
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) {

coder_sniffer/Drupal/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function process(File $phpcsFile, $stackPtr)
7474

7575
// Ensure the name is not all uppercase.
7676
// @todo We could make this more strict to check if there are more than
77-
// 2 upper case characters in a row, but not decided yet.
77+
// 2 upper case characters in a row anywhere, but not decided yet.
7878
// See https://www.drupal.org/project/coder/issues/3497433
79-
if (strtoupper($name) === $name) {
79+
if (preg_match('|^[A-Z]{3}[^a-z]*$|', $name) === 1) {
8080
$error = '%s name must use UpperCamel naming and not contain multiple upper case letters in a row';
8181
$phpcsFile->addError($error, $stackPtr, 'NoUpperAcronyms', $errorData);
8282
}

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/NamingConventions/ValidEnumCaseUnitTest.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@ enum Test: int {
1010
// Upper case parts are allowed for now.
1111
case FourJSONCase = 4;
1212
case FiveAndAHorseCorrect = 5;
13+
case UIExample = 6;
14+
}
15+
16+
// Those are all ok.
17+
enum FiscalQuarter {
18+
case Q1;
19+
case Q2;
20+
case Q3;
21+
case Q4;
22+
}
23+
24+
enum Plan {
25+
case A;
26+
case B;
27+
case C;
1328
}

tests/Drupal/good/good.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,38 @@ enum PUROSELY_WRONG_BUT_OK: int {
19151915
case Two = 2;
19161916
}
19171917

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+
}
1949+
19181950
/**
19191951
* Doc block is here and an ignore directive is ok.
19201952
*/

0 commit comments

Comments
 (0)