@@ -112,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
112
112
if ($ varParts [1 ]) {
113
113
return ;
114
114
}
115
- $ error = 'Short description duplicates class property name . ' ;
116
- $ phpcsFile ->addWarning ($ error , $ isShortDescriptionAfterVar , 'AlreadyHaveMeaningFulNameVar ' );
115
+ $ error = 'Short description must be before @var tag . ' ;
116
+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionAfterVar , 'ShortDescriptionAfterVar ' );
117
117
return ;
118
118
}
119
+
119
120
// Check if class has already have meaningful description before @var tag
120
121
$ isShortDescriptionPreviousVar = $ phpcsFile ->findPrevious (
121
122
T_DOC_COMMENT_STRING ,
@@ -125,23 +126,37 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
125
126
null ,
126
127
false
127
128
);
128
- if ($ this ->PHPDocFormattingValidator ->providesMeaning (
129
- $ isShortDescriptionPreviousVar ,
130
- $ commentStart ,
131
- $ tokens
132
- ) !== true ) {
133
- preg_match (
134
- '`^((?:\|?(?:array\([^\)]*\)|[ \\\\\[\]]+))*)( .*)?`i ' ,
135
- $ tokens [($ foundVar + 2 )]['content ' ],
136
- $ varParts
137
- );
138
- if ($ varParts [1 ]) {
139
- return ;
140
- }
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 )) {
141
149
$ error = 'Short description duplicates class property name. ' ;
142
- $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningFulNameVar ' );
150
+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningfulNameVar ' );
143
151
return ;
144
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
+ }
145
160
}
146
161
147
162
/**
0 commit comments