Conditions | 11 |
Paths | 17 |
Total Lines | 68 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
95 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
96 | { |
||
97 | // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
||
98 | if ($this->supportsAbove('5.3') === false) { |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | $tokens = $phpcsFile->getTokens(); |
||
103 | |||
104 | if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
||
105 | return; |
||
106 | } |
||
107 | |||
108 | $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
||
109 | $functionPtr = $stackPtr; |
||
110 | |||
111 | // Find all the functions in this class or interface. |
||
112 | while ($functionToken = $phpcsFile->findNext(T_FUNCTION, $functionPtr, $classScopeCloser)) { |
||
113 | /* |
||
114 | * Get the scope closer for this function in order to know how |
||
115 | * to advance to the next function. |
||
116 | * If no body of function (e.g. for interfaces), there is |
||
117 | * no closing curly brace; advance the pointer differently. |
||
118 | */ |
||
119 | $scopeCloser = isset($tokens[$functionToken]['scope_closer']) |
||
120 | ? $tokens[$functionToken]['scope_closer'] |
||
121 | : $functionToken + 1; |
||
122 | |||
123 | |||
124 | $methodName = $phpcsFile->getDeclarationName($functionToken); |
||
125 | $methodNameLc = strtolower($methodName); |
||
126 | if (isset($this->magicMethods[$methodNameLc]) === false) { |
||
127 | $functionPtr = $scopeCloser; |
||
128 | continue; |
||
129 | } |
||
130 | |||
131 | $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
||
132 | |||
133 | if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
||
134 | $error = 'Visibility for magic method %s must be %s. Found: %s'; |
||
135 | $data = array( |
||
136 | $methodName, |
||
137 | $this->magicMethods[$methodNameLc]['visibility'], |
||
138 | $methodProperties['scope'], |
||
139 | ); |
||
140 | |||
141 | $phpcsFile->addError($error, $functionToken, 'MethodVisibility', $data); |
||
142 | } |
||
143 | |||
144 | if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
||
145 | $error = 'Magic method %s cannot be defined as static.'; |
||
146 | $errorCode = 'MethodStatic'; |
||
147 | if ( $this->magicMethods[$methodNameLc]['static'] === true ) { |
||
148 | $error = 'Magic method %s must be defined as static.'; |
||
149 | $errorCode = 'MethodNonStatic'; |
||
150 | } |
||
151 | $data = array( |
||
152 | $methodName, |
||
153 | ); |
||
154 | |||
155 | $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
||
156 | } |
||
157 | |||
158 | // Advance to next function. |
||
159 | $functionPtr = $scopeCloser; |
||
160 | } |
||
161 | |||
162 | }//end process() |
||
163 | |||
166 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.