11<?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
26namespace Magento2 \Sniffs \Commenting ;
37
48use PHP_CodeSniffer \Files \File ;
@@ -108,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
108112 if ($ varParts [1 ]) {
109113 return ;
110114 }
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 ' );
113117 return ;
114118 }
119+
115120 // Check if class has already have meaningful description before @var tag
116121 $ isShortDescriptionPreviousVar = $ phpcsFile ->findPrevious (
117122 T_DOC_COMMENT_STRING ,
@@ -121,23 +126,37 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
121126 null ,
122127 false
123128 );
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 )) {
137149 $ error = 'Short description duplicates class property name. ' ;
138- $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningFulNameVar ' );
150+ $ phpcsFile ->addWarning ($ error , $ isShortDescriptionPreviousVar , 'AlreadyHaveMeaningfulNameVar ' );
139151 return ;
140152 }
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+ }
141160 }
142161
143162 /**
0 commit comments