Skip to content

Commit 6689a21

Browse files
authored
fix(DocComment): Fix undefined string index on short comments (#3307937)
1 parent e4e05ca commit 6689a21

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ public function process(File $phpcsFile, $stackPtr)
224224
// Remove any trailing white spaces which are detected by other sniffs.
225225
$shortContent = trim($shortContent);
226226

227-
if (preg_match('|\p{Lu}|u', $shortContent[0]) === 0
227+
if ($shortContent !== ''
228+
&& preg_match('|\p{Lu}|u', $shortContent[0]) === 0
228229
// Allow both variants of inheritdoc comments.
229230
&& $shortContent !== '{@inheritdoc}'
230231
&& $shortContent !== '{@inheritDoc}'

tests/Drupal/bad/BadUnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class BadUnitTest extends CoderSniffUnitTest
2727
protected function getErrorList(string $testFile): array
2828
{
2929
switch ($testFile) {
30+
case 'bad_crlf.inc':
31+
return [
32+
1 => 2,
33+
8 => 1,
34+
];
3035
case 'bad.css':
3136
return [
3237
1 => 1,

tests/Drupal/bad/bad_crlf.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Drupal\example\Controller;
3+
4+
/**
5+
* Foo.
6+
*/
7+
class ExampleController
8+
{
9+
10+
}

tests/Drupal/bad/bad_crlf.inc.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Drupal\example\Controller;
4+
5+
/**
6+
* Foo.
7+
*/
8+
class ExampleController {}

0 commit comments

Comments
 (0)