Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c15d174

Browse filesBrowse files
authored
Merge pull request #135 from udovicic/bugfix/const-docblock-detection
Refactor PHPDoc search
2 parents a916b11 + 5465546 commit c15d174
Copy full SHA for c15d174

File tree

Expand file treeCollapse file tree

5 files changed

+50
-20
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+50
-20
lines changed

‎Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php
+2-17Lines changed: 2 additions & 17 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php
+2-2Lines changed: 2 additions & 2 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php
+36Lines changed: 36 additions & 0 deletions
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
*
+9Lines changed: 9 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.