Skip to content

Commit eb696ed

Browse files
committed
Allow auto-fixing inheritDoc tag when alone
1 parent c2e4f0a commit eb696ed

File tree

2 files changed

+378
-1
lines changed

2 files changed

+378
-1
lines changed

Diff for: Magento2/Sniffs/Annotation/AnnotationFormatValidator.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ private function validateShortDescriptionFormat(
125125
$error = 'No blank lines are allowed before short description';
126126
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
127127
}
128+
128129
if (strtolower($tokens[$shortPtr]['content']) === '{@inheritdoc}') {
129130
$error = 'If the @inheritdoc not inline it shouldn’t have braces';
130-
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
131+
$fix = $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
132+
if ($fix === true) {
133+
$phpcsFile->fixer->replaceToken($shortPtr, '@inheritDoc');
134+
}
131135
}
136+
132137
$shortPtrContent = $tokens[$shortPtr]['content'];
133138
if (preg_match('/^\p{Ll}/u', $shortPtrContent) === 1) {
134139
$error = 'Short description must start with a capital letter';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,372 @@
1+
<?php
2+
3+
/**
4+
* Class for method structure for annotations test cases
5+
*/
6+
class MethodAnnotationFixture
7+
{
8+
/**
9+
*
10+
* @inheritdoc
11+
*/
12+
public function getProductListDefaultSortBy1()
13+
{
14+
}
15+
16+
/**
17+
*
18+
* @inheritdoc
19+
*/
20+
public function getProductListDefaultSortBy10($store = null)
21+
{
22+
return $store;
23+
}
24+
25+
/**
26+
* Block for short
27+
*
28+
* {@inheritdoc}
29+
*
30+
*/
31+
public function getProductListDefaultSortBy102()
32+
{
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function getProductListDefaultBy()
39+
{
40+
return;
41+
}
42+
43+
/**
44+
*
45+
* @inheritDoc
46+
*
47+
*/
48+
public function getProductListDefaultSortBy13()
49+
{
50+
return;
51+
}
52+
53+
/**
54+
* ProductVisibilityCondition constructor
55+
* @param \Magento\Catalog\Model\Product\Visibility $productVisibility
56+
*/
57+
public function content(\Magento\Catalog\Model\Product\Visibility $productVisibility)
58+
{
59+
$this->productVisibility = $productVisibility;
60+
}
61+
62+
/**
63+
* block description
64+
*
65+
* {@inheritdoc}
66+
*
67+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
68+
* @return void
69+
*/
70+
public function construct(AbstractDb $collection)
71+
{
72+
/** @var */
73+
$collection->setVisibility($this->productVisibility->getVisibleInCatalogIds());
74+
}
75+
76+
/**
77+
* Move category
78+
*
79+
*
80+
* @param int $parentId new parent category id
81+
*
82+
* @return $this
83+
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
84+
*/
85+
public function move($parentId)
86+
{
87+
/**
88+
* Validate new parent category id. (category model is used for backward
89+
* compatibility in event params)
90+
*/
91+
try {
92+
$this->categoryRepository->get($parentId, $this->getStoreId());
93+
}
94+
catch (NoSuchEntityException $e) {
95+
throw new \Magento\Framework\Exception\LocalizedException(
96+
__('Sorry, but we can\'t find the new parent category you selected.'),
97+
$e
98+
);
99+
}
100+
return true;
101+
}
102+
103+
/**
104+
* Block for short description
105+
*
106+
* This a long description {@inheritdoc} consists more lines as part of the long description
107+
* on multi line.
108+
*
109+
* @param int $store
110+
*
111+
*
112+
*/
113+
public function getProductListDefaultSortBy26032($store)
114+
{
115+
return $store;
116+
}
117+
118+
/**
119+
*
120+
*
121+
*
122+
*/
123+
public function getProductListDefaultSortBy2632()
124+
{
125+
}
126+
127+
/**
128+
* Block for short description
129+
*
130+
* This a long description {@inheritdoc} consists more lines as part of the long description
131+
* on multi line.
132+
*
133+
* @param int $store
134+
*
135+
*
136+
*
137+
*/
138+
public function getProductListDefaultSortBy2002($store)
139+
{
140+
return $store;
141+
}
142+
143+
/**
144+
*
145+
* block for short description
146+
*
147+
* @param int $store
148+
* @return int
149+
*/
150+
public function getProductListDefaultSortBy3002($store)
151+
{
152+
return $store;
153+
}
154+
155+
/**
156+
* Block for short description
157+
*
158+
* @see consists more lines as part of the long description
159+
* on multi line.
160+
*
161+
* @param string $store
162+
* @param string $foo
163+
*/
164+
public function getProductListDefaultSortBy12($store, $foo)
165+
{
166+
return $store === $foo;
167+
}
168+
169+
/**
170+
* Block for short description
171+
*
172+
* {@inheritdoc}
173+
*
174+
* @param string $store
175+
* @param string $foo
176+
*/
177+
public function getProductListDefaultSort2($store, $foo)
178+
{
179+
return $store === $foo;
180+
}
181+
182+
/**
183+
* Block for short description
184+
*
185+
* a long description {@inheritdoc} consists more lines as part of the long description
186+
* on multi line.
187+
*
188+
* @param string $store
189+
* @param string $foo
190+
*/
191+
public function getProductListDefault($store, $foo)
192+
{
193+
return $store === $foo;
194+
}
195+
196+
/**
197+
* Retrieve custom options
198+
*
199+
* @param ProductOptionInterface $productOption
200+
*
201+
* @return array
202+
*/
203+
protected function getCustomOptions(ProductOptionInterface $productOption)
204+
{
205+
if ($productOption
206+
&& $productOption->getExtensionAttributes()
207+
&& $productOption->getExtensionAttributes()->getCustomOptions()
208+
) {
209+
return $productOption->getExtensionAttributes()->getCustomOptions();
210+
}
211+
return [];
212+
}
213+
214+
/**
215+
* This is the summary for a DocBlock.
216+
*
217+
* This is the description for a DocBlock. This text may contain
218+
* multiple lines and even some _markdown_.
219+
* * Markdown style lists function too
220+
* * Just try this out once
221+
* The section after the description contains the tags; which provide
222+
* structured meta-data concerning the given element.
223+
*
224+
* @param int $example This is an example function/method parameter description.
225+
* @param string $example2 This is a second example.
226+
*
227+
*/
228+
public function getProductListDefaultSortBy2($example, $example2)
229+
{
230+
return $example === $example2;
231+
}
232+
233+
/**
234+
* Returns the content of the tokens from the specified start position in
235+
* the token stack for the specified length.
236+
*
237+
* @param int $start
238+
* @param int $length
239+
*
240+
* @return string The token contents.
241+
*/
242+
public function getProductListDefaultSortBy($start, $length)
243+
{
244+
return $start === $length;
245+
}
246+
247+
/**
248+
* Some text about this step/method returns the content of the tokens the token stack for the specified length
249+
*
250+
* @param string $name
251+
* @param string $folder
252+
*
253+
* @see this file
254+
* @When I create a file called :name in :folder
255+
*/
256+
public function getProductListDefaultSortBy222($name, $folder)
257+
{
258+
return $name === $folder;
259+
}
260+
261+
public function setExtensionAs(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
262+
{
263+
return $this->_setExtensionAttributes($extensionAttributes);
264+
}
265+
266+
/**
267+
*
268+
* short description
269+
* @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes
270+
* @return mixed
271+
*/
272+
public function setEn(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
273+
{
274+
return $this->_setExtensionAttributes($extensionAttributes);
275+
}
276+
277+
/**
278+
* @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes
279+
* @return mixed
280+
*/
281+
public function setExtenw(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
282+
{
283+
return $this->_setExtensionAttributes($extensionAttributes);
284+
}
285+
286+
/**
287+
*
288+
* Short description
289+
* @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes
290+
* @return mixed
291+
*/
292+
public function setExff(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes)
293+
{
294+
return $this->_setExtensionAttributes($extensionAttributes);
295+
}
296+
297+
/**
298+
* @inheritDoc
299+
*
300+
* @param int $start
301+
* @param int $length
302+
*
303+
* @return string The token contents.
304+
*/
305+
public function getProductSortBy($start, $length)
306+
{
307+
return $start === $length;
308+
}
309+
310+
/**
311+
* This is a well-formed deprecated function
312+
*
313+
* @deprecated can be used in this context
314+
* @see is ok here
315+
*/
316+
public function deprecated(): bool
317+
{
318+
return true;
319+
}
320+
321+
/**
322+
* This deprecated function is incorrect since it only contains the @deprecated tag
323+
*
324+
* @deprecated
325+
*/
326+
public function incorrectlyDeprecated()
327+
{
328+
return false;
329+
}
330+
331+
/**
332+
* This deprecated function is incorrect since it only contains the @deprecated tag
333+
*
334+
* @deprecated Should not be used
335+
*/
336+
public function incorrectAsWell()
337+
{
338+
return false;
339+
}
340+
341+
/**
342+
* This deprecated function is incorrect since the @see tag does not have extra info
343+
*
344+
* @deprecated
345+
* @see
346+
*/
347+
public function anotherOne()
348+
{
349+
return false;
350+
}
351+
352+
/**
353+
* This deprecated function is incorrect since the @see tag does not have extra info
354+
*
355+
* @deprecated Should not be used
356+
* @see
357+
*/
358+
public function yetAnotherOne()
359+
{
360+
return false;
361+
}
362+
363+
/**
364+
* This function is correct since the @see tag can be used without the @deprecated tag
365+
*
366+
* @see Magento\Framework\NewHandler
367+
*/
368+
public function correctUseOfSee()
369+
{
370+
return true;
371+
}
372+
}

0 commit comments

Comments
 (0)