Conditions | 9 |
Paths | 11 |
Total Lines | 67 |
Lines | 5 |
Ratio | 7.46 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
56 | { |
||
57 | if ($this->supportsBelow('7.2') === false) { |
||
58 | return; |
||
59 | } |
||
60 | |||
61 | $tokens = $phpcsFile->getTokens(); |
||
62 | |||
63 | $nextNonEmpty = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
||
64 | View Code Duplication | if ($tokens[$nextNonEmpty]['code'] !== T_OPEN_PARENTHESIS |
|
65 | || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
||
66 | ) { |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | if ($tokens[$stackPtr]['code'] === T_STRING) { |
||
71 | $ignore = array( |
||
72 | T_FUNCTION => true, |
||
73 | T_CONST => true, |
||
74 | T_USE => true, |
||
75 | ); |
||
76 | |||
77 | $prevNonEmpty = $phpcsFile->findPrevious(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
||
78 | if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) { |
||
79 | // Not a function call. |
||
80 | return; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
||
85 | $lastInParenthesis = $phpcsFile->findPrevious( |
||
86 | \PHP_CodeSniffer_Tokens::$emptyTokens, |
||
87 | ($closer - 1), |
||
88 | $nextNonEmpty, |
||
89 | true |
||
90 | ); |
||
91 | |||
92 | if ($tokens[$lastInParenthesis]['code'] !== T_COMMA) { |
||
93 | return; |
||
94 | } |
||
95 | |||
96 | $data = array(); |
||
97 | switch ($tokens[$stackPtr]['code']) { |
||
98 | case T_ISSET: |
||
99 | $data[] = 'calls to isset()'; |
||
100 | $errorCode = 'FoundInIsset'; |
||
101 | break; |
||
102 | |||
103 | case T_UNSET: |
||
104 | $data[] = 'calls to unset()'; |
||
105 | $errorCode = 'FoundInUnset'; |
||
106 | break; |
||
107 | |||
108 | default: |
||
109 | $data[] = 'function calls'; |
||
110 | $errorCode = 'FoundInFunctionCall'; |
||
111 | break; |
||
112 | } |
||
113 | |||
114 | $phpcsFile->addError( |
||
115 | 'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier', |
||
116 | $lastInParenthesis, |
||
117 | $errorCode, |
||
118 | $data |
||
119 | ); |
||
120 | |||
121 | }//end process() |
||
122 | |||
124 |