File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
Inpsyde/Sniffs/CodeQuality Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 18
18
use Inpsyde \PhpcsHelpers ;
19
19
use PHP_CodeSniffer \Files \File ;
20
20
use PHP_CodeSniffer \Sniffs \Sniff ;
21
+ use PHP_CodeSniffer \Util \Tokens ;
21
22
22
23
/**
23
24
* @package php-coding-standards
@@ -34,6 +35,8 @@ final class NoAccessorsSniff implements Sniff
34
35
35
36
public $ skipForFunctions = true ;
36
37
38
+ public $ skipForNonPublic = true ;
39
+
37
40
/**
38
41
* @return int[]
39
42
*/
@@ -54,11 +57,28 @@ public function process(File $file, $position)
54
57
}
55
58
56
59
$ functionName = $ file ->getDeclarationName ($ position );
57
-
58
60
if (!$ functionName || in_array ($ functionName , self ::ALLOWED_NAMES , true )) {
59
61
return ;
60
62
}
61
63
64
+ if ($ this ->skipForNonPublic && PhpcsHelpers::functionIsMethod ($ file , $ position )) {
65
+ $ modifierPointerPosition = $ file ->findPrevious (
66
+ [T_WHITESPACE , T_ABSTRACT ],
67
+ $ position - 1 ,
68
+ null ,
69
+ true ,
70
+ null ,
71
+ true
72
+ );
73
+ $ modifierPointer = $ file ->getTokens ()[$ modifierPointerPosition ] ?? null ;
74
+ if (!in_array ($ modifierPointer ['code ' ], Tokens::$ scopeModifiers , true )) {
75
+ $ modifierPointer = null ;
76
+ }
77
+ if ($ modifierPointer && $ modifierPointer ['code ' ] !== T_PUBLIC ) {
78
+ return ;
79
+ }
80
+ }
81
+
62
82
preg_match ('/^(set|get)[_A-Z0-9]+/ ' , $ functionName , $ matches );
63
83
if (!$ matches ) {
64
84
return ;
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ function withThing() {
40
40
41
41
}
42
42
43
- // @phpcsWarningCodeOnNextLine NoSetter
44
- function setTheThing ($ foo , $ bar ) {
43
+ private function setTheThing ($ foo , $ bar ) {
45
44
46
45
}
47
46
You can’t perform that action at this time.
0 commit comments