File tree Expand file tree Collapse file tree 3 files changed +43
-4
lines changed
SlevomatCodingStandard/Sniffs/Complexity Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 2222use const T_DO ;
2323use const T_ELSE ;
2424use const T_ELSEIF ;
25+ use const T_FN ;
2526use const T_FOR ;
2627use const T_FOREACH ;
2728use const T_FUNCTION ;
@@ -79,6 +80,7 @@ class CognitiveSniff implements Sniff
7980 * B3. Nesting increments
8081 */
8182 private const NESTING_INCREMENTS = [
83+ T_FN => T_FN ,
8284 T_CLOSURE => T_CLOSURE ,
8385 // increments, but does not receive
8486 T_ELSEIF => T_ELSEIF ,
@@ -127,10 +129,7 @@ class CognitiveSniff implements Sniff
127129 */
128130 public function register (): array
129131 {
130- return [
131- T_CLOSURE ,
132- T_FUNCTION ,
133- ];
132+ return TokenHelper::FUNCTION_TOKEN_CODES ;
134133 }
135134
136135 public function process (File $ phpcsFile , int $ stackPtr ): void
Original file line number Diff line number Diff line change @@ -57,6 +57,12 @@ public static function dataProviderFiles(): array
5757 'anonymous function ' ,
5858 19 ,
5959 ],
60+ [
61+ __DIR__ . '/data/cognitive/nesting4.php ' ,
62+ 3 ,
63+ 'anonymous function ' ,
64+ 19 ,
65+ ],
6066 [
6167 __DIR__ . '/data/cognitive/nestingContinueWithLabel.php ' ,
6268 3 ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ fn (ClassJavaType $ classType ) =>
4+ if (true ) { // +1
5+ return $ Symbols ->unknownMethodSymbol ();
6+ }
7+
8+ $ unknownFound = false ;
9+
10+ $ symbols = $ classType ->getSymbol ()->members ()->lookup (name);
11+
12+ foreach ($ symbols as $ symbol ) { // +1
13+ if ($ overrideSymbol ->isKind (MTH ) // +2 (nesting = 1)
14+ && !$ overrideSymbol ->isStatic ()) { // +1
15+
16+ if (canOverride ($ methodJavaSymbol )) { // +3 (nesting = 2)
17+ $ overriding = checkOverridingParameters ($ methodJavaSymbol , $ classType );
18+
19+ if ($ overriding === null ) { // +4 (nesting = 3)
20+ if (!$ unknownFound ) { // +5 (nesting = 4)
21+ $ unknownFound = true ;
22+ }
23+ } elseif ($ overriding ) { // +1
24+ return $ methodJavaSymbol ;
25+ }
26+ }
27+ }
28+ }
29+
30+ if ($ unknownFound ) { // +1
31+ return $ symbols ->unknownMethodSymbol ;
32+ }
33+
34+ return null ;
You can’t perform that action at this time.
0 commit comments