File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,21 @@ protected function processVariable(File $phpcsFile, $stackPtr) {
179
179
180
180
$ method = $ phpcsFile ->getTokens ()[$ methodPtr ];
181
181
if ($ method ['parenthesis_opener ' ] < $ stackPtr && $ method ['parenthesis_closer ' ] > $ stackPtr ) {
182
+ $ lookBackTo = max (
183
+ $ method ['parenthesis_opener ' ],
184
+ $ phpcsFile ->findPrevious (T_COMMA , $ stackPtr )
185
+ );
186
+ // Only apply to properties declared in the constructor.
187
+ $ modifierPtr = $ phpcsFile ->findPrevious (
188
+ Collections::propertyModifierKeywords (),
189
+ $ stackPtr ,
190
+ $ lookBackTo
191
+ );
192
+ if ($ modifierPtr === false ) {
193
+ // No modifier found.
194
+ return ;
195
+ }
196
+
182
197
$ this ->processMemberVar ($ phpcsFile , $ stackPtr );
183
198
return ;
184
199
}
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ public function testSniffWithFixtures(
42
42
$ this ->setFixture (sprintf ("%s/fixtures/VariableComment/%s.php " , __DIR__ , $ fixture ));
43
43
$ this ->setErrors ($ errors );
44
44
$ this ->setWarnings ($ warnings );
45
-
46
45
$ this ->verifyCsResults ();
47
46
}
48
47
@@ -90,6 +89,14 @@ public static function fixtureProvider(): array {
90
89
],
91
90
'warnings ' => [],
92
91
],
92
+ 'Constructor with mixed CPP ' => [
93
+ 'fixture ' => 'constructor_with_mixed_property_promotion ' ,
94
+ 'errors ' => [
95
+ 21 => 'Missing member variable doc comment ' ,
96
+ ],
97
+ 'warnings ' => [
98
+ ],
99
+ ],
93
100
];
94
101
95
102
if (version_compare (PHP_VERSION , '8.0.0 ' ) >= 0 ) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MoodleHQ \MoodleCS \moodle \Tests \Sniffs \PHPUnit ;
4
+
5
+ class constructor_with_mixed_property_promotion {
6
+ /**
7
+ * Constructor
8
+ *
9
+ * @param string $serverurl a Moodle URL
10
+ * @param string $token the token used to do the web service call
11
+ * @param string $example
12
+ * @param string $example2
13
+ * @param string $example3
14
+ */
15
+ public function __construct (
16
+ $ serverurl ,
17
+ string $ token ,
18
+ /** @var string The example */
19
+ protected string $ example ,
20
+ string $ example2 ,
21
+ protected string $ example3
22
+ ) {
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments