1
1
<?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
2
6
namespace Magento2 \Sniffs \Commenting ;
3
7
4
8
use PHP_CodeSniffer \Files \File ;
@@ -108,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
108
112
if ($ varParts [1 ]) {
109
113
return ;
110
114
}
111
- $ error = 'Short description duplicates class property name . ' ;
112
- $ phpcsFile ->addWarning ($ error , $ isShortDescriptionAfterVar , 'AlreadyHaveMeaningFulNameVar ' );
115
+ $ error = 'Short description must be before @var tag . ' ;
116
+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionAfterVar , 'ShortDescriptionAfterVar ' );
113
117
return ;
114
118
}
119
+
115
120
// Check if class has already have meaningful description before @var tag
116
121
$ isShortDescriptionPreviousVar = $ phpcsFile ->findPrevious (
117
122
T_DOC_COMMENT_STRING ,
@@ -121,23 +126,37 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
121
126
null ,
122
127
false
123
128
);
124
- if ($ this ->PHPDocFormattingValidator ->providesMeaning (
125
- $ isShortDescriptionPreviousVar ,
126
- $ commentStart ,
127
- $ tokens
128
- ) !== true ) {
129
- preg_match (
130
- '`^((?:\|?(?:array\([^\)]*\)|[ \\\\\[\]]+))*)( .*)?`i ' ,
131
- $ tokens [($ foundVar + 2 )]['content ' ],
132
- $ varParts
133
- );
134
- if ($ varParts [1 ]) {
135
- return ;
136
- }
129
+
130
+ if ($ isShortDescriptionPreviousVar === false ) {
131
+ return ;
132
+ }
133
+
134
+ $ propertyNamePosition = $ phpcsFile ->findNext (
135
+ T_VARIABLE ,
136
+ $ foundVar ,
137
+ null ,
138
+ false ,
139
+ null ,
140
+ false
141
+ );
142
+ if ($ propertyNamePosition === false ) {
143
+ return ;
144
+ };
145
+ $ propertyName = trim ($ tokens [$ propertyNamePosition ]['content ' ], '$ ' );
146
+ $ shortDescription = strtolower ($ tokens [$ isShortDescriptionPreviousVar ]['content ' ]);
147
+
148
+ if ($ shortDescription === strtolower ($ propertyName )) {
137
149
$ error = 'Short description duplicates class property name. ' ;
138
- $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningFulNameVar ' );
150
+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningfulNameVar ' );
139
151
return ;
140
152
}
153
+
154
+ $ propertyNameParts = array_filter (preg_split ('/(?=[A-Z])/ ' , $ propertyName ));
155
+
156
+ if ($ shortDescription === strtolower (implode (' ' , $ propertyNameParts ))) {
157
+ $ error = 'Short description duplicates class property name. ' ;
158
+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningfulNameVar ' );
159
+ }
141
160
}
142
161
143
162
/**
0 commit comments