Skip to content

Commit f1fe7c1

Browse files
committed
fix: FunctionComment sniff docs and unit test.
- Fixed the sniff docs with the new changes regarding the nested functions being ignored, and the void magic methods. - Fixed the unit test to include a test on the `__construct` magic method for the `VoidReturnTagFound` violation.
1 parent a915378 commit f1fe7c1

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

yCodeTech/Docs/Commenting/FunctionCommentStandard.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
This rule enforces:
77
8-
1. Functions with `non-void` return types (`string`, `bool`, etc.) must have a `@return` tag.
8+
1. Functions with `non-void` return types (`string`, `bool`, etc.) must have a `@return` tag (nested anonymous function and closure returns will be ignored).
99
2. Functions with `void` return types must NOT have `@return` tags, except generator functions.
1010
3. Generator functions must have a `@return` tag.
1111
@@ -14,6 +14,7 @@
1414
- Both typed and untyped functions are checked.
1515
- Return types can be declared or inferred from function signature.
1616
- Magic methods (e.g. `__construct`, `__get`, etc.) are exempt from requiring `@return` tags.
17+
- Most magic methods are exempt from having `@return` tags removed, except those that return `void`: `__construct`, `__destruct`, `__clone`, `__set`, `__unset`, `__wakeup`, and `__unserialize`.
1718
- Fixing `@return` tags will have the type `mixed`, and generator functions will have the type `iterable`; these should then be edited manually to specific types.
1819
1920
---
@@ -78,6 +79,31 @@ public function processData(array $data): void
7879
</code>
7980
</code_comparison>
8081

82+
<code_comparison>
83+
<code title="✔️ Valid: No @return for void constructor magic method">
84+
<![CDATA[
85+
/**
86+
* Constructor method.<em>
87+
</em> */
88+
public function __construct()
89+
{
90+
}
91+
]]>
92+
</code>
93+
<code title="❌ Invalid: @return tag on void constructor magic method">
94+
<![CDATA[
95+
/**
96+
* Constructor method.
97+
*
98+
* <em>@return void</em>
99+
*/
100+
public function __construct()
101+
{
102+
}
103+
]]>
104+
</code>
105+
</code_comparison>
106+
81107
<code_comparison>
82108
<code title="✔️ Valid: @return tag for generator function">
83109
<![CDATA[

yCodeTech/Tests/Commenting/FunctionCommentUnitTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class TestClass
2828
echo $message;
2929
}
3030

31+
/**
32+
* Constructor method with a `@return` tag.
33+
*
34+
* @return void
35+
*/
36+
public function __construct() {
37+
}
38+
3139
/**
3240
* Generator function missing iterable @return tag
3341
*

yCodeTech/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class TestClass
2828
echo $message;
2929
}
3030

31+
/**
32+
* Constructor method with a `@return` tag.
33+
*/
34+
public function __construct() {
35+
}
36+
3137
/**
3238
* Generator function missing iterable @return tag
3339
*

yCodeTech/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function getErrorList()
3232
return [
3333
14 => 1, // Function missing @return tag
3434
24 => 1, // Void function with a @return tag
35-
36 => 1, // Generator function missing @return tag (should get iterable)
36-
48 => 1, // Generator function with yield from missing @return tag
35+
34 => 1, // Void constructor magic method with a @return tag
36+
44 => 1, // Generator function missing @return tag (should get iterable)
37+
56 => 1, // Generator function with yield from missing @return tag
3738
];
3839
}
3940

@@ -49,4 +50,4 @@ public function getWarningList()
4950
{
5051
return [];
5152
}
52-
}
53+
}

0 commit comments

Comments
 (0)