Skip to content

Commit cf3d23f

Browse files
authored
Merge branch 'develop' into feature/magento#131-deprecated-description
2 parents 13ceb9a + c15d174 commit cf3d23f

5 files changed

+50
-20
lines changed

Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

+2-17
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,8 @@ public function process(File $phpcsFile, $stackPtr)
5656

5757
$namePtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1, null, false, null, true);
5858

59-
$commentStartPtr = $phpcsFile->findPrevious(
60-
[
61-
T_WHITESPACE,
62-
T_DOC_COMMENT_STAR,
63-
T_DOC_COMMENT_WHITESPACE,
64-
T_DOC_COMMENT_TAG,
65-
T_DOC_COMMENT_STRING,
66-
T_DOC_COMMENT_CLOSE_TAG
67-
],
68-
$stackPtr - 1,
69-
null,
70-
true,
71-
null,
72-
true
73-
);
74-
75-
if ($tokens[$commentStartPtr]['code'] !== T_DOC_COMMENT_OPEN_TAG) {
59+
$commentStartPtr = $this->PHPDocFormattingValidator->findPHPDoc($stackPtr, $phpcsFile);
60+
if ($commentStartPtr === -1) {
7661
return;
7762
}
7863

Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function process(File $phpcsFile, $stackPtr)
5959
true
6060
);
6161

62-
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, null, false, null, true);
63-
if ($commentStartPtr === false) {
62+
$commentStartPtr = $this->PHPDocFormattingValidator->findPHPDoc($stackPtr, $phpcsFile);
63+
if ($commentStartPtr === -1) {
6464
return;
6565
}
6666

Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php

+36
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,47 @@
66
*/
77
namespace Magento2\Sniffs\Commenting;
88

9+
use PHP_CodeSniffer\Files\File;
10+
911
/**
1012
* Helper class for common DocBlock validations
1113
*/
1214
class PHPDocFormattingValidator
1315
{
16+
/**
17+
* Finds matching PHPDoc for current pointer
18+
*
19+
* @param int $startPtr
20+
* @param File $phpcsFile
21+
* @return int
22+
*/
23+
public function findPHPDoc($startPtr, $phpcsFile)
24+
{
25+
$tokens = $phpcsFile->getTokens();
26+
27+
$commentStartPtr = $phpcsFile->findPrevious(
28+
[
29+
T_WHITESPACE,
30+
T_DOC_COMMENT_STAR,
31+
T_DOC_COMMENT_WHITESPACE,
32+
T_DOC_COMMENT_TAG,
33+
T_DOC_COMMENT_STRING,
34+
T_DOC_COMMENT_CLOSE_TAG
35+
],
36+
$startPtr - 1,
37+
null,
38+
true,
39+
null,
40+
true
41+
);
42+
43+
if ($tokens[$commentStartPtr]['code'] !== T_DOC_COMMENT_OPEN_TAG) {
44+
return -1;
45+
}
46+
47+
return $commentStartPtr;
48+
}
49+
1450
/**
1551
* Determines if the comment identified by $commentStartPtr provides additional meaning to origin at $namePtr
1652
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* Profiler
5+
*/
6+
class Profiler
7+
{
8+
const PROFILER = true;
9+
}

Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getErrorList()
2222
*/
2323
public function getWarningList($testFile = '')
2424
{
25-
if ($testFile === 'ConstantsPHPDocFormattingUnitTest.1.inc') {
25+
if ($testFile !== 'ConstantsPHPDocFormattingUnitTest.2.inc') {
2626
return [];
2727
}
2828

0 commit comments

Comments
 (0)