Conditions | 11 |
Paths | 23 |
Total Lines | 44 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
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 |
||
113 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
114 | { |
||
115 | $interfaces = $this->findImplementedInterfaceNames($phpcsFile, $stackPtr); |
||
116 | |||
117 | if (is_array($interfaces) === false || $interfaces === array()) { |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | $tokens = $phpcsFile->getTokens(); |
||
122 | $checkMethods = false; |
||
123 | |||
124 | if(isset($tokens[$stackPtr]['scope_closer'])) { |
||
125 | $checkMethods = true; |
||
126 | $scopeCloser = $tokens[$stackPtr]['scope_closer']; |
||
127 | } |
||
128 | |||
129 | foreach ($interfaces as $interface) { |
||
130 | $lcInterface = strtolower($interface); |
||
131 | if (isset($this->newInterfaces[$lcInterface]) === true) { |
||
132 | $this->addError($phpcsFile, $stackPtr, $interface); |
||
133 | } |
||
134 | |||
135 | if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) { |
||
136 | $nextFunc = $stackPtr; |
||
137 | while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
||
138 | $funcName = strtolower($phpcsFile->getDeclarationName($nextFunc)); |
||
139 | if (is_string($funcName) === false) { |
||
140 | continue; |
||
141 | } |
||
142 | |||
143 | if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) { |
||
144 | $error = 'Classes that implement interface %s do not support the method %s(). See %s'; |
||
145 | $data = array( |
||
146 | $interface, |
||
147 | $funcName, |
||
148 | $this->unsupportedMethods[$lcInterface][$funcName], |
||
149 | ); |
||
150 | $phpcsFile->addError($error, $nextFunc, 'UnsupportedMethod', $data); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | }//end process() |
||
157 | |||
197 |
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.